Skip to content

Commit faf7e36

Browse files
committed
DATAMONGO-1765 - Polishing.
Lambdas and AssertJ in test cases.
1 parent a95f772 commit faf7e36

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverUnitTests.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@
1515
*/
1616
package org.springframework.data.mongodb.core.convert;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.hamcrest.Matchers.*;
20-
import static org.hamcrest.Matchers.contains;
21-
import static org.junit.Assert.assertThat;
18+
import static org.assertj.core.api.Assertions.*;
2219
import static org.mockito.ArgumentMatchers.*;
23-
import static org.mockito.ArgumentMatchers.any;
2420
import static org.mockito.Mockito.*;
2521

2622
import java.util.Arrays;
27-
import java.util.Collection;
2823
import java.util.Collections;
2924

3025
import org.bson.Document;
@@ -35,9 +30,7 @@
3530
import org.mockito.ArgumentCaptor;
3631
import org.mockito.Mock;
3732
import org.mockito.Mockito;
38-
import org.mockito.invocation.InvocationOnMock;
3933
import org.mockito.junit.MockitoJUnitRunner;
40-
import org.mockito.stubbing.Answer;
4134
import org.springframework.dao.InvalidDataAccessApiUsageException;
4235
import org.springframework.data.mongodb.MongoDbFactory;
4336
import org.springframework.data.mongodb.core.DocumentTestUtils;
@@ -88,7 +81,7 @@ public void bulkFetchShouldLoadDbRefsCorrectly() {
8881
Document _id = DocumentTestUtils.getAsDocument(captor.getValue(), "_id");
8982
Iterable<Object> $in = DocumentTestUtils.getTypedValue(_id, "$in", Iterable.class);
9083

91-
assertThat($in, iterableWithSize(2));
84+
assertThat($in).hasSize(2);
9285
}
9386

9487
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-1194
@@ -117,19 +110,9 @@ public void bulkFetchShouldRestoreOriginalOrder() {
117110
DBRef ref1 = new DBRef("collection-1", o1.get("_id"));
118111
DBRef ref2 = new DBRef("collection-1", o2.get("_id"));
119112

120-
when(cursorMock.into(any())).then(new Answer<Object>() {
113+
when(cursorMock.into(any())).then(invocation -> Arrays.asList(o2, o1));
121114

122-
@Override
123-
public Object answer(InvocationOnMock invocation) throws Throwable {
124-
125-
Collection<Document> collection = (Collection<Document>) invocation.getArguments()[0];
126-
collection.add(o2);
127-
collection.add(o1);
128-
return collection;
129-
}
130-
});
131-
132-
assertThat(resolver.bulkFetch(Arrays.asList(ref1, ref2)), contains(o1, o2));
115+
assertThat(resolver.bulkFetch(Arrays.asList(ref1, ref2))).containsExactly(o1, o2);
133116
}
134117

135118
@Test // DATAMONGO-1765

0 commit comments

Comments
 (0)