Skip to content

Commit 44ce256

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-1854 - Move to AssertJ
1 parent b5818eb commit 44ce256

File tree

4 files changed

+69
-70
lines changed

4 files changed

+69
-70
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package org.springframework.data.mongodb.repository.query;
1717

18-
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
18+
import static org.assertj.core.api.Assertions.*;
2019
import static org.mockito.ArgumentMatchers.any;
2120
import static org.mockito.ArgumentMatchers.anyString;
2221
import static org.mockito.ArgumentMatchers.eq;
@@ -27,7 +26,6 @@
2726
import java.util.Locale;
2827
import java.util.Optional;
2928

30-
import org.assertj.core.api.Assertions;
3129
import org.bson.Document;
3230
import org.bson.types.ObjectId;
3331
import org.junit.Before;
@@ -124,7 +122,7 @@ public void testDeleteExecutionReturnsZeroWhenWriteResultIsNull() {
124122
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
125123
query.setDeleteQuery(true);
126124

127-
assertThat(query.execute(new Object[] { "fake" }), is(0L));
125+
assertThat(query.execute(new Object[] { "fake" })).isEqualTo(0L);
128126
}
129127

130128
@Test // DATAMONGO-566, DATAMONGO-978
@@ -136,7 +134,7 @@ public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
136134
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
137135
query.setDeleteQuery(true);
138136

139-
assertThat(query.execute(new Object[] { "fake" }), is(100L));
137+
assertThat(query.execute(new Object[] { "fake" })).isEqualTo(100L);
140138
verify(mongoOperationsMock, times(1)).remove(any(), eq(Person.class), eq("persons"));
141139
}
142140

@@ -151,7 +149,8 @@ public void metadataShouldNotBeAddedToQueryWhenNotPresent() {
151149
verify(executableFind).as(Person.class);
152150
verify(withQueryMock).matching(captor.capture());
153151

154-
assertThat(captor.getValue().getMeta().getComment(), nullValue());
152+
assertThat(captor.getValue().getMeta().getComment()).isNull();
153+
;
155154
}
156155

157156
@Test // DATAMONGO-957
@@ -165,7 +164,7 @@ public void metadataShouldBeAddedToQueryCorrectly() {
165164
verify(executableFind).as(Person.class);
166165
verify(withQueryMock).matching(captor.capture());
167166

168-
assertThat(captor.getValue().getMeta().getComment(), is("comment"));
167+
assertThat(captor.getValue().getMeta().getComment()).isEqualTo("comment");
169168
}
170169

171170
@Test // DATAMONGO-957
@@ -179,7 +178,7 @@ public void metadataShouldBeAddedToCountQueryCorrectly() {
179178
verify(executableFind).as(Person.class);
180179
verify(withQueryMock, atLeast(1)).matching(captor.capture());
181180

182-
assertThat(captor.getValue().getMeta().getComment(), is("comment"));
181+
assertThat(captor.getValue().getMeta().getComment()).isEqualTo("comment");
183182
}
184183

185184
@Test // DATAMONGO-957, DATAMONGO-1783
@@ -193,7 +192,7 @@ public void metadataShouldBeAddedToStringBasedQueryCorrectly() {
193192
verify(executableFind).as(Person.class);
194193
verify(withQueryMock).matching(captor.capture());
195194

196-
assertThat(captor.getValue().getMeta().getComment(), is("comment"));
195+
assertThat(captor.getValue().getMeta().getComment()).isEqualTo("comment");
197196
}
198197

199198
@Test // DATAMONGO-1057
@@ -211,8 +210,8 @@ public void slicedExecutionShouldRetainNrOfElementsToSkip() {
211210
verify(executableFind, times(2)).as(Person.class);
212211
verify(withQueryMock, times(2)).matching(captor.capture());
213212

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);
216215
}
217216

218217
@Test // DATAMONGO-1057
@@ -230,8 +229,8 @@ public void slicedExecutionShouldIncrementLimitByOne() {
230229
verify(executableFind, times(2)).as(Person.class);
231230
verify(withQueryMock, times(2)).matching(captor.capture());
232231

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);
235234
}
236235

237236
@Test // DATAMONGO-1057
@@ -250,8 +249,8 @@ public void slicedExecutionShouldRetainSort() {
250249
verify(withQueryMock, times(2)).matching(captor.capture());
251250

252251
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);
255254
}
256255

257256
@Test // DATAMONGO-1080
@@ -263,7 +262,7 @@ public void doesNotTryToPostProcessQueryResultIntoWrapperType() {
263262

264263
AbstractMongoQuery query = createQueryForMethod("findByLastname", String.class);
265264

266-
assertThat(query.execute(new Object[] { "lastname" }), is(reference));
265+
assertThat(query.execute(new Object[] { "lastname" })).isEqualTo(reference);
267266
}
268267

269268
@Test // DATAMONGO-1865
@@ -275,7 +274,7 @@ public void limitingSingleEntityQueryCallsFirst() {
275274

276275
AbstractMongoQuery query = createQueryForMethod("findFirstByLastname", String.class).setLimitingQuery(true);
277276

278-
assertThat(query.execute(new Object[] { "lastname" }), is(reference));
277+
assertThat(query.execute(new Object[] { "lastname" })).isEqualTo(reference);
279278
}
280279

