Browse Source

Polishing.

Reformat code.

See #3660.
Original pull request: #3662.
pull/860/head
Mark Paluch 5 years ago
parent
commit
2b715c54d3
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 35
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java
  2. 28
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java

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

@ -171,8 +171,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -171,8 +171,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
Assert.notNull(path, "ObjectPath must not be null");
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap, this::readDBRef,
this::getPotentiallyConvertedSimpleRead);
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap,
this::readDBRef, this::getPotentiallyConvertedSimpleRead);
}
/**
@ -527,7 +527,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -527,7 +527,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
return;
}
if (property.isDocumentReference() || (!property.isDbReference() && property.findAnnotation(Reference.class) != null)) {
if (property.isDocumentReference()
|| (!property.isDbReference() && property.findAnnotation(Reference.class) != null)) {
// quite unusual but sounds like worth having?
@ -595,13 +596,13 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -595,13 +596,13 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
Assert.notNull(referringProperty, "Cannot create DocumentReference. The referringProperty must not be null!");
if (referringProperty.isDbReference()) {
return () -> toDBRef(source, referringProperty);
}
if (referringProperty.isDbReference()) {
return () -> toDBRef(source, referringProperty);
}
if (referringProperty.isDocumentReference() || referringProperty.findAnnotation(Reference.class) != null) {
return createDocumentPointer(source, referringProperty);
}
if (referringProperty.isDocumentReference() || referringProperty.findAnnotation(Reference.class) != null) {
return createDocumentPointer(source, referringProperty);
}
throw new IllegalArgumentException("The referringProperty is neither a DBRef nor a document reference");
}
@ -612,7 +613,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -612,7 +613,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
return () -> source;
}
if(source instanceof DocumentPointer) {
if (source instanceof DocumentPointer) {
return (DocumentPointer<?>) source;
}
@ -622,7 +623,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -622,7 +623,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
}
if (ClassUtils.isAssignableValue(referringProperty.getAssociationTargetType(), source)) {
return documentPointerFactory.computePointer(mappingContext, referringProperty, source, referringProperty.getActualType());
return documentPointerFactory.computePointer(mappingContext, referringProperty, source,
referringProperty.getActualType());
}
return () -> source;
@ -1978,9 +1980,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -1978,9 +1980,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
private final ContainerValueConverter<DBRef> dbRefConverter;
private final ValueConverter<Object> elementConverter;
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path, ContainerValueConverter<Bson> documentConverter,
ContainerValueConverter<Collection<?>> collectionConverter, ContainerValueConverter<Bson> mapConverter,
ContainerValueConverter<DBRef> dbRefConverter, ValueConverter<Object> elementConverter) {
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path,
ContainerValueConverter<Bson> documentConverter, ContainerValueConverter<Collection<?>> collectionConverter,
ContainerValueConverter<Bson> mapConverter, ContainerValueConverter<DBRef> dbRefConverter,
ValueConverter<Object> elementConverter) {
this.conversions = customConversions;
this.path = path;
@ -2052,8 +2055,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App @@ -2052,8 +2055,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
Assert.notNull(currentPath, "ObjectPath must not be null");
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter, dbRefConverter,
elementConverter);
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter,
dbRefConverter, elementConverter);
}
public ObjectPath getPath() {

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

@ -30,7 +30,6 @@ import java.time.LocalDateTime; @@ -30,7 +30,6 @@ import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import org.assertj.core.api.Assertions;
import org.bson.types.Code;
import org.bson.types.Decimal128;
import org.bson.types.ObjectId;
@ -42,6 +41,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @@ -42,6 +41,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.beans.factory.annotation.Value;
@ -529,7 +529,7 @@ class MappingMongoConverterUnitTests { @@ -529,7 +529,7 @@ class MappingMongoConverterUnitTests {
}
@Test
public void convertsObjectsIfNecessary() {
void convertsObjectsIfNecessary() {
ObjectId id = new ObjectId();
assertThat(converter.convertToMongoType(id)).isEqualTo(id);
@ -2113,21 +2113,21 @@ class MappingMongoConverterUnitTests { @@ -2113,21 +2113,21 @@ class MappingMongoConverterUnitTests {
}
@Test // DATAMONGO-2479
public void entityCallbacksAreNotSetByDefault() {
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
void entityCallbacksAreNotSetByDefault() {
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
}
@Test // DATAMONGO-2479
public void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
ApplicationContext ctx = new StaticApplicationContext();
converter.setApplicationContext(ctx);
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
}
@Test // DATAMONGO-2479
public void setterForEntityCallbackOverridesContextInitializedOnes() {
void setterForEntityCallbackOverridesContextInitializedOnes() {
ApplicationContext ctx = new StaticApplicationContext();
converter.setApplicationContext(ctx);
@ -2135,11 +2135,11 @@ class MappingMongoConverterUnitTests { @@ -2135,11 +2135,11 @@ class MappingMongoConverterUnitTests {
EntityCallbacks callbacks = EntityCallbacks.create();
converter.setEntityCallbacks(callbacks);
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
}
@Test // DATAMONGO-2479
public void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
EntityCallbacks callbacks = EntityCallbacks.create();
ApplicationContext ctx = new StaticApplicationContext();
@ -2147,11 +2147,11 @@ class MappingMongoConverterUnitTests { @@ -2147,11 +2147,11 @@ class MappingMongoConverterUnitTests {
converter.setEntityCallbacks(callbacks);
converter.setApplicationContext(ctx);
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
}
@Test // DATAMONGO-2479
public void resolveDBRefMapValueShouldInvokeCallbacks() {
void resolveDBRefMapValueShouldInvokeCallbacks() {
AfterConvertCallback<Person> afterConvertCallback = spy(new ReturningAfterConvertCallback());
converter.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
@ -2168,7 +2168,7 @@ class MappingMongoConverterUnitTests { @@ -2168,7 +2168,7 @@ class MappingMongoConverterUnitTests {
}
@Test // DATAMONGO-2300
public void readAndConvertDBRefNestedByMapCorrectly() {
void readAndConvertDBRefNestedByMapCorrectly() {
org.bson.Document cluster = new org.bson.Document("_id", 100L);
DBRef dbRef = new DBRef("clusters", 100L);
@ -2434,7 +2434,6 @@ class MappingMongoConverterUnitTests { @@ -2434,7 +2434,6 @@ class MappingMongoConverterUnitTests {
@Test // GH-3660
void usesCustomConverterForMapTypesOnWrite() {
converter = new MappingMongoConverter(resolver, mappingContext);
converter.setCustomConversions(MongoCustomConversions.create(it -> {
it.registerConverter(new TypeImplementingMapToDocumentConverter());
@ -2521,7 +2520,6 @@ class MappingMongoConverterUnitTests { @@ -2521,7 +2520,6 @@ class MappingMongoConverterUnitTests {
assertThat(target.typeImplementingMap).isEqualTo(new TypeImplementingMap("one", 2));
}
static class GenericType<T> {
T content;
}
@ -3098,7 +3096,7 @@ class MappingMongoConverterUnitTests { @@ -3098,7 +3096,7 @@ class MappingMongoConverterUnitTests {
String val1;
int val2;
public TypeImplementingMap(String val1, int val2) {
TypeImplementingMap(String val1, int val2) {
this.val1 = val1;
this.val2 = val2;
}

Loading…
Cancel
Save