Skip to content

Commit d956c8c

Browse files
committed
DATAMONGO-1756 - Polishing.
Remove redundant casts. Add author tag. Original pull request: spring-projects#491.
1 parent e8ae928 commit d956c8c

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

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

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.springframework.data.mapping.MappingException;
4242
import org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference;
4343
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
44-
import org.springframework.data.mongodb.core.aggregation.ExposedFields.FieldReference;
4544
import org.springframework.data.mongodb.core.convert.DbRefResolver;
4645
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
4746
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
@@ -55,6 +54,7 @@
5554
* @author Oliver Gierke
5655
* @author Thomas Darimont
5756
* @author Mark Paluch
57+
* @author Christoph Strobl
5858
*/
5959
@RunWith(MockitoJUnitRunner.class)
6060
public class TypeBasedAggregationOperationContextUnitTests {
@@ -99,8 +99,7 @@ public void returnsReferencesToNestedFieldsCorrectly() {
9999
public void aliasesIdFieldCorrectly() {
100100

101101
AggregationOperationContext context = getContext(Foo.class);
102-
assertThat(context.getReference("id"),
103-
is((FieldReference) new DirectFieldReference(new ExposedField(field("id", "_id"), true))));
102+
assertThat(context.getReference("id"), is(new DirectFieldReference(new ExposedField(field("id", "_id"), true))));
104103
}
105104

106105
@Test // DATAMONGO-912
@@ -117,8 +116,7 @@ public void shouldUseCustomConversionIfPresentAndConversionIsRequiredInFirstStag
117116

118117
org.bson.Document agg = newAggregation(matchStage, projectStage).toDocument("test", context);
119118

120-
org.bson.Document age = getValue(
121-
(org.bson.Document) getValue(getPipelineElementFromAggregationAt(agg, 0), "$match"), "age");
119+
org.bson.Document age = getValue(getValue(getPipelineElementFromAggregationAt(agg, 0), "$match"), "age");
122120
assertThat(age, is(new org.bson.Document("v", 10)));
123121
}
124122

@@ -136,8 +134,7 @@ public void shouldUseCustomConversionIfPresentAndConversionIsRequiredInLaterStag
136134

137135
org.bson.Document agg = newAggregation(projectStage, matchStage).toDocument("test", context);
138136

139-
org.bson.Document age = getValue(
140-
(org.bson.Document) getValue(getPipelineElementFromAggregationAt(agg, 1), "$match"), "age");
137+
org.bson.Document age = getValue(getValue(getPipelineElementFromAggregationAt(agg, 1), "$match"), "age");
141138
assertThat(age, is(new org.bson.Document("v", 10)));
142139
}
143140

@@ -154,11 +151,11 @@ public void rendersAggregationOptionsInTypedAggregationContextCorrectly() {
154151
org.bson.Document projection = getPipelineElementFromAggregationAt(document, 0);
155152
assertThat(projection.containsKey("$project"), is(true));
156153

157-
assertThat(projection.get("$project"), is((Object) new org.bson.Document("name", 1).append("age", 1)));
154+
assertThat(projection.get("$project"), is(new Document("name", 1).append("age", 1)));
158155

159-
assertThat(document.get("allowDiskUse"), is((Object) true));
160-
assertThat(document.get("explain"), is((Object) true));
161-
assertThat(document.get("cursor"), is((Object) new org.bson.Document("foo", 1)));
156+
assertThat(document.get("allowDiskUse"), is(true));
157+
assertThat(document.get("explain"), is(true));
158+
assertThat(document.get("cursor"), is(new Document("foo", 1)));
162159
}
163160

164161
@Test // DATAMONGO-1585
@@ -172,25 +169,23 @@ public void rendersSortOfProjectedFieldCorrectly() {
172169
Document sort = getPipelineElementFromAggregationAt(dbo, 1);
173170

174171
Document definition = (Document) sort.get("$sort");
175-
assertThat(definition.get("counter"), is(equalTo((Object) 1)));
172+
assertThat(definition.get("counter"), is(equalTo(1)));
176173
}
177174

178175
@Test // DATAMONGO-1586
179176
public void rendersFieldAliasingProjectionCorrectly() {
180177

181178
AggregationOperationContext context = getContext(FooPerson.class);
182-
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class,
183-
project() //
184-
.and("name").as("person_name") //
185-
.and("age.value").as("age"));
179+
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class, project() //
180+
.and("name").as("person_name") //
181+
.and("age.value").as("age"));
186182

187183
Document dbo = agg.toDocument("person", context);
188184

