DATACMNS-1101 - Remove Optional from mapping/convert use except for caching of absence and computations that are used to populate caches.

This commit is contained in:
Mark Paluch
2017-06-27 15:46:05 +02:00
committed by Oliver Gierke
parent 74fbe13f54
commit 6c65c02e78
56 changed files with 848 additions and 747 deletions

View File

@@ -24,7 +24,7 @@ import org.springframework.data.mapping.context.SamplePersistentProperty;
/**
* Integration tests for Mapping metadata.
*
*
* @author Jon Brisbin
* @author Oliver Gierke
*/
@@ -42,7 +42,7 @@ public class MappingMetadataTests {
PersistentEntity<?, SamplePersistentProperty> person = ctx.getRequiredPersistentEntity(PersonWithId.class);
assertThat(person.getIdProperty()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(String.class));
assertThat(person.getIdProperty()).satisfies(it -> assertThat(it.getType()).isEqualTo(String.class));
}
@Test

View File

@@ -18,7 +18,6 @@ package org.springframework.data.mapping;
import static org.assertj.core.api.Assertions.*;
import java.lang.annotation.Annotation;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,7 +29,7 @@ import org.springframework.data.util.TypeInformation;
/**
* Unit tests for {@link Parameter}.
*
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
@@ -45,8 +44,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalSetupEqual() {
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<Object, P> left = new Parameter<>("name", type, annotations, entity);
Parameter<Object, P> right = new Parameter<>("name", type, annotations, entity);
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -55,8 +54,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalSetupAndNullNameEqual() {
Parameter<Object, P> left = new Parameter<>(Optional.empty(), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.empty(), type, annotations, Optional.of(entity));
Parameter<Object, P> left = new Parameter<>(null, type, annotations, entity);
Parameter<Object, P> right = new Parameter<>(null, type, annotations, entity);
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -65,8 +64,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalAndNullEntitySetupEqual() {
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.empty());
Parameter<Object, P> right = new Parameter<>(Optional.of("name"), type, annotations, Optional.empty());
Parameter<Object, P> left = new Parameter<>("name", type, annotations, null);
Parameter<Object, P> right = new Parameter<>("name", type, annotations, null);
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -75,9 +74,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithDifferentNameAreNotEqual() {
Parameter<Object, P> left = new Parameter<>(Optional.of("first"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.of("second"), type, annotations,
Optional.of(entity));
Parameter<Object, P> left = new Parameter<>("first", type, annotations, entity);
Parameter<Object, P> right = new Parameter<>("second", type, annotations, entity);
assertThat(left).isNotEqualTo(right);
}
@@ -85,9 +83,9 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithDifferenTypeAreNotEqual() {
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<String, P> right = new Parameter<>(Optional.of("name"), ClassTypeInformation.from(String.class),
annotations, Optional.of(stringEntity));
Parameter<Object, P> left = new Parameter<>("name", type, annotations, entity);
Parameter<String, P> right = new Parameter<>("name", ClassTypeInformation.from(String.class), annotations,
stringEntity);
assertThat(left).isNotEqualTo(right);
}

View File

@@ -29,9 +29,10 @@ import org.springframework.data.util.ClassTypeInformation;
/**
* Unit tests for {@link PreferredConstructorDiscoverer}.
*
*
* @author Oliver Gierke
* @author Roman Rodov
* @author Mark Paluch
*/
public class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
@@ -41,7 +42,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PreferredConstructorDiscoverer<EntityWithoutConstructor, P> discoverer = new PreferredConstructorDiscoverer<>(
EntityWithoutConstructor.class);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
assertThat(discoverer.getConstructor()).satisfies(constructor -> {
assertThat(constructor).isNotNull();
assertThat(constructor.isNoArgConstructor()).isTrue();
@@ -55,7 +56,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PreferredConstructorDiscoverer<ClassWithEmptyConstructor, P> discoverer = new PreferredConstructorDiscoverer<>(
ClassWithEmptyConstructor.class);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
assertThat(discoverer.getConstructor()).satisfies(constructor -> {
assertThat(constructor).isNotNull();
assertThat(constructor.isNoArgConstructor()).isTrue();
@@ -69,7 +70,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PreferredConstructorDiscoverer<ClassWithMultipleConstructorsWithoutEmptyOne, P> discoverer = new PreferredConstructorDiscoverer<>(
ClassWithMultipleConstructorsWithoutEmptyOne.class);
assertThat(discoverer.getConstructor()).isNotPresent();
assertThat(discoverer.getConstructor()).isNull();
}
@Test
@@ -78,7 +79,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PreferredConstructorDiscoverer<ClassWithMultipleConstructorsAndAnnotation, P> discoverer = new PreferredConstructorDiscoverer<>(
ClassWithMultipleConstructorsAndAnnotation.class);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
assertThat(discoverer.getConstructor()).satisfies(constructor -> {
assertThat(constructor).isNotNull();
assertThat(constructor.isNoArgConstructor()).isFalse();
@@ -100,7 +101,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class));
PreferredConstructorDiscoverer<Inner, P> discoverer = new PreferredConstructorDiscoverer<>(entity);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
assertThat(discoverer.getConstructor()).satisfies(constructor -> {
Parameter<?, P> parameter = constructor.getParameters().iterator().next();
assertThat(constructor.isEnclosingClassParameter(parameter)).isTrue();
@@ -113,7 +114,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(SyntheticConstructor.class));
PreferredConstructorDiscoverer<SyntheticConstructor, P> discoverer = new PreferredConstructorDiscoverer<>(entity);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
assertThat(discoverer.getConstructor()).satisfies(constructor -> {
PersistenceConstructor annotation = constructor.getConstructor().getAnnotation(PersistenceConstructor.class);
assertThat(annotation).isNotNull();

View File

@@ -33,7 +33,7 @@ public class TargetAwareIdentifierAccessorUnitTests {
Object sample = new Object();
IdentifierAccessor accessor = new TargetAwareIdentifierAccessor(() -> sample) {
IdentifierAccessor accessor = new TargetAwareIdentifierAccessor(sample) {
@Override
public Object getIdentifier() {

View File

@@ -42,7 +42,7 @@ import org.springframework.util.StringUtils;
/**
* Unit test for {@link AbstractMappingContext}.
*
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
@@ -111,7 +111,7 @@ public class AbstractMappingContextUnitTests {
public void returnsNullPersistentEntityForSimpleTypes() {
SampleMappingContext context = new SampleMappingContext();
assertThat(context.getPersistentEntity(String.class)).isEmpty();
assertThat(context.getPersistentEntity(String.class)).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-214
@@ -132,7 +132,7 @@ public class AbstractMappingContextUnitTests {
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
.getRequiredPersistentEntity(Sample.class);
assertThat(entity.getPersistentProperty("metaClass")).isNotPresent();
assertThat(entity.getPersistentProperty("metaClass")).isNull();
}
@Test // DATACMNS-332
@@ -142,7 +142,7 @@ public class AbstractMappingContextUnitTests {
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
.getRequiredPersistentEntity(Extension.class);
assertThat(entity.getPersistentProperty("foo")).hasValueSatisfying(it -> assertThat(it.isIdProperty()).isTrue());
assertThat(entity.getPersistentProperty("foo")).satisfies(it -> assertThat(it.isIdProperty()).isTrue());
}
@Test // DATACMNS-345
@@ -154,8 +154,8 @@ public class AbstractMappingContextUnitTests {
.getRequiredPersistentEntity(Sample.class);
assertThat(entity.getPersistentProperty("persons"))
.hasValueSatisfying(it -> assertThat(mappingContext.getPersistentEntity(it))
.hasValueSatisfying(inner -> assertThat(inner.getType()).isEqualTo(Person.class)));
.satisfies(it -> assertThat(mappingContext.getPersistentEntity(it))
.satisfies(inner -> assertThat(inner.getType()).isEqualTo(Person.class)));
}
@Test // DATACMNS-380
@@ -193,7 +193,7 @@ public class AbstractMappingContextUnitTests {
public void shouldReturnNullForSimpleTypesIfInStrictIsEnabled() {
context.setStrict(true);
assertThat(context.getPersistentEntity(Integer.class)).isEmpty();
assertThat(context.getPersistentEntity(Integer.class)).isNull();
}
@Test // DATACMNS-462

View File

@@ -41,7 +41,7 @@ import org.springframework.util.ReflectionUtils;
/**
* Unit tests for {@link AbstractPersistentProperty}.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@@ -99,8 +99,8 @@ public class AbstractPersistentPropertyUnitTests {
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "id");
assertThat(property.getGetter()).isPresent();
assertThat(property.getSetter()).isPresent();
assertThat(property.getGetter()).isNotNull();
assertThat(property.getSetter()).isNotNull();
}
@Test // DATACMNS-206
@@ -108,8 +108,8 @@ public class AbstractPersistentPropertyUnitTests {
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "anotherId");
assertThat(property.getGetter()).isNotPresent();
assertThat(property.getSetter()).isNotPresent();
assertThat(property.getGetter()).isNull();
assertThat(property.getSetter()).isNull();
}
@Test // DATACMNS-206
@@ -117,8 +117,8 @@ public class AbstractPersistentPropertyUnitTests {
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "yetAnotherId");
assertThat(property.getGetter()).isPresent();
assertThat(property.getSetter()).isNotPresent();
assertThat(property.getGetter()).isNotNull();
assertThat(property.getSetter()).isNull();
}
@Test // DATACMNS-206
@@ -126,8 +126,8 @@ public class AbstractPersistentPropertyUnitTests {
SamplePersistentProperty property = getProperty(AccessorTestClass.class, "yetYetAnotherId");
assertThat(property.getGetter()).isNotPresent();
assertThat(property.getSetter()).isPresent();
assertThat(property.getGetter()).isNull();
assertThat(property.getSetter()).isNotNull();
}
@Test // DATACMNS-206
@@ -137,8 +137,8 @@ public class AbstractPersistentPropertyUnitTests {
PersistentProperty<SamplePersistentProperty> property = new SamplePersistentProperty(Property.of(field),
getEntity(AccessorTestClass.class), typeHolder);
assertThat(property.getGetter()).isNotPresent();
assertThat(property.getSetter()).isNotPresent();
assertThat(property.getGetter()).isNull();
assertThat(property.getSetter()).isNull();
}
@Test // DATACMNS-337
@@ -325,8 +325,8 @@ public class AbstractPersistentPropertyUnitTests {
}
@Override
public <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType) {
return Optional.empty();
public <A extends Annotation> A findAnnotation(Class<A> annotationType) {
return null;
}
@Override
@@ -335,8 +335,8 @@ public class AbstractPersistentPropertyUnitTests {
}
@Override
public <A extends Annotation> Optional<A> findPropertyOrOwnerAnnotation(Class<A> annotationType) {
return Optional.empty();
public <A extends Annotation> A findPropertyOrOwnerAnnotation(Class<A> annotationType) {
return null;
}
}

View File

@@ -29,7 +29,6 @@ import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.annotation.AccessType;
@@ -84,7 +83,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-282
public void populatesAnnotationCacheWithDirectAnnotationsOnCreation() {
assertThat(entity.getPersistentProperty("meta")).hasValueSatisfying(property -> {
assertThat(entity.getPersistentProperty("meta")).satisfies(property -> {
// Assert direct annotations are cached on construction
Map<Class<? extends Annotation>, Annotation> cache = getAnnotationCache(property);
@@ -92,7 +91,8 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
assertThat(cache.containsKey(MyAnnotation.class)).isFalse();
// Assert meta annotation is found and cached
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
assertThat(property.findAnnotation(MyAnnotation.class))
.satisfies(annotation -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
});
}
@@ -110,25 +110,28 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-243
public void defaultsToFieldAccess() {
assertThat(getProperty(FieldAccess.class, "name")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
assertThat(getProperty(FieldAccess.class, "name")).satisfies(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
public void usesAccessTypeDeclaredOnTypeAsDefault() {
assertThat(getProperty(PropertyAccess.class, "firstname")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isTrue());
assertThat(getProperty(PropertyAccess.class, "firstname"))
.satisfies(it -> assertThat(it.usePropertyAccess()).isTrue());
}
@Test // DATACMNS-243
public void propertyAnnotationOverridesTypeConfiguration() {
assertThat(getProperty(PropertyAccess.class, "lastname")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
assertThat(getProperty(PropertyAccess.class, "lastname"))
.satisfies(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
public void fieldAnnotationOverridesTypeConfiguration() {
assertThat(getProperty(PropertyAccess.class, "emailAddress")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
assertThat(getProperty(PropertyAccess.class, "emailAddress"))
.satisfies(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
@@ -139,24 +142,27 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-534
public void treatsNoAnnotationCorrectly() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "noAnnotations")).hasValueSatisfying(it -> assertThat(it.isWritable()).isTrue());
assertThat(getProperty(ClassWithReadOnlyProperties.class, "noAnnotations"))
.satisfies(it -> assertThat(it.isWritable()).isTrue());
}
@Test // DATACMNS-534
public void treatsTransientAsNotExisting() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "transientProperty")).isEmpty();
assertThat(getProperty(ClassWithReadOnlyProperties.class, "transientProperty")).isNull();
}
@Test // DATACMNS-534
public void treatsReadOnlyAsNonWritable() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty")).hasValueSatisfying(it -> assertThat(it.isWritable()).isFalse());
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty"))
.satisfies(it -> assertThat(it.isWritable()).isFalse());
}
@Test // DATACMNS-534
public void considersPropertyWithReadOnlyMetaAnnotationReadOnly() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "customReadOnlyProperty")).hasValueSatisfying(it -> assertThat(it.isWritable()).isFalse());
assertThat(getProperty(ClassWithReadOnlyProperties.class, "customReadOnlyProperty"))
.satisfies(it -> assertThat(it.isWritable()).isFalse());
}
@Test // DATACMNS-556
@@ -168,11 +174,11 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@SuppressWarnings("unchecked")
public void cachesNonPresenceOfAnnotationOnField() {
Optional<SamplePersistentProperty> property = getProperty(Sample.class, "getterWithoutField");
SamplePersistentProperty property = getProperty(Sample.class, "getterWithoutField");
assertThat(property).hasValueSatisfying(it -> {
assertThat(property).satisfies(it -> {
assertThat(it.findAnnotation(MyAnnotation.class)).isNotPresent();
assertThat(it.findAnnotation(MyAnnotation.class)).isNull();
Map<Class<?>, ?> field = (Map<Class<?>, ?>) ReflectionTestUtils.getField(it, "annotationCache");
@@ -184,7 +190,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-825
public void composedAnnotationWithAliasForGetCachedCorrectly() {
assertThat(entity.getPersistentProperty("metaAliased")).hasValueSatisfying(property -> {
assertThat(entity.getPersistentProperty("metaAliased")).satisfies(property -> {
// Assert direct annotations are cached on construction
Map<Class<? extends Annotation>, Annotation> cache = getAnnotationCache(property);
@@ -192,20 +198,24 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
assertThat(cache.containsKey(MyAnnotation.class)).isFalse();
// Assert meta annotation is found and cached
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(it -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
assertThat(property.findAnnotation(MyAnnotation.class))
.satisfies(it -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
});
}
@Test // DATACMNS-825
public void composedAnnotationWithAliasShouldHaveSynthesizedAttributeValues() {
assertThat(entity.getPersistentProperty("metaAliased")).hasValueSatisfying(property -> assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> assertThat(AnnotationUtils.getValue(annotation)).isEqualTo("spring")));
assertThat(entity.getPersistentProperty("metaAliased"))
.satisfies(property -> assertThat(property.findAnnotation(MyAnnotation.class))
.satisfies(annotation -> assertThat(AnnotationUtils.getValue(annotation)).isEqualTo("spring")));
}
@Test // DATACMNS-867
public void revisedAnnotationWithAliasShouldHaveSynthesizedAttributeValues() {
assertThat(entity.getPersistentProperty("setter")).hasValueSatisfying(property -> assertThat(property.findAnnotation(RevisedAnnnotationWithAliasFor.class)).hasValueSatisfying(annotation -> {
assertThat(entity.getPersistentProperty("setter")).satisfies(
property -> assertThat(property.findAnnotation(RevisedAnnnotationWithAliasFor.class)).satisfies(annotation -> {
assertThat(annotation.name()).isEqualTo("my-value");
assertThat(annotation.value()).isEqualTo("my-value");
}));
@@ -217,16 +227,16 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
}
private <A extends Annotation> A assertAnnotationPresent(Class<A> annotationType,
Optional<? extends AnnotationBasedPersistentProperty<?>> property) {
AnnotationBasedPersistentProperty<?> property) {
Optional<A> annotation = property.flatMap(it -> it.findAnnotation(annotationType));
A annotation = property.findAnnotation(annotationType);
assertThat(annotation).isPresent();
assertThat(annotation).isNotNull();
return annotation.get();
return annotation;
}
private Optional<SamplePersistentProperty> getProperty(Class<?> type, String name) {
private SamplePersistentProperty getProperty(Class<?> type, String name) {
return context.getRequiredPersistentEntity(type).getPersistentProperty(name);
}

View File

@@ -24,7 +24,6 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.hamcrest.CoreMatchers;
import org.junit.Rule;
@@ -119,20 +118,20 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
assertThat(properties).hasSize(3);
Iterator<T> iterator = properties.iterator();
assertThat(entity.getPersistentProperty("firstName")).hasValue(iterator.next());
assertThat(entity.getPersistentProperty("lastName")).hasValue(iterator.next());
assertThat(entity.getPersistentProperty("ssn")).hasValue(iterator.next());
assertThat(entity.getPersistentProperty("firstName")).isEqualTo(iterator.next());
assertThat(entity.getPersistentProperty("lastName")).isEqualTo(iterator.next());
assertThat(entity.getPersistentProperty("ssn")).isEqualTo(iterator.next());
}
@Test // DATACMNS-186
public void addingAndIdPropertySetsIdPropertyInternally() {
MutablePersistentEntity<Person, T> entity = createEntity(Person.class);
assertThat(entity.getIdProperty()).isNotPresent();
assertThat(entity.getIdProperty()).isNull();
when(property.isIdProperty()).thenReturn(true);
entity.addPersistentProperty(property);
assertThat(entity.getIdProperty()).hasValue(property);
assertThat(entity.getIdProperty()).isEqualTo(property);
}
@Test // DATACMNS-186
@@ -154,15 +153,15 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
SampleMappingContext context = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
Optional<SamplePersistentProperty> property = entity.getPersistentProperty(LastModifiedBy.class);
SamplePersistentProperty property = entity.getPersistentProperty(LastModifiedBy.class);
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("field"));
assertThat(property.getName()).isEqualTo("field");
property = entity.getPersistentProperty(CreatedBy.class);
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("property"));
assertThat(property.getName()).isEqualTo("property");
assertThat(entity.getPersistentProperty(CreatedDate.class)).isNotPresent();
assertThat(entity.getPersistentProperty(CreatedDate.class)).isNull();
}
@Test // DATACMNS-596
@@ -253,7 +252,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
}
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type, Comparator<T> comparator) {
return new BasicPersistentEntity<>(ClassTypeInformation.from(type), Optional.ofNullable(comparator));
return new BasicPersistentEntity<>(ClassTypeInformation.from(type), comparator);
}
@TypeAlias("foo")

View File

@@ -23,7 +23,6 @@ import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -124,7 +123,7 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
@Test // DATACMNS-809
public void shouldSetAndGetProperty() throws Exception {
assertThat(getProperty(bean, propertyName)).hasValueSatisfying(property -> {
assertThat(getProperty(bean, propertyName)).satisfies(property -> {
PersistentPropertyAccessor persistentPropertyAccessor = getPersistentPropertyAccessor(bean);
@@ -147,7 +146,7 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
return factory.getPropertyAccessor(mappingContext.getRequiredPersistentEntity(bean.getClass()), bean);
}
private Optional<? extends PersistentProperty<?>> getProperty(Object bean, String name) {
private PersistentProperty<?> getProperty(Object bean, String name) {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getRequiredPersistentEntity(bean.getClass());

View File

@@ -97,7 +97,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
@Test // DATACMNS-809
public void shouldSetAndGetProperty() throws Exception {
assertThat(getProperty(bean, propertyName)).hasValueSatisfying(property -> {
assertThat(getProperty(bean, propertyName)).satisfies(property -> {
PersistentPropertyAccessor persistentPropertyAccessor = getPersistentPropertyAccessor(bean);
@@ -126,14 +126,16 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
@Test // DATACMNS-809
public void getPropertyShouldFailOnUnhandledProperty() {
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
assertThat(getProperty(new Dummy(), "dummy"))
.satisfies(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property)));
}
@Test // DATACMNS-809
public void setPropertyShouldFailOnUnhandledProperty() {
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
assertThat(getProperty(new Dummy(), "dummy"))
.satisfies(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty())));
}
@@ -151,7 +153,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
return factory.getPropertyAccessor(mappingContext.getRequiredPersistentEntity(bean.getClass()), bean);
}
private Optional<? extends PersistentProperty<?>> getProperty(Object bean, String name) {
private PersistentProperty<?> getProperty(Object bean, String name) {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getRequiredPersistentEntity(bean.getClass());

View File

@@ -18,8 +18,6 @@ package org.springframework.data.mapping.model;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Optional;
import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.mapping.PersistentPropertyAccessor;
@@ -60,7 +58,7 @@ public class ConvertingPropertyAccessorUnitTests {
Entity entity = new Entity();
entity.id = 1L;
assertThat(getIdProperty()).hasValueSatisfying(
assertThat(getIdProperty()).satisfies(
it -> assertThat(getAccessor(entity, CONVERSION_SERVICE).getProperty(it, String.class)).isEqualTo("1"));
}
@@ -69,7 +67,7 @@ public class ConvertingPropertyAccessorUnitTests {
ConversionService conversionService = mock(ConversionService.class);
assertThat(getIdProperty()).hasValueSatisfying(it -> {
assertThat(getIdProperty()).satisfies(it -> {
assertThat(getAccessor(new Entity(), conversionService).getProperty(it, Number.class)).isNull();
verify(conversionService, times(0)).convert(1L, Number.class);
});
@@ -83,7 +81,7 @@ public class ConvertingPropertyAccessorUnitTests {
ConversionService conversionService = mock(ConversionService.class);
assertThat(getIdProperty()).hasValueSatisfying(it -> {
assertThat(getIdProperty()).satisfies(it -> {
assertThat(getAccessor(entity, conversionService).getProperty(it, Number.class)).isEqualTo(1L);
verify(conversionService, times(0)).convert(1L, Number.class);
});
@@ -94,7 +92,7 @@ public class ConvertingPropertyAccessorUnitTests {
Entity entity = new Entity();
assertThat(getIdProperty()).hasValueSatisfying(property -> {
assertThat(getIdProperty()).satisfies(property -> {
getAccessor(entity, CONVERSION_SERVICE).setProperty(property, "1");
assertThat(entity.id).isEqualTo(1L);
});
@@ -103,7 +101,7 @@ public class ConvertingPropertyAccessorUnitTests {
@Test // DATACMNS-596
public void doesNotInvokeConversionIfTypeAlreadyMatchesOnSet() {
assertThat(getIdProperty()).hasValueSatisfying(it -> {
assertThat(getIdProperty()).satisfies(it -> {
getAccessor(new Entity(), mock(ConversionService.class)).setProperty(it, 1L);
verify(mock(ConversionService.class), times(0)).convert(1L, Long.class);
});
@@ -115,7 +113,7 @@ public class ConvertingPropertyAccessorUnitTests {
return new ConvertingPropertyAccessor(wrapper, conversionService);
}
private static Optional<SamplePersistentProperty> getIdProperty() {
private static SamplePersistentProperty getIdProperty() {
SampleMappingContext mappingContext = new SampleMappingContext();
BasicPersistentEntity<Object, SamplePersistentProperty> entity = mappingContext

View File

@@ -50,12 +50,12 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class)) {
@Override
public Optional<P> getPersistentProperty(String name) {
return Optional.ofNullable(property);
public P getPersistentProperty(String name) {
return property;
}
};
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> {
assertThat(entity.getPersistenceConstructor()).satisfies(constructor -> {
Iterator<Parameter<Object, P>> iterator = constructor.getParameters().iterator();
ParameterValueProvider<P> provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider,
@@ -75,7 +75,7 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
Optional.of(property));
assertThat(entity.getPersistenceConstructor())
.hasValueSatisfying(constructor -> assertThatExceptionOfType(MappingException.class)//
.satisfies(constructor -> assertThatExceptionOfType(MappingException.class)//
.isThrownBy(() -> provider.getParameterValue(constructor.getParameters().iterator().next()))//
.withMessageContaining("bar")//
.withMessageContaining(Entity.class.getName()));

View File

@@ -18,8 +18,6 @@ package org.springframework.data.mapping.model;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,7 +69,7 @@ public class SpelExpressionParameterProviderUnitTests {
@Test
public void evaluatesSpELExpression() {
when(parameter.getSpelExpression()).thenReturn(Optional.of("expression"));
when(parameter.getSpelExpression()).thenReturn("expression");
provider.getParameterValue(parameter);
verify(delegate, times(0)).getParameterValue(parameter);
@@ -81,7 +79,7 @@ public class SpelExpressionParameterProviderUnitTests {
@Test
public void handsSpELValueToConversionService() {
doReturn(Optional.of("source")).when(parameter).getSpelExpression();
doReturn("source").when(parameter).getSpelExpression();
doReturn("value").when(evaluator).evaluate(any());
provider.getParameterValue(parameter);
@@ -93,7 +91,7 @@ public class SpelExpressionParameterProviderUnitTests {
@Test
public void doesNotConvertNullValue() {
doReturn(Optional.of("source")).when(parameter).getSpelExpression();
doReturn("source").when(parameter).getSpelExpression();
doReturn(null).when(evaluator).evaluate(any());
provider.getParameterValue(parameter);
@@ -115,7 +113,7 @@ public class SpelExpressionParameterProviderUnitTests {
}
};
doReturn(Optional.of("source")).when(parameter).getSpelExpression();
doReturn("source").when(parameter).getSpelExpression();
doReturn("value").when(evaluator).evaluate(any());
assertThat(provider.getParameterValue(parameter)).isEqualTo("FOO");