15
15
*/
16
16
package org .springframework .data .mongodb .repository .query ;
17
17
18
- import static org .hamcrest .Matchers .*;
19
- import static org .junit .Assert .*;
18
+ import static org .assertj .core .api .Assertions .*;
20
19
import static org .mockito .ArgumentMatchers .any ;
21
20
import static org .mockito .ArgumentMatchers .anyString ;
22
21
import static org .mockito .ArgumentMatchers .eq ;
27
26
import java .util .Locale ;
28
27
import java .util .Optional ;
29
28
30
- import org .assertj .core .api .Assertions ;
31
29
import org .bson .Document ;
32
30
import org .bson .types .ObjectId ;
33
31
import org .junit .Before ;
@@ -124,7 +122,7 @@ public void testDeleteExecutionReturnsZeroWhenWriteResultIsNull() {
124
122
MongoQueryFake query = createQueryForMethod ("deletePersonByLastname" , String .class );
125
123
query .setDeleteQuery (true );
126
124
127
- assertThat (query .execute (new Object [] { "fake" }), is (0L ) );
125
+ assertThat (query .execute (new Object [] { "fake" })). isEqualTo (0L );
128
126
}
129
127
130
128
@ Test // DATAMONGO-566, DATAMONGO-978
@@ -136,7 +134,7 @@ public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
136
134
MongoQueryFake query = createQueryForMethod ("deletePersonByLastname" , String .class );
137
135
query .setDeleteQuery (true );
138
136
139
- assertThat (query .execute (new Object [] { "fake" }), is (100L ) );
137
+ assertThat (query .execute (new Object [] { "fake" })). isEqualTo (100L );
140
138
verify (mongoOperationsMock , times (1 )).remove (any (), eq (Person .class ), eq ("persons" ));
141
139
}
142
140
@@ -151,7 +149,8 @@ public void metadataShouldNotBeAddedToQueryWhenNotPresent() {
151
149
verify (executableFind ).as (Person .class );
152
150
verify (withQueryMock ).matching (captor .capture ());
153
151
154
- assertThat (captor .getValue ().getMeta ().getComment (), nullValue ());
152
+ assertThat (captor .getValue ().getMeta ().getComment ()).isNull ();
153
+ ;
155
154
}
156
155
157
156
@ Test // DATAMONGO-957
@@ -165,7 +164,7 @@ public void metadataShouldBeAddedToQueryCorrectly() {
165
164
verify (executableFind ).as (Person .class );
166
165
verify (withQueryMock ).matching (captor .capture ());
167
166
168
- assertThat (captor .getValue ().getMeta ().getComment (), is ("comment" ) );
167
+ assertThat (captor .getValue ().getMeta ().getComment ()). isEqualTo ("comment" );
169
168
}
170
169
171
170
@ Test // DATAMONGO-957
@@ -179,7 +178,7 @@ public void metadataShouldBeAddedToCountQueryCorrectly() {
179
178
verify (executableFind ).as (Person .class );
180
179
verify (withQueryMock , atLeast (1 )).matching (captor .capture ());
181
180
182
- assertThat (captor .getValue ().getMeta ().getComment (), is ("comment" ) );
181
+ assertThat (captor .getValue ().getMeta ().getComment ()). isEqualTo ("comment" );
183
182
}
184
183
185
184
@ Test // DATAMONGO-957, DATAMONGO-1783
@@ -193,7 +192,7 @@ public void metadataShouldBeAddedToStringBasedQueryCorrectly() {
193
192
verify (executableFind ).as (Person .class );
194
193
verify (withQueryMock ).matching (captor .capture ());
195
194
196
- assertThat (captor .getValue ().getMeta ().getComment (), is ("comment" ) );
195
+ assertThat (captor .getValue ().getMeta ().getComment ()). isEqualTo ("comment" );
197
196
}
198
197
199
198
@ Test // DATAMONGO-1057
@@ -211,8 +210,8 @@ public void slicedExecutionShouldRetainNrOfElementsToSkip() {
211
210
verify (executableFind , times (2 )).as (Person .class );
212
211
verify (withQueryMock , times (2 )).matching (captor .capture ());
213
212
214
- assertThat (captor .getAllValues ().get (0 ).getSkip (), is ( 0L ) );
215
- assertThat (captor .getAllValues ().get (1 ).getSkip (), is ( 10L ) );
213
+ assertThat (captor .getAllValues ().get (0 ).getSkip ()). isZero ( );
214
+ assertThat (captor .getAllValues ().get (1 ).getSkip ()). isEqualTo ( 10 );
216
215
}
217
216
218
217
@ Test // DATAMONGO-1057
@@ -230,8 +229,8 @@ public void slicedExecutionShouldIncrementLimitByOne() {
230
229
verify (executableFind , times (2 )).as (Person .class );
231
230
verify (withQueryMock , times (2 )).matching (captor .capture ());
232
231
233
- assertThat (captor .getAllValues ().get (0 ).getLimit (), is (11 ) );
234
- assertThat (captor .getAllValues ().get (1 ).getLimit (), is (11 ) );
232
+ assertThat (captor .getAllValues ().get (0 ).getLimit ()). isEqualTo (11 );
233
+ assertThat (captor .getAllValues ().get (1 ).getLimit ()). isEqualTo (11 );
235
234
}
236
235
237
236
@ Test // DATAMONGO-1057
@@ -250,8 +249,8 @@ public void slicedExecutionShouldRetainSort() {
250
249
verify (withQueryMock , times (2 )).matching (captor .capture ());
251
250
252
251
Document expectedSortObject = new Document ().append ("bar" , -1 );
253
- assertThat (captor .getAllValues ().get (0 ).getSortObject (), is (expectedSortObject ) );
254
- assertThat (captor .getAllValues ().get (1 ).getSortObject (), is (expectedSortObject ) );
252
+ assertThat (captor .getAllValues ().get (0 ).getSortObject ()). isEqualTo (expectedSortObject );
253
+ assertThat (captor .getAllValues ().get (1 ).getSortObject ()). isEqualTo (expectedSortObject );
255
254
}
256
255
257
256
@ Test // DATAMONGO-1080
@@ -263,7 +262,7 @@ public void doesNotTryToPostProcessQueryResultIntoWrapperType() {
263
262
264
263
AbstractMongoQuery query = createQueryForMethod ("findByLastname" , String .class );
265
264
266
- assertThat (query .execute (new Object [] { "lastname" }), is (reference ) );
265
+ assertThat (query .execute (new Object [] { "lastname" })). isEqualTo (reference );
267
266
}
268
267
269
268
@ Test // DATAMONGO-1865
@@ -275,7 +274,7 @@ public void limitingSingleEntityQueryCallsFirst() {
275
274
276
275
AbstractMongoQuery query = createQueryForMethod ("findFirstByLastname" , String .class ).setLimitingQuery (true );
277
276
278
- assertThat (query .execute (new Object [] { "lastname" }), is (reference ) );
277
+ assertThat (query .execute (new Object [] { "lastname" })). isEqualTo (reference );
279
278
}
280
279
281
280
@ Test // DATAMONGO-1872
@@ -297,7 +296,7 @@ public void usesAnnotatedSortWhenPresent() {
297
296
298
297
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
299
298
verify (withQueryMock ).matching (captor .capture ());
300
- assertThat (captor .getValue ().getSortObject (), is ( equalTo ( new Document ("age" , 1 )) ));
299
+ assertThat (captor .getValue ().getSortObject ()). isEqualTo ( new Document ("age" , 1 ));
301
300
}
302
301
303
302
@ Test // DATAMONGO-1979
@@ -308,7 +307,7 @@ public void usesExplicitSortOverridesAnnotatedSortWhenPresent() {
308
307
309
308
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
310
309
verify (withQueryMock ).matching (captor .capture ());
311
- assertThat (captor .getValue ().getSortObject (), is ( equalTo ( new Document ("age" , -1 )) ));
310
+ assertThat (captor .getValue ().getSortObject ()). isEqualTo ( new Document ("age" , -1 ));
312
311
}
313
312
314
313
@ Test // DATAMONGO-1854
@@ -319,7 +318,7 @@ public void shouldApplyStaticAnnotatedCollation() {
319
318
320
319
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
321
320
verify (withQueryMock ).matching (captor .capture ());
322
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
321
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
323
322
.contains (Collation .of ("en_US" ).toDocument ());
324
323
}
325
324
@@ -331,7 +330,7 @@ public void shouldApplyStaticAnnotatedCollationAsDocument() {
331
330
332
331
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
333
332
verify (withQueryMock ).matching (captor .capture ());
334
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
333
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
335
334
.contains (Collation .of ("en_US" ).toDocument ());
336
335
}
337
336
@@ -343,7 +342,7 @@ public void shouldApplyDynamicAnnotatedCollationAsString() {
343
342
344
343
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
345
344
verify (withQueryMock ).matching (captor .capture ());
346
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
345
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
347
346
.contains (Collation .of ("en_US" ).toDocument ());
348
347
}
349
348
@@ -355,7 +354,7 @@ public void shouldApplyDynamicAnnotatedCollationAsDocument() {
355
354
356
355
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
357
356
verify (withQueryMock ).matching (captor .capture ());
358
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
357
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
359
358
.contains (Collation .of ("en_US" ).toDocument ());
360
359
}
361
360
@@ -367,7 +366,7 @@ public void shouldApplyDynamicAnnotatedCollationAsLocale() {
367
366
368
367
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
369
368
verify (withQueryMock ).matching (captor .capture ());
370
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
369
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
371
370
.contains (Collation .of ("en_US" ).toDocument ());
372
371
}
373
372
@@ -379,7 +378,7 @@ public void shouldThrowExceptionOnNonParsableCollation() {
379
378
380
379
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
381
380
verify (withQueryMock ).matching (captor .capture ());
382
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
381
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
383
382
.contains (Collation .of ("en_US" ).toDocument ());
384
383
}
385
384
@@ -391,7 +390,7 @@ public void shouldApplyDynamicAnnotatedCollationIn() {
391
390
392
391
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
393
392
verify (withQueryMock ).matching (captor .capture ());
394
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
393
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
395
394
.contains (Collation .of ("en_US" ).toDocument ());
396
395
}
397
396
@@ -404,7 +403,7 @@ public void shouldApplyCollationParameter() {
404
403
405
404
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
406
405
verify (withQueryMock ).matching (captor .capture ());
407
- Assertions . assertThat (captor .getValue ().getCollation ()).contains (collation );
406
+ assertThat (captor .getValue ().getCollation ()).contains (collation );
408
407
}
409
408
410
409
@ Test // DATAMONGO-1854
@@ -416,7 +415,7 @@ public void collationParameterShouldOverrideAnnotation() {
416
415
417
416
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
418
417
verify (withQueryMock ).matching (captor .capture ());
419
- Assertions . assertThat (captor .getValue ().getCollation ()).contains (collation );
418
+ assertThat (captor .getValue ().getCollation ()).contains (collation );
420
419
}
421
420
422
421
@ Test // DATAMONGO-1854
@@ -427,7 +426,7 @@ public void collationParameterShouldNotBeAppliedWhenNullOverrideAnnotation() {
427
426
428
427
ArgumentCaptor <Query > captor = ArgumentCaptor .forClass (Query .class );
429
428
verify (withQueryMock ).matching (captor .capture ());
430
- Assertions . assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
429
+ assertThat (captor .getValue ().getCollation ().map (Collation ::toDocument ))
431
430
.contains (Collation .of ("en_US" ).toDocument ());
432
431
}
433
432
0 commit comments