Skip to content

Commit 2b715c5

Browse files
committed
Polishing.
Reformat code. See #3660. Original pull request: #3662.
1 parent ece261a commit 2b715c5

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ protected ConversionContext getConversionContext(ObjectPath path) {
171171

172172
Assert.notNull(path, "ObjectPath must not be null");
173173

174-
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap, this::readDBRef,
175-
this::getPotentiallyConvertedSimpleRead);
174+
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap,
175+
this::readDBRef, this::getPotentiallyConvertedSimpleRead);
176176
}
177177

178178
/**
@@ -527,7 +527,8 @@ private void readAssociation(Association<MongoPersistentProperty> association, P
527527
return;
528528
}
529529

530-
if (property.isDocumentReference() || (!property.isDbReference() && property.findAnnotation(Reference.class) != null)) {
530+
if (property.isDocumentReference()
531+
|| (!property.isDbReference() && property.findAnnotation(Reference.class) != null)) {
531532

532533
// quite unusual but sounds like worth having?
533534

@@ -595,13 +596,13 @@ public DocumentPointer toDocumentPointer(Object source, @Nullable MongoPersisten
595596

596597
Assert.notNull(referringProperty, "Cannot create DocumentReference. The referringProperty must not be null!");
597598

598-
if (referringProperty.isDbReference()) {
599-
return () -> toDBRef(source, referringProperty);
600-
}
599+
if (referringProperty.isDbReference()) {
600+
return () -> toDBRef(source, referringProperty);
601+
}
601602

602-
if (referringProperty.isDocumentReference() || referringProperty.findAnnotation(Reference.class) != null) {
603-
return createDocumentPointer(source, referringProperty);
604-
}
603+
if (referringProperty.isDocumentReference() || referringProperty.findAnnotation(Reference.class) != null) {
604+
return createDocumentPointer(source, referringProperty);
605+
}
605606

606607
throw new IllegalArgumentException("The referringProperty is neither a DBRef nor a document reference");
607608
}
@@ -612,7 +613,7 @@ DocumentPointer<?> createDocumentPointer(Object source, @Nullable MongoPersisten
612613
return () -> source;
613614
}
614615

615-
if(source instanceof DocumentPointer) {
616+
if (source instanceof DocumentPointer) {
616617
return (DocumentPointer<?>) source;
617618
}
618619

@@ -622,7 +623,8 @@ DocumentPointer<?> createDocumentPointer(Object source, @Nullable MongoPersisten
622623
}
623624

624625
if (ClassUtils.isAssignableValue(referringProperty.getAssociationTargetType(), source)) {
625-
return documentPointerFactory.computePointer(mappingContext, referringProperty, source, referringProperty.getActualType());
626+
return documentPointerFactory.computePointer(mappingContext, referringProperty, source,
627+
referringProperty.getActualType());
626628
}
627629

628630
return () -> source;
@@ -1978,9 +1980,10 @@ protected static class ConversionContext {
19781980
private final ContainerValueConverter<DBRef> dbRefConverter;
19791981
private final ValueConverter<Object> elementConverter;
19801982

1981-
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path, ContainerValueConverter<Bson> documentConverter,
1982-
ContainerValueConverter<Collection<?>> collectionConverter, ContainerValueConverter<Bson> mapConverter,
1983-
ContainerValueConverter<DBRef> dbRefConverter, ValueConverter<Object> elementConverter) {
1983+
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path,
1984+
ContainerValueConverter<Bson> documentConverter, ContainerValueConverter<Collection<?>> collectionConverter,
1985+
ContainerValueConverter<Bson> mapConverter, ContainerValueConverter<DBRef> dbRefConverter,
1986+
ValueConverter<Object> elementConverter) {
19841987

19851988
this.conversions = customConversions;
19861989
this.path = path;
@@ -2052,8 +2055,8 @@ public ConversionContext withPath(ObjectPath currentPath) {
20522055

20532056
Assert.notNull(currentPath, "ObjectPath must not be null");
20542057

2055-
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter, dbRefConverter,
2056-
elementConverter);
2058+
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter,
2059+
dbRefConverter, elementConverter);
20572060
}
20582061

20592062
public ObjectPath getPath() {

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

+13-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.time.temporal.ChronoUnit;
3131
import java.util.*;
3232

33-
import org.assertj.core.api.Assertions;
3433
import org.bson.types.Code;
3534
import org.bson.types.Decimal128;
3635
import org.bson.types.ObjectId;
@@ -42,6 +41,7 @@
4241
import org.mockito.Mock;
4342
import org.mockito.Mockito;
4443
import org.mockito.junit.jupiter.MockitoExtension;
44+
4545
import org.springframework.aop.framework.ProxyFactory;
4646
import org.springframework.beans.ConversionNotSupportedException;
4747
import org.springframework.beans.factory.annotation.Value;
@@ -529,7 +529,7 @@ void writesBigIntegerIdCorrectly() {
529529
}
530530

531531
@Test
532-
public void convertsObjectsIfNecessary() {
532+
void convertsObjectsIfNecessary() {
533533

534534
ObjectId id = new ObjectId();
535535
assertThat(converter.convertToMongoType(id)).isEqualTo(id);
@@ -2113,45 +2113,45 @@ void shouldAllowReadingBackDbObject() {
21132113
}
21142114

21152115
@Test // DATAMONGO-2479
2116-
public void entityCallbacksAreNotSetByDefault() {
2117-
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
2116+
void entityCallbacksAreNotSetByDefault() {
2117+
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
21182118
}
21192119

21202120
@Test // DATAMONGO-2479
2121-
public void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
2121+
void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
21222122

21232123
ApplicationContext ctx = new StaticApplicationContext();
21242124
converter.setApplicationContext(ctx);
21252125

2126-
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
2126+
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
21272127
}
21282128

21292129
@Test // DATAMONGO-2479
2130-
public void setterForEntityCallbackOverridesContextInitializedOnes() {
2130+
void setterForEntityCallbackOverridesContextInitializedOnes() {
21312131

21322132
ApplicationContext ctx = new StaticApplicationContext();
21332133
converter.setApplicationContext(ctx);
21342134

21352135
EntityCallbacks callbacks = EntityCallbacks.create();
21362136
converter.setEntityCallbacks(callbacks);
21372137

2138-
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
2138+
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
21392139
}
21402140

21412141
@Test // DATAMONGO-2479
2142-
public void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
2142+
void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
21432143

21442144
EntityCallbacks callbacks = EntityCallbacks.create();
21452145
ApplicationContext ctx = new StaticApplicationContext();
21462146

21472147
converter.setEntityCallbacks(callbacks);
21482148
converter.setApplicationContext(ctx);
21492149

2150-
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
2150+
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
21512151
}
21522152

21532153
@Test // DATAMONGO-2479
2154-
public void resolveDBRefMapValueShouldInvokeCallbacks() {
2154+
void resolveDBRefMapValueShouldInvokeCallbacks() {
21552155

21562156
AfterConvertCallback<Person> afterConvertCallback = spy(new ReturningAfterConvertCallback());
21572157
converter.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
@@ -2168,7 +2168,7 @@ public void resolveDBRefMapValueShouldInvokeCallbacks() {
21682168
}
21692169

21702170
@Test // DATAMONGO-2300
2171-
public void readAndConvertDBRefNestedByMapCorrectly() {
2171+
void readAndConvertDBRefNestedByMapCorrectly() {
21722172

21732173
org.bson.Document cluster = new org.bson.Document("_id", 100L);
21742174
DBRef dbRef = new DBRef("clusters", 100L);
@@ -2434,7 +2434,6 @@ void shouldUseMostConcreteCustomConversionTargetOnRead() {
24342434
@Test // GH-3660
24352435
void usesCustomConverterForMapTypesOnWrite() {
24362436

2437-
24382437
converter = new MappingMongoConverter(resolver, mappingContext);
24392438
converter.setCustomConversions(MongoCustomConversions.create(it -> {
24402439
it.registerConverter(new TypeImplementingMapToDocumentConverter());
@@ -2521,7 +2520,6 @@ void usesCustomConverterForPropertiesUsingTypesImplementingMapOnRead() {
25212520
assertThat(target.typeImplementingMap).isEqualTo(new TypeImplementingMap("one", 2));
25222521
}
25232522

2524-
25252523
static class GenericType<T> {
25262524
T content;
25272525
}
@@ -3098,7 +3096,7 @@ static class TypeImplementingMap implements Map<String,String> {
30983096
String val1;
30993097
int val2;
31003098

3101-
public TypeImplementingMap(String val1, int val2) {
3099+
TypeImplementingMap(String val1, int val2) {
31023100
this.val1 = val1;
31033101
this.val2 = val2;
31043102
}

0 commit comments

Comments
 (0)