Skip to content

Commit 02229f2

Browse files
committed
Polishing.
Reformat code. See #3998
1 parent 1009491 commit 02229f2

File tree

2 files changed

+33
-55
lines changed

2 files changed

+33
-55
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ public <R> R project(EntityProjection<R, ?> projection, Bson bson) {
302302
}
303303

304304
@SuppressWarnings("unchecked")
305-
private <R> R doReadProjection(ConversionContext context, Bson bson,
306-
EntityProjection<R, ?> projection) {
305+
private <R> R doReadProjection(ConversionContext context, Bson bson, EntityProjection<R, ?> projection) {
307306

308307
MongoPersistentEntity<?> entity = getMappingContext().getRequiredPersistentEntity(projection.getActualDomainType());
309308
TypeInformation<?> mappedType = projection.getActualMappedType();
@@ -631,8 +630,7 @@ private void readProperties(ConversionContext context, MongoPersistentEntity<?>
631630
}
632631

633632
readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback,
634-
propertyContext,
635-
evaluator);
633+
propertyContext, evaluator);
636634
continue;
637635
}
638636

@@ -654,8 +652,7 @@ private void readProperties(ConversionContext context, MongoPersistentEntity<?>
654652
}
655653

656654
readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback,
657-
propertyContext,
658-
evaluator);
655+
propertyContext, evaluator);
659656
continue;
660657
}
661658

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

+30-49
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,6 @@ void shouldUseMostConcreteCustomConversionTargetOnRead() {
24112411
verify(subTypeOfGenericTypeConverter).convert(eq(source));
24122412
}
24132413

2414-
24152414
@Test // GH-3660
24162415
void usesCustomConverterForMapTypesOnWrite() {
24172416

@@ -2455,9 +2454,8 @@ void usesCustomConverterForTypesImplementingMapOnRead() {
24552454
}));
24562455
converter.afterPropertiesSet();
24572456

2458-
org.bson.Document source = new org.bson.Document("1st", "one")
2459-
.append("2nd", 2)
2460-
.append("_class", TypeImplementingMap.class.getName());
2457+
org.bson.Document source = new org.bson.Document("1st", "one").append("2nd", 2).append("_class",
2458+
TypeImplementingMap.class.getName());
24612459

24622460
TypeImplementingMap target = converter.read(TypeImplementingMap.class, source);
24632461

@@ -2492,9 +2490,8 @@ void usesCustomConverterForPropertiesUsingTypesImplementingMapOnRead() {
24922490
converter.afterPropertiesSet();
24932491

24942492
org.bson.Document source = new org.bson.Document("typeImplementingMap",
2495-
new org.bson.Document("1st", "one")
2496-
.append("2nd", 2))
2497-
.append("_class", TypeWrappingTypeImplementingMap.class.getName());
2493+
new org.bson.Document("1st", "one").append("2nd", 2)).append("_class",
2494+
TypeWrappingTypeImplementingMap.class.getName());
24982495

24992496
TypeWrappingTypeImplementingMap target = converter.read(TypeWrappingTypeImplementingMap.class, source);
25002497

