Skip to content

Commit 262a631

Browse files
committed
DATAMONGO-1176 - Test code cleanup.
Replace DbObject in documentation with Document. Fix typos. Change dbObject variable names to document.
1 parent 039740a commit 262a631

File tree

46 files changed

+861
-857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+861
-857
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DBObjectTestUtils.java renamed to spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DocumentTestUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,12 +28,11 @@
2828
* Helper classes to ease assertions on {@link Document}s.
2929
*
3030
* @author Oliver Gierke
31+
* @author Mark Paluch
3132
*/
32-
public abstract class DBObjectTestUtils {
33+
public abstract class DocumentTestUtils {
3334

34-
private DBObjectTestUtils() {
35-
36-
}
35+
private DocumentTestUtils() {}
3736

3837
/**
3938
* Expects the field with the given key to be not {@literal null} and a {@link Document} in turn and returns it.

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,10 +1487,10 @@ public void optimisticLockingHandlingWithExistingId() {
14871487
@Test
14881488
public void doesNotFailOnVersionInitForUnversionedEntity() {
14891489

1490-
org.bson.Document dbObject = new org.bson.Document();
1491-
dbObject.put("firstName", "Oliver");
1490+
org.bson.Document document = new org.bson.Document();
1491+
document.put("firstName", "Oliver");
14921492

1493-
template.insert(dbObject, template.determineCollectionName(PersonWithVersionPropertyOfTypeInteger.class));
1493+
template.insert(document, template.determineCollectionName(PersonWithVersionPropertyOfTypeInteger.class));
14941494
}
14951495

14961496
/**
@@ -1542,12 +1542,12 @@ public void rejectsNullObjectToBeSaved() {
15421542
* @see DATAMONGO-550
15431543
*/
15441544
@Test
1545-
public void savesPlainDbObjectCorrectly() {
1545+
public void savesPlainDocumentCorrectly() {
15461546

1547-
org.bson.Document dbObject = new org.bson.Document("foo", "bar");
1548-
template.save(dbObject, "collection");
1547+
org.bson.Document document = new org.bson.Document("foo", "bar");
1548+
template.save(document, "collection");
15491549

1550-
assertThat(dbObject.containsKey("_id"), is(true));
1550+
assertThat(document.containsKey("_id"), is(true));
15511551
}
15521552

15531553
/**
@@ -1556,24 +1556,24 @@ public void savesPlainDbObjectCorrectly() {
15561556
@Test(expected = InvalidDataAccessApiUsageException.class)
15571557
public void rejectsPlainObjectWithOutExplicitCollection() {
15581558

1559-
org.bson.Document dbObject = new org.bson.Document("foo", "bar");
1560-
template.save(dbObject, "collection");
1559+
org.bson.Document document = new org.bson.Document("foo", "bar");
1560+
template.save(document, "collection");
15611561

1562-
template.findById(dbObject.get("_id"), org.bson.Document.class);
1562+
template.findById(document.get("_id"), org.bson.Document.class);
15631563
}
15641564

15651565
/**
15661566
* @see DATAMONGO-550
15671567
*/
15681568
@Test
1569-
public void readsPlainDbObjectById() {
1569+
public void readsPlainDocumentById() {
15701570

1571-
org.bson.Document dbObject = new org.bson.Document("foo", "bar");
1572-
template.save(dbObject, "collection");
1571+
org.bson.Document document = new org.bson.Document("foo", "bar");
1572+
template.save(document, "collection");
15731573

1574-
org.bson.Document result = template.findById(dbObject.get("_id"), org.bson.Document.class, "collection");
1575-
assertThat(result.get("foo"), is(dbObject.get("foo")));
1576-
assertThat(result.get("_id"), is(dbObject.get("_id")));
1574+
org.bson.Document result = template.findById(document.get("_id"), org.bson.Document.class, "collection");
1575+
assertThat(result.get("foo"), is(document.get("foo")));
1576+
assertThat(result.get("_id"), is(document.get("_id")));
15771577
}
15781578

15791579
/**
@@ -1735,9 +1735,9 @@ public void nullsValuesForUpdatesOfUnversionedEntity() {
17351735
@Test
17361736
public void savesJsonStringCorrectly() {
17371737

1738-
org.bson.Document dbObject = new org.bson.Document().append("first", "first").append("second", "second");
1738+
org.bson.Document document = new org.bson.Document().append("first", "first").append("second", "second");
17391739

1740-
template.save(dbObject, "collection");
1740+
template.save(document, "collection");
17411741

17421742
List<org.bson.Document> result = template.findAll(org.bson.Document.class, "collection");
17431743
assertThat(result.size(), is(1));
@@ -2992,7 +2992,7 @@ public void shouldReuseExistingDBRefInQueryFromDbRefAssociationAfterLoad() {
29922992
* @see DATAMONGO-970
29932993
*/
29942994
@Test
2995-
public void insertsAndRemovesBasicDbObjectCorrectly() {
2995+
public void insertsAndRemovesBasicDocumentCorrectly() {
29962996

29972997
org.bson.Document object = new org.bson.Document("key", "value");
29982998
template.insert(object, "collection");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 the original author or authors.
2+
* Copyright 2010-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -340,7 +340,7 @@ public void findAllAndRemoveShouldRemoveDocumentsReturedByFindQuery() {
340340

341341
verify(collection, times(1)).deleteMany(queryCaptor.capture());
342342

343-
Document idField = DBObjectTestUtils.getAsDocument(queryCaptor.getValue(), "_id");
343+
Document idField = DocumentTestUtils.getAsDocument(queryCaptor.getValue(), "_id");
344344
assertThat((List<Object>) idField.get("$in"),
345345
IsIterableContainingInOrder.<Object> contains(Integer.valueOf(0), Integer.valueOf(1)));
346346
}
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.mongodb.core;
217

318
import org.bson.Document;
419
import org.springframework.core.convert.converter.Converter;
520

21+
/**
22+
* @author Thomas Risberg
23+
* @author Oliver Gierke
24+
* @author Christoph Strobl
25+
* @author Mark Paluch
26+
*/
627
public class PersonWriteConverter implements Converter<Person, Document> {
728

829
public Document convert(Person source) {
9-
Document dbo = new Document();
10-
dbo.put("_id", source.getId());
11-
dbo.put("name", source.getFirstName());
12-
dbo.put("age", source.getAge());
13-
return dbo;
30+
Document document = new Document();
31+
document.put("_id", source.getId());
32+
document.put("name", source.getFirstName());
33+
document.put("age", source.getAge());
34+
return document;
1435
}
15-
1636
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ public class SerializationUtilsUnitTests {
4040
@Test
4141
public void writesSimpleDocument() {
4242

43-
Document dbObject = new Document("foo", "bar");
44-
assertThat(serializeToJsonSafely(dbObject), is("{ \"foo\" : \"bar\"}"));
43+
Document document = new Document("foo", "bar");
44+
assertThat(serializeToJsonSafely(document), is("{ \"foo\" : \"bar\"}"));
4545
}
4646

4747
@Test
4848
public void writesComplexObjectAsPlainToString() {
4949

50-
Document dbObject = new Document("foo", new Complex());
51-
assertThat(serializeToJsonSafely(dbObject),
50+
Document document = new Document("foo", new Complex());
51+
assertThat(serializeToJsonSafely(document),
5252
startsWith("{ \"foo\" : { $java : org.springframework.data.mongodb.core.SerializationUtilsUnitTests$Complex"));
5353
}
5454

5555
@Test
5656
public void writesCollection() {
5757

58-
Document dbObject = new Document("foo", Arrays.asList("bar", new Complex()));
58+
Document document = new Document("foo", Arrays.asList("bar", new Complex()));
5959
Matcher<String> expectedOutput = allOf(
6060
startsWith(
6161
"{ \"foo\" : [ \"bar\", { $java : org.springframework.data.mongodb.core.SerializationUtilsUnitTests$Complex"),
6262
endsWith(" } ] }"));
63-
assertThat(serializeToJsonSafely(dbObject), is(expectedOutput));
63+
assertThat(serializeToJsonSafely(document), is(expectedOutput));
6464
}
6565

6666
/**
@@ -69,12 +69,12 @@ public void writesCollection() {
6969
@Test
7070
public void flattenMapShouldFlatOutNestedStructureCorrectly() {
7171

72-
Document dbo = new Document();
73-
dbo.put("_id", 1);
74-
dbo.put("nested", new Document("value", "conflux"));
72+
Document document = new Document();
73+
document.put("_id", 1);
74+
document.put("nested", new Document("value", "conflux"));
7575

76-
assertThat(flattenMap(dbo), hasEntry("_id", (Object) 1));
77-
assertThat(flattenMap(dbo), hasEntry("nested.value", (Object) "conflux"));
76+
assertThat(flattenMap(document), hasEntry("_id", (Object) 1));
77+
assertThat(flattenMap(document), hasEntry("nested.value", (Object) "conflux"));
7878
}
7979

8080
/**
@@ -86,12 +86,12 @@ public void flattenMapShouldFlatOutNestedStructureWithListCorrectly() {
8686
BasicDBList dbl = new BasicDBList();
8787
dbl.addAll(Arrays.asList("nightwielder", "calamity"));
8888

89-
Document dbo = new Document();
90-
dbo.put("_id", 1);
91-
dbo.put("nested", new Document("value", dbl));
89+
Document document = new Document();
90+
document.put("_id", 1);
91+
document.put("nested", new Document("value", dbl));
9292

93-
assertThat(flattenMap(dbo), hasEntry("_id", (Object) 1));
94-
assertThat(flattenMap(dbo), hasEntry("nested.value", (Object) dbl));
93+
assertThat(flattenMap(document), hasEntry("_id", (Object) 1));
94+
assertThat(flattenMap(document), hasEntry("nested.value", (Object) dbl));
9595
}
9696

9797
/**
@@ -100,11 +100,11 @@ public void flattenMapShouldFlatOutNestedStructureWithListCorrectly() {
100100
@Test
101101
public void flattenMapShouldLeaveKeywordsUntouched() {
102102

103-
Document dbo = new Document();
104-
dbo.put("_id", 1);
105-
dbo.put("nested", new Document("$regex", "^conflux$"));
103+
Document document = new Document();
104+
document.put("_id", 1);
105+
document.put("nested", new Document("$regex", "^conflux$"));
106106

107-
Map<String, Object> map = flattenMap(dbo);
107+
Map<String, Object> map = flattenMap(document);
108108

109109
assertThat(map, hasEntry("_id", (Object) 1));
110110
assertThat(map.get("nested"), notNullValue());
@@ -117,14 +117,14 @@ public void flattenMapShouldLeaveKeywordsUntouched() {
117117
@Test
118118
public void flattenMapShouldAppendCommandsCorrectly() {
119119

120-
Document dbo = new Document();
120+
Document document = new Document();
121121
Document nested = new Document();
122122
nested.put("$regex", "^conflux$");
123123
nested.put("$options", "i");
124-
dbo.put("_id", 1);
125-
dbo.put("nested", nested);
124+
document.put("_id", 1);
125+
document.put("nested", nested);
126126

127-
Map<String, Object> map = flattenMap(dbo);
127+
Map<String, Object> map = flattenMap(document);
128128

129129
assertThat(map, hasEntry("_id", (Object) 1));
130130
assertThat(map.get("nested"), notNullValue());
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,9 +34,10 @@
3434
* Unit tests for {@link UnwrapAndReadDocumentCallback}.
3535
*
3636
* @author Oliver Gierke
37+
* @author Mark Paluch
3738
*/
3839
@RunWith(MockitoJUnitRunner.class)
39-
public class UnwrapAndReadDbObjectCallbackUnitTests {
40+
public class UnwrapAndReadDocumentCallbackUnitTests {
4041

4142
@Mock MongoDbFactory factory;
4243

@@ -62,7 +63,7 @@ public void usesFirstLevelValues() {
6263
}
6364

6465
@Test
65-
public void unwrapsUnderscoreIdIfBasicDocument() {
66+
public void unwrapsUnderscoreIdIfDocument() {
6667

6768
Target target = callback.doWith(new Document("_id", new Document("foo", "bar")));
6869

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -986,14 +986,14 @@ public void shouldPerformDateProjectionOperatorsCorrectly() throws ParseExceptio
986986
);
987987

988988
AggregationResults<Document> results = mongoTemplate.aggregate(agg, Document.class);
989-
Document dbo = results.getUniqueMappedResult();
989+
Document document = results.getUniqueMappedResult();
990990

991-
assertThat(dbo, is(notNullValue()));
992-
assertThat((String) dbo.get("concat"), is("ABCDE"));
993-
assertThat((Integer) dbo.get("strcasecmp"), is(-1));
994-
assertThat((String) dbo.get("substr"), is("B"));
995-
assertThat((String) dbo.get("toLower"), is("abc"));
996-
assertThat((String) dbo.get("toUpper"), is("ABC"));
991+
assertThat(document, is(notNullValue()));
992+
assertThat((String) document.get("concat"), is("ABCDE"));
993+
assertThat((Integer) document.get("strcasecmp"), is(-1));
994+
assertThat((String) document.get("substr"), is("B"));
995+
assertThat((String) document.get("toLower"), is("abc"));
996+
assertThat((String) document.get("toUpper"), is("ABC"));
997997
}
998998

999999
/**
@@ -1023,19 +1023,19 @@ public void shouldPerformStringProjectionOperatorsCorrectly() throws ParseExcept
10231023
);
10241024

10251025
AggregationResults<Document> results = mongoTemplate.aggregate(agg, Document.class);
1026-
Document dbo = results.getUniqueMappedResult();
1026+
Document document = results.getUniqueMappedResult();
10271027

1028-
assertThat(dbo, is(notNullValue()));
1029-
assertThat((Integer) dbo.get("dayOfYear"), is(241));
1030-
assertThat((Integer) dbo.get("dayOfMonth"), is(29));
1031-
assertThat((Integer) dbo.get("dayOfWeek"), is(2));
1032-
assertThat((Integer) dbo.get("year"), is(1983));
1033-
assertThat((Integer) dbo.get("month"), is(8));
1034-
assertThat((Integer) dbo.get("week"), is(35));
1035-
assertThat((Integer) dbo.get("hour"), is(12));
1036-
assertThat((Integer) dbo.get("minute"), is(34));
1037-
assertThat((Integer) dbo.get("second"), is(56));
1038-
assertThat((Integer) dbo.get("millisecond"), is(789));
1028+
assertThat(document, is(notNullValue()));
1029+
assertThat((Integer) document.get("dayOfYear"), is(241));
1030+
assertThat((Integer) document.get("dayOfMonth"), is(29));
1031+
assertThat((Integer) document.get("dayOfWeek"), is(2));
1032+
assertThat((Integer) document.get("year"), is(1983));
1033+
assertThat((Integer) document.get("month"), is(8));
1034+
assertThat((Integer) document.get("week"), is(35));
1035+
assertThat((Integer) document.get("hour"), is(12));
1036+
assertThat((Integer) document.get("minute"), is(34));
1037+
assertThat((Integer) document.get("second"), is(56));
1038+
assertThat((Integer) document.get("millisecond"), is(789));
10391039
}
10401040

10411041
/**
@@ -1316,23 +1316,23 @@ public void shouldRetrieveDateTimeFragementsCorrectly() throws Exception {
13161316
AggregationResults<Document> result = mongoTemplate.aggregate(agg, ObjectWithDate.class, Document.class);
13171317

13181318
assertThat(result.getMappedResults(), hasSize(1));
1319-
Document dbo = result.getMappedResults().get(0);
1320-
1321-
assertThat(dbo.get("hour"), is((Object) dateTime.getHourOfDay()));
1322-
assertThat(dbo.get("min"), is((Object) dateTime.getMinuteOfHour()));
1323-
assertThat(dbo.get("second"), is((Object) dateTime.getSecondOfMinute()));
1324-
assertThat(dbo.get("millis"), is((Object) dateTime.getMillisOfSecond()));
1325-
assertThat(dbo.get("year"), is((Object) dateTime.getYear()));
1326-
assertThat(dbo.get("month"), is((Object) dateTime.getMonthOfYear()));
1319+
Document document = result.getMappedResults().get(0);
1320+
1321+
assertThat(document.get("hour"), is((Object) dateTime.getHourOfDay()));
1322+
assertThat(document.get("min"), is((Object) dateTime.getMinuteOfHour()));
1323+
assertThat(document.get("second"), is((Object) dateTime.getSecondOfMinute()));
1324+
assertThat(document.get("millis"), is((Object) dateTime.getMillisOfSecond()));
1325+
assertThat(document.get("year"), is((Object) dateTime.getYear()));
1326+
assertThat(document.get("month"), is((Object) dateTime.getMonthOfYear()));
13271327
// dateTime.getWeekOfWeekyear()) returns 6 since for MongoDB the week starts on sunday and not on monday.
1328-
assertThat(dbo.get("week"), is((Object) 5));
1329-
assertThat(dbo.get("dayOfYear"), is((Object) dateTime.getDayOfYear()));
1330-
assertThat(dbo.get("dayOfMonth"), is((Object) dateTime.getDayOfMonth()));
1328+
assertThat(document.get("week"), is((Object) 5));
1329+
assertThat(document.get("dayOfYear"), is((Object) dateTime.getDayOfYear()));
1330+
assertThat(document.get("dayOfMonth"), is((Object) dateTime.getDayOfMonth()));
13311331

13321332
// dateTime.getDayOfWeek()
1333-
assertThat(dbo.get("dayOfWeek"), is((Object) 6));
1334-
assertThat(dbo.get("dayOfYearPlus1Day"), is((Object) dateTime.plusDays(1).getDayOfYear()));
1335-
assertThat(dbo.get("dayOfYearPlus1DayManually"), is((Object) dateTime.plusDays(1).getDayOfYear()));
1333+
assertThat(document.get("dayOfWeek"), is((Object) 6));
1334+
assertThat(document.get("dayOfYearPlus1Day"), is((Object) dateTime.plusDays(1).getDayOfYear()));
1335+
assertThat(document.get("dayOfYearPlus1DayManually"), is((Object) dateTime.plusDays(1).getDayOfYear()));
13361336
}
13371337

13381338
/**

0 commit comments

Comments
 (0)