189185
Document projection = getPipelineElementFromAggregationAt(dbo, 0);
190-
assertThat(getAsDocument(projection, "$project"),
191-
isBsonObject() //
192-
.containing("person_name", "$name") //
193-
.containing("age", "$age.value"));
186+
assertThat(getAsDocument(projection, "$project"), isBsonObject() //
187+
.containing("person_name", "$name") //
188+
.containing("age", "$age.value"));
194189
}
195190

196191
@Test // DATAMONGO-1133
@@ -205,7 +200,7 @@ public void shouldHonorAliasedFieldsInGroupExpressions() {
205200

206201
org.bson.Document definition = (org.bson.Document) group.get("$group");
207202

208-
assertThat(definition.get("_id"), is(equalTo((Object) "$counter_name")));
203+
assertThat(definition.get("_id"), is(equalTo("$counter_name")));
209204
}
210205

211206
@Test // DATAMONGO-1326, DATAMONGO-1585
@@ -221,8 +216,8 @@ public void lookupShouldInheritFieldsFromInheritingAggregationOperation() {
221216

222217
org.bson.Document definition = (org.bson.Document) sort.get("$sort");
223218

224-
assertThat(definition.get("resourceId"), is(equalTo((Object) 1)));
225-
assertThat(definition.get("counter_name"), is(equalTo((Object) 1)));
219+
assertThat(definition.get("resourceId"), is(equalTo(1)));
220+
assertThat(definition.get("counter_name"), is(equalTo(1)));
226221
}
227222

228223
@Test // DATAMONGO-1326
@@ -237,7 +232,7 @@ public void groupLookupShouldInheritFieldsFromPreviousAggregationOperation() {
237232

238233
org.bson.Document definition = (org.bson.Document) sort.get("$sort");
239234

240-
assertThat(definition.get("foreignKey"), is(equalTo((Object) 1)));
235+
assertThat(definition.get("foreignKey"), is(equalTo(1)));
241236
}
242237

243238
@Test // DATAMONGO-1326
@@ -254,7 +249,7 @@ public void lookupGroupAggregationShouldUseCorrectGroupField() {
254249
org.bson.Document definition = (org.bson.Document) group.get("$group");
255250
org.bson.Document field = (org.bson.Document) definition.get("something_totally_different");
256251

257-
assertThat(field.get("$min"), is(equalTo((Object) "$lookup.otherkey")));
252+
assertThat(field.get("$min"), is(equalTo("$lookup.otherkey")));
258253
}
259254

260255
@Test // DATAMONGO-1326
@@ -271,7 +266,7 @@ public void lookupGroupAggregationShouldOverwriteExposedFields() {
271266

272267
org.bson.Document definition = (org.bson.Document) sort.get("$sort");
273268

274-
assertThat(definition.get("something_totally_different"), is(equalTo((Object) 1)));
269+
assertThat(definition.get("something_totally_different"), is(equalTo(1)));
275270
}
276271

277272
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@@ -289,11 +284,10 @@ public void lookupGroupAggregationShouldFailInvalidFieldReference() {
289284
public void rendersAggregationConditionalInTypedAggregationContextCorrectly() {
290285

291286
AggregationOperationContext context = getContext(FooPerson.class);
292-
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class,
293-
project("name") //
294-
.and("age") //
295-
.applyCondition(
296-
ConditionalOperators.when(Criteria.where("age.value").lt(10)).then(new Age(0)).otherwiseValueOf("age")) //
287+
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class, project("name") //
288+
.and("age") //
289+
.applyCondition(
290+
ConditionalOperators.when(Criteria.where("age.value").lt(10)).then(new Age(0)).otherwiseValueOf("age")) //
297291
);
298292

299293
Document document = agg.toDocument("person", context);
@@ -316,10 +310,9 @@ public void rendersAggregationConditionalInTypedAggregationContextCorrectly() {
316310
public void rendersAggregationIfNullInTypedAggregationContextCorrectly() {
317311

318312
AggregationOperationContext context = getContext(FooPerson.class);
319-
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class,
320-
project("name") //
321-
.and("age") //
322-
.applyCondition(ConditionalOperators.ifNull("age").then(new Age(0))) //
313+
TypedAggregation<FooPerson> agg = newAggregation(FooPerson.class, project("name") //
314+
.and("age") //
315+
.applyCondition(ConditionalOperators.ifNull("age").then(new Age(0))) //
323316
);
324317

325318
Document document = agg.toDocument("person", context);

0 commit comments

Comments
 (0)