@@ -2516,13 +2513,12 @@ void shouldWriteNullPropertyCorrectly() {
25162513
@Test // GH-3686
25172514
void readsCollectionContainingNullValue() {
25182515

2519-
org.bson.Document source = new org.bson.Document("items", Arrays.asList(new org.bson.Document("itemKey", "i1"), null, new org.bson.Document("itemKey", "i3")));
2516+
org.bson.Document source = new org.bson.Document("items",
2517+
Arrays.asList(new org.bson.Document("itemKey", "i1"), null, new org.bson.Document("itemKey", "i3")));
25202518

25212519
Order target = converter.read(Order.class, source);
25222520

2523-
assertThat(target.items)
2524-
.map(it -> it != null ? it.itemKey : null)
2525-
.containsExactly("i1", null, "i3");
2521+
assertThat(target.items).map(it -> it != null ? it.itemKey : null).containsExactly("i1", null, "i3");
25262522
}
25272523

25282524
@Test // GH-3686
@@ -2538,14 +2534,13 @@ void readsArrayContainingNullValue() {
25382534
@Test // GH-3686
25392535
void readsMapContainingNullValue() {
25402536

2541-
org.bson.Document source = new org.bson.Document("mapOfObjects", new org.bson.Document("item1", "i1").append("item2", null).append("item3", "i3"));
2537+
org.bson.Document source = new org.bson.Document("mapOfObjects",
2538+
new org.bson.Document("item1", "i1").append("item2", null).append("item3", "i3"));
25422539

25432540
ClassWithMapProperty target = converter.read(ClassWithMapProperty.class, source);
25442541

2545-
assertThat(target.mapOfObjects)
2546-
.containsEntry("item1", "i1")
2547-
.containsEntry("item2", null)
2548-
.containsEntry("item3", "i3");
2542+
assertThat(target.mapOfObjects).containsEntry("item1", "i1").containsEntry("item2", null).containsEntry("item3",
2543+
"i3");
25492544
}
25502545

25512546
@Test // GH-3670
@@ -2557,7 +2552,7 @@ void appliesCustomConverterEvenToSimpleTypes() {
25572552
}));
25582553
converter.afterPropertiesSet();
25592554

2560-
org.bson.Document source = new org.bson.Document("content", new Binary(new byte[] {0x00, 0x42}));
2555+
org.bson.Document source = new org.bson.Document("content", new Binary(new byte[] { 0x00, 0x42 }));
25612556

25622557
GenericType<Object> target = converter.read(GenericType.class, source);
25632558
assertThat(target.content).isInstanceOf(byte[].class);
@@ -2566,17 +2561,20 @@ void appliesCustomConverterEvenToSimpleTypes() {
25662561
@Test // GH-3702
25672562
void readsRawDocument() {
25682563

2569-
org.bson.Document source = new org.bson.Document("_id", "id-1").append("raw", new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1)));
2564+
org.bson.Document source = new org.bson.Document("_id", "id-1").append("raw",
2565+
new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1)));
25702566

25712567
WithRawDocumentProperties target = converter.read(WithRawDocumentProperties.class, source);
25722568

2573-
assertThat(target.raw).isInstanceOf(org.bson.Document.class).isEqualTo( new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1)));
2569+
assertThat(target.raw).isInstanceOf(org.bson.Document.class)
2570+
.isEqualTo(new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1)));
25742571
}
25752572

25762573
@Test // GH-3702
25772574
void readsListOfRawDocument() {
25782575

2579-
org.bson.Document source = new org.bson.Document("_id", "id-1").append("listOfRaw", Arrays.asList(new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1))));
2576+
org.bson.Document source = new org.bson.Document("_id", "id-1").append("listOfRaw",
2577+
Arrays.asList(new org.bson.Document("simple", 1).append("document", new org.bson.Document("inner-doc", 1))));
25802578

25812579
WithRawDocumentProperties target = converter.read(WithRawDocumentProperties.class, source);
25822580

