37
37
import org .bson .Document ;
38
38
import org .bson .conversions .Bson ;
39
39
import org .bson .types .ObjectId ;
40
- import org .junit .Before ;
41
- import org .junit .Ignore ;
42
- import org .junit .Test ;
43
- import org .junit .runner .RunWith ;
40
+ import org .junit .jupiter .api .BeforeEach ;
41
+ import org .junit .jupiter .api .Disabled ;
42
+ import org .junit .jupiter .api .Test ;
44
43
import org .mockito .ArgumentCaptor ;
45
44
import org .mockito .ArgumentMatcher ;
46
45
import org .mockito .Mock ;
47
46
import org .mockito .Mockito ;
48
- import org .mockito .junit .MockitoJUnitRunner ;
47
+ import org .mockito .junit .jupiter .MockitoSettings ;
48
+ import org .mockito .quality .Strictness ;
49
49
import org .springframework .beans .factory .annotation .Value ;
50
50
import org .springframework .context .ApplicationContext ;
51
51
import org .springframework .context .ApplicationListener ;
122
122
* @author Mark Paluch
123
123
* @author Michael J. Simons
124
124
*/
125
- @ RunWith ( MockitoJUnitRunner . class )
125
+ @ MockitoSettings ( strictness = Strictness . LENIENT )
126
126
public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
127
127
128
128
MongoTemplate template ;
@@ -146,8 +146,8 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
146
146
MappingMongoConverter converter ;
147
147
MongoMappingContext mappingContext ;
148
148
149
- @ Before
150
- public void setUp () {
149
+ @ BeforeEach
150
+ public void beforeEach () {
151
151
152
152
when (findIterable .iterator ()).thenReturn (cursor );
153
153
when (factory .getDb ()).thenReturn (db );
@@ -209,34 +209,36 @@ public void rejectsNullMongoClient() {
209
209
.isThrownBy (() -> new MongoTemplate ((com .mongodb .client .MongoClient ) null , "database" ));
210
210
}
211
211
212
- @ Test ( expected = IllegalArgumentException . class ) // DATAMONGO-1870
213
- public void removeHandlesMongoExceptionProperly () throws Exception {
212
+ @ Test // DATAMONGO-1870
213
+ public void removeHandlesMongoExceptionProperly () {
214
214
215
215
MongoTemplate template = mockOutGetDb ();
216
216
217
- template .remove (null , "collection" );
217
+ assertThatExceptionOfType ( IllegalArgumentException . class ). isThrownBy (() -> template .remove (null , "collection" ) );
218
218
}
219
219
220
220
@ Test
221
- public void defaultsConverterToMappingMongoConverter () throws Exception {
221
+ public void defaultsConverterToMappingMongoConverter () {
222
222
MongoTemplate template = new MongoTemplate (mongo , "database" );
223
223
assertThat (ReflectionTestUtils .getField (template , "mongoConverter" ) instanceof MappingMongoConverter ).isTrue ();
224
224
}
225
225
226
- @ Test ( expected = InvalidDataAccessApiUsageException . class )
226
+ @ Test
227
227
public void rejectsNotFoundMapReduceResource () {
228
228
229
229
GenericApplicationContext ctx = new GenericApplicationContext ();
230
230
ctx .refresh ();
231
231
template .setApplicationContext (ctx );
232
- template .mapReduce ("foo" , "classpath:doesNotExist.js" , "function() {}" , Person .class );
232
+
233
+ assertThatExceptionOfType (InvalidDataAccessApiUsageException .class )
234
+ .isThrownBy (() -> template .mapReduce ("foo" , "classpath:doesNotExist.js" , "function() {}" , Person .class ));
233
235
}
234
236
235
- @ Test ( expected = InvalidDataAccessApiUsageException . class ) // DATAMONGO-322
237
+ @ Test // DATAMONGO-322
236
238
public void rejectsEntityWithNullIdIfNotSupportedIdType () {
237
239
238
240
Object entity = new NotAutogenerateableId ();
239
- template .save (entity );
241
+ assertThatExceptionOfType ( InvalidDataAccessApiUsageException . class ). isThrownBy (() -> template .save (entity ) );
240
242
}
241
243
242
244
@ Test // DATAMONGO-322
@@ -466,7 +468,7 @@ public void geoNearShouldIgnoreReadPreferenceWhenNotSet() {
466
468
}
467
469
468
470
@ Test // DATAMONGO-1334
469
- @ Ignore ("TODO: mongo3 - a bit hard to tests with the immutable object stuff" )
471
+ @ Disabled ("TODO: mongo3 - a bit hard to tests with the immutable object stuff" )
470
472
public void mapReduceShouldUseZeroAsDefaultLimit () {
471
473
472
474
MongoCursor cursor = mock (MongoCursor .class );
@@ -1323,7 +1325,7 @@ public void findAndReplaceShouldUseDefaultCollationWhenPresent() {
1323
1325
assertThat (options .getValue ().getCollation ().getLocale ()).isEqualTo ("de_AT" );
1324
1326
}
1325
1327
1326
- @ Test // DATAMONGO-18545
1328
+ @ Test // DATAMONGO-1854
1327
1329
public void findAndReplaceShouldUseCollationEvenIfDefaultCollationIsPresent () {
1328
1330
1329
1331
template .findAndReplace (new BasicQuery ("{}" ).collation (Collation .of ("fr" )), new Sith ());
@@ -1822,7 +1824,7 @@ private MongoTemplate mockOutGetDb() {
1822
1824
@ Override
1823
1825
protected MongoOperations getOperationsForExceptionHandling () {
1824
1826
MongoTemplate template = spy (this .template );
1825
- when (template .getDb ()).thenThrow (new MongoException ("Error!" ));
1827
+ lenient (). when (template .getDb ()).thenThrow (new MongoException ("Error!" ));
1826
1828
return template ;
1827
1829
}
1828
1830
0 commit comments