17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
20
- import java .net .UnknownHostException ;
20
+ import com .mongodb .MongoSocketReadTimeoutException ;
21
+ import com .mongodb .MongoSocketWriteException ;
21
22
22
23
import org .bson .BsonDocument ;
23
24
import org .junit .jupiter .api .BeforeEach ;
45
46
* @author Michal Vich
46
47
* @author Oliver Gierke
47
48
* @author Christoph Strobl
49
+ * @author Brice Vandeputte
48
50
*/
49
51
public class MongoExceptionTranslatorUnitTests {
50
52
53
+ public static final String EXCEPTION_MESSAGE = "IOException" ;
51
54
MongoExceptionTranslator translator ;
52
55
53
56
@ BeforeEach
@@ -68,13 +71,30 @@ public void translateDuplicateKey() {
68
71
public void translateSocketException () {
69
72
70
73
expectExceptionWithCauseMessage (
71
- translator .translateExceptionIfPossible (new MongoSocketException ("IOException" , new ServerAddress ())),
72
- DataAccessResourceFailureException .class , "IOException" );
74
+ translator .translateExceptionIfPossible (new MongoSocketException (EXCEPTION_MESSAGE , new ServerAddress ())),
75
+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
76
+
77
+ }
78
+
79
+ @ Test // GH-3568
80
+ public void translateSocketChildrenExceptions () {
81
+
82
+ expectExceptionWithCauseMessage (
83
+ translator .translateExceptionIfPossible (
84
+ new MongoSocketWriteException ("intermediate message" , new ServerAddress (), new Exception (EXCEPTION_MESSAGE ))
85
+ ),
86
+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
87
+
88
+ expectExceptionWithCauseMessage (
89
+ translator .translateExceptionIfPossible (
90
+ new MongoSocketReadTimeoutException ("intermediate message" , new ServerAddress (), new Exception (EXCEPTION_MESSAGE ))
91
+ ),
92
+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
73
93
74
94
}
75
95
76
96
@ Test
77
- public void translateCursorNotFound () throws UnknownHostException {
97
+ public void translateCursorNotFound () {
78
98
79
99
expectExceptionWithCauseMessage (
80
100
translator .translateExceptionIfPossible (new MongoCursorNotFoundException (1L , new ServerAddress ())),
0 commit comments