@@ -2587,11 +2585,12 @@ void readsListOfRawDocument() {
25872585
@Test // GH-3692
25882586
void readsMapThatDoesNotComeAsDocument() {
25892587

2590-
org.bson.Document source = new org.bson.Document("_id", "id-1").append("mapOfObjects", Collections.singletonMap("simple", 1));
2588+
org.bson.Document source = new org.bson.Document("_id", "id-1").append("mapOfObjects",
2589+
Collections.singletonMap("simple", 1));
25912590

25922591
ClassWithMapProperty target = converter.read(ClassWithMapProperty.class, source);
25932592

2594-
assertThat(target.mapOfObjects).containsEntry("simple",1);
2593+
assertThat(target.mapOfObjects).containsEntry("simple", 1);
25952594
}
25962595

25972596
@Test // GH-3851
@@ -2611,23 +2610,22 @@ void readsMapThatDoesNotComeAsDocument() {
26112610

26122611
converter.writePropertyInternal(sourceValue, accessor, persistentProperty);
26132612

2614-
assertThat(accessor.getDocument()).isEqualTo(new org.bson.Document("pName", new org.bson.Document("_id", id.toString())));
2613+
assertThat(accessor.getDocument())
2614+
.isEqualTo(new org.bson.Document("pName", new org.bson.Document("_id", id.toString())));
26152615
}
26162616

26172617
@Test // GH-2860
26182618
void projectShouldReadSimpleInterfaceProjection() {
26192619

26202620
org.bson.Document source = new org.bson.Document("birthDate",
2621-
Date.from(LocalDate.of(1999, 12, 1).atStartOfDay().toInstant(ZoneOffset.UTC))).append("foo",
2622-
"Walter");
2621+
Date.from(LocalDate.of(1999, 12, 1).atStartOfDay().toInstant(ZoneOffset.UTC))).append("foo", "Walter");
26232622

26242623
EntityProjectionIntrospector discoverer = EntityProjectionIntrospector.create(converter.getProjectionFactory(),
26252624
EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy()
26262625
.and((target, underlyingType) -> !converter.conversions.isSimpleType(target)),
26272626
mappingContext);
26282627

2629-
EntityProjection<PersonProjection, Person> projection = discoverer
2630-
.introspect(PersonProjection.class, Person.class);
2628+
EntityProjection<PersonProjection, Person> projection = discoverer.introspect(PersonProjection.class, Person.class);
26312629
PersonProjection person = converter.project(projection, source);
26322630

26332631
assertThat(person.getBirthDate()).isEqualTo(LocalDate.of(1999, 12, 1));
@@ -2638,16 +2636,14 @@ void projectShouldReadSimpleInterfaceProjection() {
26382636
void projectShouldReadSimpleDtoProjection() {
26392637

26402638
org.bson.Document source = new org.bson.Document("birthDate",
2641-
Date.from(LocalDate.of(1999, 12, 1).atStartOfDay().toInstant(ZoneOffset.UTC))).append("foo",
2642-
"Walter");
2639+
Date.from(LocalDate.of(1999, 12, 1).atStartOfDay().toInstant(ZoneOffset.UTC))).append("foo", "Walter");
26432640

26442641
EntityProjectionIntrospector introspector = EntityProjectionIntrospector.create(converter.getProjectionFactory(),
26452642
EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy()
26462643
.and((target, underlyingType) -> !converter.conversions.isSimpleType(target)),
26472644
mappingContext);
26482645

2649-
EntityProjection<PersonDto, Person> projection = introspector
2650-
.introspect(PersonDto.class, Person.class);
2646+
EntityProjection<PersonDto, Person> projection = introspector.introspect(PersonDto.class, Person.class);
26512647
PersonDto person = converter.project(projection, source);
26522648

26532649
assertThat(person.getBirthDate()).isEqualTo(LocalDate.of(1999, 12, 1));
@@ -2738,8 +2734,7 @@ interface InterfaceType {
27382734
@EqualsAndHashCode
27392735
@Getter
27402736
static class Address implements InterfaceType {
2741-
@Field("s")
2742-
String street;
2737+
@Field("s") String street;
27432738
String city;
27442739
}
27452740

@@ -3340,7 +3335,7 @@ static class TypeWrappingTypeImplementingMap {
33403335
}
33413336

33423337
@EqualsAndHashCode
3343-
static class TypeImplementingMap implements Map<String,String> {
3338+
static class TypeImplementingMap implements Map<String, String> {
33443339

33453340
String val1;
33463341
int val2;
@@ -3455,15 +3450,9 @@ static class Book {
34553450

34563451
Author author = new Author();
34573452

3458-
public Book() {}
3459-
3460-
public Book(String id, String name, Author author) {
3461-
this.id = id;
3462-
this.name = name;
3463-
this.author = author;
3464-
}
34653453
}
34663454

3455+
@Data
34673456
static class Author {
34683457

34693458
@Id String id;
@@ -3472,14 +3461,6 @@ static class Author {
34723461

34733462
String lastName;
34743463

3475-
public Author() {}
3476-
3477-
public Author(String id, String firstName, String lastName) {
3478-
this.id = id;
3479-
this.firstName = firstName;
3480-
this.lastName = lastName;
3481-
}
3482-
34833464
}
34843465

34853466
}

0 commit comments

Comments
 (0)