Skip to content

Commit ee203bf

Browse files
committed
Polishing.
Reformat code. See #3660. Original pull request: #3662.
1 parent 990696b commit ee203bf

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

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

+16-20
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ public MappingMongoConverter(DbRefResolver dbRefResolver,
141141
this::getWriteTarget);
142142
this.idMapper = new QueryMapper(this);
143143

144-
145144
this.spELContext = new SpELContext(DocumentPropertyAccessor.INSTANCE);
146145
this.dbRefProxyHandler = new DefaultDbRefProxyHandler(spELContext, mappingContext,
147146
(prop, bson, evaluator, path) -> {
@@ -161,8 +160,8 @@ protected ConversionContext getConversionContext(ObjectPath path) {
161160

162161
Assert.notNull(path, "ObjectPath must not be null");
163162

164-
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap, this::readDBRef,
165-
this::getPotentiallyConvertedSimpleRead);
163+
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap,
164+
this::readDBRef, this::getPotentiallyConvertedSimpleRead);
166165
}
167166

168167
/**
@@ -376,8 +375,7 @@ private <S extends Object> S read(ConversionContext context, MongoPersistentEnti
376375
}
377376

378377
private <S> S populateProperties(ConversionContext context, MongoPersistentEntity<S> entity,
379-
DocumentAccessor documentAccessor,
380-
SpELExpressionEvaluator evaluator, S instance) {
378+
DocumentAccessor documentAccessor, SpELExpressionEvaluator evaluator, S instance) {
381379

382380
PersistentPropertyAccessor<S> accessor = new ConvertingPropertyAccessor<>(entity.getPropertyAccessor(instance),
383381
conversionService);
@@ -423,8 +421,7 @@ private Object readAndPopulateIdentifier(ConversionContext context, PersistentPr
423421

424422
@Nullable
425423
private Object readIdValue(ConversionContext context, SpELExpressionEvaluator evaluator,
426-
MongoPersistentProperty idProperty,
427-
Object rawId) {
424+
MongoPersistentProperty idProperty, Object rawId) {
428425

429426
String expression = idProperty.getSpelExpression();
430427
Object resolvedValue = expression != null ? evaluator.evaluate(expression) : rawId;
@@ -434,8 +431,7 @@ private Object readIdValue(ConversionContext context, SpELExpressionEvaluator ev
434431

435432
private void readProperties(ConversionContext context, MongoPersistentEntity<?> entity,
436433
PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor,
437-
MongoDbPropertyValueProvider valueProvider,
438-
SpELExpressionEvaluator evaluator) {
434+
MongoDbPropertyValueProvider valueProvider, SpELExpressionEvaluator evaluator) {
439435

440436
DbRefResolverCallback callback = null;
441437

@@ -505,8 +501,7 @@ private void readAssociation(Association<MongoPersistentProperty> association, P
505501

506502
@Nullable
507503
private Object readUnwrapped(ConversionContext context, DocumentAccessor documentAccessor,
508-
MongoPersistentProperty prop,
509-
MongoPersistentEntity<?> unwrappedEntity) {
504+
MongoPersistentProperty prop, MongoPersistentEntity<?> unwrappedEntity) {
510505

511506
if (prop.findAnnotation(Unwrapped.class).onEmpty().equals(OnEmpty.USE_EMPTY)) {
512507
return read(context, unwrappedEntity, (Document) documentAccessor.getDocument());
@@ -1447,8 +1442,7 @@ private <T> List<T> bulkReadAndConvertDBRefs(ConversionContext context, List<DBR
14471442
T target = null;
14481443
if (document != null) {
14491444

1450-
maybeEmitEvent(
1451-
new AfterLoadEvent<>(document, (Class<T>) type.getType(), collectionName));
1445+
maybeEmitEvent(new AfterLoadEvent<>(document, (Class<T>) type.getType(), collectionName));
14521446
target = (T) readDocument(context, document, type);
14531447
}
14541448

@@ -1541,9 +1535,10 @@ private <T extends Object> T doConvert(Object value, Class<? extends T> target)
15411535
}
15421536

15431537
@SuppressWarnings("ConstantConditions")
1544-
private <T extends Object> T doConvert(Object value, Class<? extends T> target, @Nullable Class<? extends T> fallback) {
1538+
private <T extends Object> T doConvert(Object value, Class<? extends T> target,
1539+
@Nullable Class<? extends T> fallback) {
15451540

1546-
if(conversionService.canConvert(value.getClass(), target) || fallback == null) {
1541+
if (conversionService.canConvert(value.getClass(), target) || fallback == null) {
15471542
return conversionService.convert(value, target);
15481543
}
15491544
return conversionService.convert(value, fallback);
@@ -1861,9 +1856,10 @@ protected static class ConversionContext {
18611856
private final ContainerValueConverter<DBRef> dbRefConverter;
18621857
private final ValueConverter<Object> elementConverter;
18631858

1864-
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path, ContainerValueConverter<Bson> documentConverter,
1865-
ContainerValueConverter<Collection<?>> collectionConverter, ContainerValueConverter<Bson> mapConverter,
1866-
ContainerValueConverter<DBRef> dbRefConverter, ValueConverter<Object> elementConverter) {
1859+
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path,
1860+
ContainerValueConverter<Bson> documentConverter, ContainerValueConverter<Collection<?>> collectionConverter,
1861+
ContainerValueConverter<Bson> mapConverter, ContainerValueConverter<DBRef> dbRefConverter,
1862+
ValueConverter<Object> elementConverter) {
18671863

18681864
this.conversions = customConversions;
18691865
this.path = path;
@@ -1935,8 +1931,8 @@ public ConversionContext withPath(ObjectPath currentPath) {
19351931

19361932
Assert.notNull(currentPath, "ObjectPath must not be null");
19371933

1938-
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter, dbRefConverter,
1939-
elementConverter);
1934+
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter,
1935+
dbRefConverter, elementConverter);
19401936
}
19411937

19421938
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)