281280
@Test // DATAMONGO-1872
@@ -297,7 +296,7 @@ public void usesAnnotatedSortWhenPresent() {
297296

298297
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
299298
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));
301300
}
302301

303302
@Test // DATAMONGO-1979
@@ -308,7 +307,7 @@ public void usesExplicitSortOverridesAnnotatedSortWhenPresent() {
308307

309308
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
310309
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));
312311
}
313312

314313
@Test // DATAMONGO-1854
@@ -319,7 +318,7 @@ public void shouldApplyStaticAnnotatedCollation() {
319318

320319
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
321320
verify(withQueryMock).matching(captor.capture());
322-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
321+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
323322
.contains(Collation.of("en_US").toDocument());
324323
}
325324

@@ -331,7 +330,7 @@ public void shouldApplyStaticAnnotatedCollationAsDocument() {
331330

332331
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
333332
verify(withQueryMock).matching(captor.capture());
334-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
333+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
335334
.contains(Collation.of("en_US").toDocument());
336335
}
337336

@@ -343,7 +342,7 @@ public void shouldApplyDynamicAnnotatedCollationAsString() {
343342

344343
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
345344
verify(withQueryMock).matching(captor.capture());
346-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
345+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
347346
.contains(Collation.of("en_US").toDocument());
348347
}
349348

@@ -355,7 +354,7 @@ public void shouldApplyDynamicAnnotatedCollationAsDocument() {
355354

356355
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
357356
verify(withQueryMock).matching(captor.capture());
358-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
357+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
359358
.contains(Collation.of("en_US").toDocument());
360359
}
361360

@@ -367,7 +366,7 @@ public void shouldApplyDynamicAnnotatedCollationAsLocale() {
367366

368367
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
369368
verify(withQueryMock).matching(captor.capture());
370-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
369+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
371370
.contains(Collation.of("en_US").toDocument());
372371
}
373372

@@ -379,7 +378,7 @@ public void shouldThrowExceptionOnNonParsableCollation() {
379378

380379
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
381380
verify(withQueryMock).matching(captor.capture());
382-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
381+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
383382
.contains(Collation.of("en_US").toDocument());
384383
}
385384

@@ -391,7 +390,7 @@ public void shouldApplyDynamicAnnotatedCollationIn() {
391390

392391
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
393392
verify(withQueryMock).matching(captor.capture());
394-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
393+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
395394
.contains(Collation.of("en_US").toDocument());
396395
}
397396

@@ -404,7 +403,7 @@ public void shouldApplyCollationParameter() {
404403

405404
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
406405
verify(withQueryMock).matching(captor.capture());
407-
Assertions.assertThat(captor.getValue().getCollation()).contains(collation);
406+
assertThat(captor.getValue().getCollation()).contains(collation);
408407
}
409408

410409
@Test // DATAMONGO-1854
@@ -416,7 +415,7 @@ public void collationParameterShouldOverrideAnnotation() {
416415

417416
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
418417
verify(withQueryMock).matching(captor.capture());
419-
Assertions.assertThat(captor.getValue().getCollation()).contains(collation);
418+
assertThat(captor.getValue().getCollation()).contains(collation);
420419
}
421420

422421
@Test // DATAMONGO-1854
@@ -427,7 +426,7 @@ public void collationParameterShouldNotBeAppliedWhenNullOverrideAnnotation() {
427426

428427
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
429428
verify(withQueryMock).matching(captor.capture());
430-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
429+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
431430
.contains(Collation.of("en_US").toDocument());
432431
}
433432

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQueryUnitTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
package org.springframework.data.mongodb.repository.query;
1717

18+
import static org.assertj.core.api.Assertions.*;
1819
import static org.mockito.Mockito.*;
1920

2021
import java.lang.reflect.Method;
2122
import java.util.List;
2223
import java.util.Locale;
2324

24-
import org.assertj.core.api.Assertions;
2525
import org.bson.Document;
2626
import org.junit.Before;
2727
import org.junit.Test;
@@ -86,7 +86,7 @@ public void shouldApplyStaticAnnotatedCollation() {
8686

8787
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
8888
verify(withQueryMock).matching(captor.capture());
89-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
89+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
9090
.contains(Collation.of("en_US").toDocument());
9191
}
9292

@@ -98,7 +98,7 @@ public void shouldApplyStaticAnnotatedCollationAsDocument() {
9898

9999
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
100100
verify(withQueryMock).matching(captor.capture());
101-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
101+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
102102
.contains(Collation.of("en_US").toDocument());
103103
}
104104

@@ -110,7 +110,7 @@ public void shouldApplyDynamicAnnotatedCollationAsString() {
110110

111111
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
112112
verify(withQueryMock).matching(captor.capture());
113-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
113+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
114114
.contains(Collation.of("en_US").toDocument());
115115
}
116116

