17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
20
- import com .mongodb .MongoSocketReadTimeoutException ;
21
- import com .mongodb .MongoSocketWriteException ;
22
-
23
20
import org .bson .BsonDocument ;
24
21
import org .junit .jupiter .api .BeforeEach ;
25
22
import org .junit .jupiter .api .Test ;
33
30
import org .springframework .data .mongodb .ClientSessionException ;
34
31
import org .springframework .data .mongodb .MongoTransactionException ;
35
32
import org .springframework .data .mongodb .UncategorizedMongoDbException ;
33
+ import org .springframework .lang .Nullable ;
36
34
37
35
import com .mongodb .MongoCursorNotFoundException ;
38
36
import com .mongodb .MongoException ;
39
37
import com .mongodb .MongoInternalException ;
40
38
import com .mongodb .MongoSocketException ;
39
+ import com .mongodb .MongoSocketReadTimeoutException ;
40
+ import com .mongodb .MongoSocketWriteException ;
41
41
import com .mongodb .ServerAddress ;
42
42
43
43
/**
48
48
* @author Christoph Strobl
49
49
* @author Brice Vandeputte
50
50
*/
51
- public class MongoExceptionTranslatorUnitTests {
51
+ class MongoExceptionTranslatorUnitTests {
52
52
53
- public static final String EXCEPTION_MESSAGE = "IOException" ;
54
- MongoExceptionTranslator translator ;
53
+ private static final String EXCEPTION_MESSAGE = "IOException" ;
54
+ private MongoExceptionTranslator translator ;
55
55
56
56
@ BeforeEach
57
- public void setUp () {
57
+ void setUp () {
58
58
translator = new MongoExceptionTranslator ();
59
59
}
60
60
61
61
@ Test
62
- public void translateDuplicateKey () {
62
+ void translateDuplicateKey () {
63
63
64
64
expectExceptionWithCauseMessage (
65
65
translator .translateExceptionIfPossible (
66
66
new com .mongodb .DuplicateKeyException (new BsonDocument (), new ServerAddress (), null )),
67
67
DuplicateKeyException .class , null );
68
68
}
69
69
70
- @ Test
71
- public void translateSocketException () {
70
+ @ Test // GH-3568
71
+ void translateSocketException () {
72
72
73
73
expectExceptionWithCauseMessage (
74
74
translator .translateExceptionIfPossible (new MongoSocketException (EXCEPTION_MESSAGE , new ServerAddress ())),
75
75
DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
76
-
77
76
}
78
77
79
78
@ Test // GH-3568
80
- public void translateSocketChildrenExceptions () {
79
+ void translateSocketExceptionSubclasses () {
81
80
82
81
expectExceptionWithCauseMessage (
83
82
translator .translateExceptionIfPossible (
@@ -94,29 +93,29 @@ public void translateSocketChildrenExceptions() {
94
93
}
95
94
96
95
@ Test
97
- public void translateCursorNotFound () {
96
+ void translateCursorNotFound () {
98
97
99
98
expectExceptionWithCauseMessage (
100
99
translator .translateExceptionIfPossible (new MongoCursorNotFoundException (1L , new ServerAddress ())),
101
100
DataAccessResourceFailureException .class );
102
101
}
103
102
104
103
@ Test
105
- public void translateToDuplicateKeyException () {
104
+ void translateToDuplicateKeyException () {
106
105
107
106
checkTranslatedMongoException (DuplicateKeyException .class , 11000 );
108
107
checkTranslatedMongoException (DuplicateKeyException .class , 11001 );
109
108
}
110
109
111
110
@ Test
112
- public void translateToDataAccessResourceFailureException () {
111
+ void translateToDataAccessResourceFailureException () {
113
112
114
113
checkTranslatedMongoException (DataAccessResourceFailureException .class , 12000 );
115
114
checkTranslatedMongoException (DataAccessResourceFailureException .class , 13440 );
116
115
}
117
116
118
117
@ Test
119
- public void translateToInvalidDataAccessApiUsageException () {
118
+ void translateToInvalidDataAccessApiUsageException () {
120
119
121
120
checkTranslatedMongoException (InvalidDataAccessApiUsageException .class , 10003 );
122
121
checkTranslatedMongoException (InvalidDataAccessApiUsageException .class , 12001 );
@@ -126,7 +125,7 @@ public void translateToInvalidDataAccessApiUsageException() {
126
125
}
127
126
128
127
@ Test
129
- public void translateToUncategorizedMongoDbException () {
128
+ void translateToUncategorizedMongoDbException () {
130
129
131
130
MongoException exception = new MongoException (0 , "" );
132
131
DataAccessException translatedException = translator .translateExceptionIfPossible (exception );
@@ -135,7 +134,7 @@ public void translateToUncategorizedMongoDbException() {
135
134
}
136
135
137
136
@ Test
138
- public void translateMongoInternalException () {
137
+ void translateMongoInternalException () {
139
138
140
139
MongoInternalException exception = new MongoInternalException ("Internal exception" );
141
140
DataAccessException translatedException = translator .translateExceptionIfPossible (exception );
@@ -144,14 +143,14 @@ public void translateMongoInternalException() {
144
143
}
145
144
146
145
@ Test
147
- public void translateUnsupportedException () {
146
+ void translateUnsupportedException () {
148
147
149
148
RuntimeException exception = new RuntimeException ();
150
149
assertThat (translator .translateExceptionIfPossible (exception )).isNull ();
151
150
}
152
151
153
152
@ Test // DATAMONGO-2045
154
- public void translateSessionExceptions () {
153
+ void translateSessionExceptions () {
155
154
156
155
checkTranslatedMongoException (ClientSessionException .class , 206 );
157
156
checkTranslatedMongoException (ClientSessionException .class , 213 );
@@ -160,7 +159,7 @@ public void translateSessionExceptions() {
160
159
}
161
160
162
161
@ Test // DATAMONGO-2045
163
- public void translateTransactionExceptions () {
162
+ void translateTransactionExceptions () {
164
163
165
164
checkTranslatedMongoException (MongoTransactionException .class , 217 );
166
165
checkTranslatedMongoException (MongoTransactionException .class , 225 );
@@ -183,13 +182,13 @@ private void checkTranslatedMongoException(Class<? extends Exception> clazz, int
183
182
assertThat (((MongoException ) cause ).getCode ()).isEqualTo (code );
184
183
}
185
184
186
- private static void expectExceptionWithCauseMessage (NestedRuntimeException e ,
185
+ private static void expectExceptionWithCauseMessage (@ Nullable NestedRuntimeException e ,
187
186
Class <? extends NestedRuntimeException > type ) {
188
187
expectExceptionWithCauseMessage (e , type , null );
189
188
}
190
189
191
- private static void expectExceptionWithCauseMessage (NestedRuntimeException e ,
192
- Class <? extends NestedRuntimeException > type , String message ) {
190
+ private static void expectExceptionWithCauseMessage (@ Nullable NestedRuntimeException e ,
191
+ Class <? extends NestedRuntimeException > type , @ Nullable String message ) {
193
192
194
193
assertThat (e ).isInstanceOf (type );
195
194
0 commit comments