1717
1818import static org .assertj .core .api .Assertions .*;
1919
20- import com .mongodb .MongoSocketReadTimeoutException ;
21- import com .mongodb .MongoSocketWriteException ;
22-
2320import org .bson .BsonDocument ;
2421import org .junit .jupiter .api .BeforeEach ;
2522import org .junit .jupiter .api .Test ;
3330import org .springframework .data .mongodb .ClientSessionException ;
3431import org .springframework .data .mongodb .MongoTransactionException ;
3532import org .springframework .data .mongodb .UncategorizedMongoDbException ;
33+ import org .springframework .lang .Nullable ;
3634
3735import com .mongodb .MongoCursorNotFoundException ;
3836import com .mongodb .MongoException ;
3937import com .mongodb .MongoInternalException ;
4038import com .mongodb .MongoSocketException ;
39+ import com .mongodb .MongoSocketReadTimeoutException ;
40+ import com .mongodb .MongoSocketWriteException ;
4141import com .mongodb .ServerAddress ;
4242
4343/**
4848 * @author Christoph Strobl
4949 * @author Brice Vandeputte
5050 */
51- public class MongoExceptionTranslatorUnitTests {
51+ class MongoExceptionTranslatorUnitTests {
5252
53- public static final String EXCEPTION_MESSAGE = "IOException" ;
54- MongoExceptionTranslator translator ;
53+ private static final String EXCEPTION_MESSAGE = "IOException" ;
54+ private MongoExceptionTranslator translator ;
5555
5656 @ BeforeEach
57- public void setUp () {
57+ void setUp () {
5858 translator = new MongoExceptionTranslator ();
5959 }
6060
6161 @ Test
62- public void translateDuplicateKey () {
62+ void translateDuplicateKey () {
6363
6464 expectExceptionWithCauseMessage (
6565 translator .translateExceptionIfPossible (
6666 new com .mongodb .DuplicateKeyException (new BsonDocument (), new ServerAddress (), null )),
6767 DuplicateKeyException .class , null );
6868 }
6969
70- @ Test
71- public void translateSocketException () {
70+ @ Test // GH-3568
71+ void translateSocketException () {
7272
7373 expectExceptionWithCauseMessage (
7474 translator .translateExceptionIfPossible (new MongoSocketException (EXCEPTION_MESSAGE , new ServerAddress ())),
7575 DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
76-
7776 }
7877
7978 @ Test // GH-3568
80- public void translateSocketChildrenExceptions () {
79+ void translateSocketExceptionSubclasses () {
8180
8281 expectExceptionWithCauseMessage (
8382 translator .translateExceptionIfPossible (
@@ -94,29 +93,29 @@ public void translateSocketChildrenExceptions() {
9493 }
9594
9695 @ Test
97- public void translateCursorNotFound () {
96+ void translateCursorNotFound () {
9897
9998 expectExceptionWithCauseMessage (
10099 translator .translateExceptionIfPossible (new MongoCursorNotFoundException (1L , new ServerAddress ())),
101100 DataAccessResourceFailureException .class );
102101 }
103102
104103 @ Test
105- public void translateToDuplicateKeyException () {
104+ void translateToDuplicateKeyException () {
106105
107106 checkTranslatedMongoException (DuplicateKeyException .class , 11000 );
108107 checkTranslatedMongoException (DuplicateKeyException .class , 11001 );
109108 }
110109
111110 @ Test
112- public void translateToDataAccessResourceFailureException () {
111+ void translateToDataAccessResourceFailureException () {
113112
114113 checkTranslatedMongoException (DataAccessResourceFailureException .class , 12000 );
115114 checkTranslatedMongoException (DataAccessResourceFailureException .class , 13440 );
116115 }
117116
118117 @ Test
119- public void translateToInvalidDataAccessApiUsageException () {
118+ void translateToInvalidDataAccessApiUsageException () {
120119
121120 checkTranslatedMongoException (InvalidDataAccessApiUsageException .class , 10003 );
122121 checkTranslatedMongoException (InvalidDataAccessApiUsageException .class , 12001 );
@@ -126,7 +125,7 @@ public void translateToInvalidDataAccessApiUsageException() {
126125 }
127126
128127 @ Test
129- public void translateToUncategorizedMongoDbException () {
128+ void translateToUncategorizedMongoDbException () {
130129
131130 MongoException exception = new MongoException (0 , "" );
132131 DataAccessException translatedException = translator .translateExceptionIfPossible (exception );
@@ -135,7 +134,7 @@ public void translateToUncategorizedMongoDbException() {
135134 }
136135
137136 @ Test
138- public void translateMongoInternalException () {
137+ void translateMongoInternalException () {
139138
140139 MongoInternalException exception = new MongoInternalException ("Internal exception" );
141140 DataAccessException translatedException = translator .translateExceptionIfPossible (exception );
@@ -144,14 +143,14 @@ public void translateMongoInternalException() {
144143 }
145144
146145 @ Test
147- public void translateUnsupportedException () {
146+ void translateUnsupportedException () {
148147
149148 RuntimeException exception = new RuntimeException ();
150149 assertThat (translator .translateExceptionIfPossible (exception )).isNull ();
151150 }
152151
153152 @ Test // DATAMONGO-2045
154- public void translateSessionExceptions () {
153+ void translateSessionExceptions () {
155154
156155 checkTranslatedMongoException (ClientSessionException .class , 206 );
157156 checkTranslatedMongoException (ClientSessionException .class , 213 );
@@ -160,7 +159,7 @@ public void translateSessionExceptions() {
160159 }
161160
162161 @ Test // DATAMONGO-2045
163- public void translateTransactionExceptions () {
162+ void translateTransactionExceptions () {
164163
165164 checkTranslatedMongoException (MongoTransactionException .class , 217 );
166165 checkTranslatedMongoException (MongoTransactionException .class , 225 );
@@ -183,13 +182,13 @@ private void checkTranslatedMongoException(Class<? extends Exception> clazz, int
183182 assertThat (((MongoException ) cause ).getCode ()).isEqualTo (code );
184183 }
185184
186- private static void expectExceptionWithCauseMessage (NestedRuntimeException e ,
185+ private static void expectExceptionWithCauseMessage (@ Nullable NestedRuntimeException e ,
187186 Class <? extends NestedRuntimeException > type ) {
188187 expectExceptionWithCauseMessage (e , type , null );
189188 }
190189
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 ) {
193192
194193 assertThat (e ).isInstanceOf (type );
195194
0 commit comments