@@ -122,7 +122,7 @@ public void shouldApplyDynamicAnnotatedCollationAsDocument() {
122122

123123
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
124124
verify(withQueryMock).matching(captor.capture());
125-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
125+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
126126
.contains(Collation.of("en_US").toDocument());
127127
}
128128

@@ -134,7 +134,7 @@ public void shouldApplyDynamicAnnotatedCollationAsLocale() {
134134

135135
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
136136
verify(withQueryMock).matching(captor.capture());
137-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
137+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
138138
.contains(Collation.of("en_US").toDocument());
139139
}
140140

@@ -146,7 +146,7 @@ public void shouldThrowExceptionOnNonParsableCollation() {
146146

147147
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
148148
verify(withQueryMock).matching(captor.capture());
149-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
149+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
150150
.contains(Collation.of("en_US").toDocument());
151151
}
152152

@@ -158,7 +158,7 @@ public void shouldApplyDynamicAnnotatedCollationIn() {
158158

159159
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
160160
verify(withQueryMock).matching(captor.capture());
161-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
161+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
162162
.contains(Collation.of("en_US").toDocument());
163163
}
164164

@@ -171,7 +171,7 @@ public void shouldApplyCollationParameter() {
171171

172172
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
173173
verify(withQueryMock).matching(captor.capture());
174-
Assertions.assertThat(captor.getValue().getCollation()).contains(collation);
174+
assertThat(captor.getValue().getCollation()).contains(collation);
175175
}
176176

177177
@Test // DATAMONGO-1854
@@ -183,7 +183,7 @@ public void collationParameterShouldOverrideAnnotation() {
183183

184184
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
185185
verify(withQueryMock).matching(captor.capture());
186-
Assertions.assertThat(captor.getValue().getCollation()).contains(collation);
186+
assertThat(captor.getValue().getCollation()).contains(collation);
187187
}
188188

189189
@Test // DATAMONGO-1854
@@ -194,7 +194,7 @@ public void collationParameterShouldNotBeAppliedWhenNullOverrideAnnotation() {
194194

195195
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
196196
verify(withQueryMock).matching(captor.capture());
197-
Assertions.assertThat(captor.getValue().getCollation().map(Collation::toDocument))
197+
assertThat(captor.getValue().getCollation().map(Collation::toDocument))
198198
.contains(Collation.of("en_US").toDocument());
199199
}
200200

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoParametersParameterAccessorUnitTests.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
*/
1616
package org.springframework.data.mongodb.repository.query;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.hamcrest.CoreMatchers.*;
20-
import static org.junit.Assert.assertThat;
18+
import static org.assertj.core.api.Assertions.*;
2119

2220
import java.lang.reflect.Method;
2321
import java.util.List;
2422

25-
import org.assertj.core.api.Assertions;
2623
import org.bson.Document;
27-
import org.hamcrest.core.IsNull;
2824
import org.junit.Test;
2925
import org.springframework.data.domain.Range;
3026
import org.springframework.data.domain.Range.Bound;
@@ -84,7 +80,7 @@ public void shouldReturnAsFullTextStringWhenNoneDefinedForMethod() throws NoSuch
8480

8581
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
8682
new Object[] { new Point(10, 20), DISTANCE });
87-
assertThat(accessor.getFullText(), IsNull.nullValue());
83+
assertThat(accessor.getFullText()).isNull();
8884
}
8985

9086
@Test // DATAMONGO-973
@@ -95,8 +91,8 @@ public void shouldProperlyConvertTextCriteria() throws NoSuchMethodException, Se
9591

9692
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
9793
new Object[] { "spring", TextCriteria.forDefaultLanguage().matching("data") });
98-
assertThat(accessor.getFullText().getCriteriaObject().toJson(),
99-
equalTo(Document.parse("{ \"$text\" : { \"$search\" : \"data\"}}").toJson()));
94+
assertThat(accessor.getFullText().getCriteriaObject().toJson())
95+
.isEqualTo(Document.parse("{ \"$text\" : { \"$search\" : \"data\"}}").toJson());
10096
}
10197

10298
@Test // DATAMONGO-1110
@@ -113,8 +109,8 @@ public void shouldDetectMinAndMaxDistance() throws NoSuchMethodException, Securi
113109

114110
Range<Distance> range = accessor.getDistanceRange();
115111

116-
assertThat(range.getLowerBound(), is(Bound.inclusive(min)));
117-
assertThat(range.getUpperBound(), is(Bound.inclusive(max)));
112+
assertThat(range.getLowerBound()).isEqualTo(Bound.inclusive(min));
113+
assertThat(range.getUpperBound()).isEqualTo(Bound.inclusive(max));
118114
}
119115

120116
@Test // DATAMONGO-1854
@@ -127,7 +123,7 @@ public void shouldDetectCollation() throws NoSuchMethodException, SecurityExcept
127123
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
128124
new Object[] { "dalinar", collation });
129125

130-
Assertions.assertThat(accessor.getCollation()).isEqualTo(collation);
126+
assertThat(accessor.getCollation()).isEqualTo(collation);
131127
}
132128

133129
interface PersonRepository extends Repository<Person, Long> {

0 commit comments

Comments
 (0)