Skip to content

Commit 5c54663

Browse files
committed
DATAMONGO-2096 - Polishing.
Migrate assertions to AssertJ. Original pull request: #613.
1 parent f04e67e commit 5c54663

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/GraphLookupOperationUnitTests.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package org.springframework.data.mongodb.core.aggregation;
1717

18-
import static org.hamcrest.core.Is.*;
19-
import static org.junit.Assert.*;
20-
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
18+
import static org.springframework.data.mongodb.test.util.Assertions.*;
19+
20+
import java.util.Arrays;
2121

2222
import org.bson.Document;
2323
import org.junit.Test;
@@ -50,8 +50,7 @@ public void shouldRenderCorrectly() {
5050
.as("reportingHierarchy");
5151

5252
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
53-
assertThat(document,
54-
isBsonObject().containing("$graphLookup.depthField", "depth").containing("$graphLookup.maxDepth", 42L));
53+
assertThat(document).containsEntry("$graphLookup.depthField", "depth").containsEntry("$graphLookup.maxDepth", 42L);
5554
}
5655

5756
@Test // DATAMONGO-1551
@@ -66,8 +65,7 @@ public void shouldRenderCriteriaCorrectly() {
6665
.as("reportingHierarchy");
6766

6867
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
69-
assertThat(document,
70-
isBsonObject().containing("$graphLookup.restrictSearchWithMatch", new Document("key", "value")));
68+
assertThat(document).containsEntry("$graphLookup.restrictSearchWithMatch", new Document("key", "value"));
7169
}
7270

7371
@Test // DATAMONGO-1551
@@ -82,9 +80,9 @@ public void shouldRenderArrayOfStartsWithCorrectly() {
8280

8381
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
8482

85-
assertThat(document,
86-
is(Document.parse("{ $graphLookup : { from: \"employees\", startWith: [\"$reportsTo\", \"$boss\"], "
87-
+ "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }")));
83+
assertThat(document)
84+
.isEqualTo(Document.parse("{ $graphLookup : { from: \"employees\", startWith: [\"$reportsTo\", \"$boss\"], "
85+
+ "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }"));
8886
}
8987

9088
@Test // DATAMONGO-1551
@@ -99,10 +97,8 @@ public void shouldRenderMixedArrayOfStartsWithCorrectly() {
9997

10098
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
10199

102-
assertThat(document,
103-
is(Document
104-
.parse("{ $graphLookup : { from: \"employees\", startWith: [\"$reportsTo\", { $literal: \"$boss\"}], "
105-
+ "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }")));
100+
assertThat(document).containsEntry("$graphLookup.startWith",
101+
Arrays.asList("$reportsTo", new Document("$literal", "$boss")));
106102
}
107103

108104
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1551
@@ -128,8 +124,7 @@ public void shouldRenderStartWithAggregationExpressions() {
128124

129125
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
130126

131-
assertThat(document, is(Document.parse("{ $graphLookup : { from: \"employees\", startWith: { $literal: \"hello\"}, "
132-
+ "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }")));
127+
assertThat(document).containsEntry("$graphLookup.startWith", new Document("$literal", "hello"));
133128
}
134129

135130
@Test // DATAMONGO-2096
@@ -140,8 +135,7 @@ public void connectFromShouldUseTargetFieldInsteadOfAlias() {
140135

141136
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
142137

143-
assertThat(document, is(Document.parse(
144-
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }")));
138+
assertThat(document).containsEntry("$graphLookup.startWith", "$contacts.userId");
145139
}
146140

147141
@Test // DATAMONGO-2096
@@ -152,8 +146,7 @@ public void connectToShouldUseTargetFieldInsteadOfAlias() {
152146

153147
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
154148

155-
assertThat(document, is(Document.parse(
156-
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"userId\", \"connectToField\" : \"connectto.field\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }")));
149+
assertThat(document).containsEntry("$graphLookup.connectToField", "connectto.field");
157150
}
158151

159152
@Test // DATAMONGO-2096
@@ -164,7 +157,6 @@ public void depthFieldShouldUseTargetFieldInsteadOfAlias() {
164157

165158
Document document = graphLookupOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
166159

167-
assertThat(document, is(Document.parse(
168-
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"foo.bar\" } }")));
160+
assertThat(document).containsEntry("$graphLookup.depthField", "foo.bar");
169161
}
170162
}

0 commit comments

Comments
 (0)