DATACMNS-867 - Additional Java 8 language feature cleanup.
Make use of lambdas and method references though out the codebase. Remove no longer required generic type parameters. Additionally remove unused imports and replace single element list initialization with dedicated singletonList. Use Assertion overloads taking Supplier for dynamic assertion error messages.
This commit is contained in:
committed by
Oliver Gierke
parent
aa4c51e1ea
commit
be347eaaab
@@ -45,8 +45,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test
|
||||
public void twoParametersWithIdenticalSetupEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
|
||||
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
|
||||
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));
|
||||
|
||||
assertThat(left).isEqualTo(right);
|
||||
assertThat(left.hashCode()).isEqualTo(right.hashCode());
|
||||
@@ -55,8 +55,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test
|
||||
public void twoParametersWithIdenticalSetupAndNullNameEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<Object, P>(Optional.empty(), type, annotations, Optional.of(entity));
|
||||
Parameter<Object, P> right = new Parameter<Object, P>(Optional.empty(), type, annotations, Optional.of(entity));
|
||||
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));
|
||||
|
||||
assertThat(left).isEqualTo(right);
|
||||
assertThat(left.hashCode()).isEqualTo(right.hashCode());
|
||||
@@ -65,8 +65,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test
|
||||
public void twoParametersWithIdenticalAndNullEntitySetupEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.empty());
|
||||
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.empty());
|
||||
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());
|
||||
|
||||
assertThat(left).isEqualTo(right);
|
||||
assertThat(left.hashCode()).isEqualTo(right.hashCode());
|
||||
@@ -75,8 +75,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test
|
||||
public void twoParametersWithDifferentNameAreNotEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("first"), type, annotations, Optional.of(entity));
|
||||
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("second"), type, annotations,
|
||||
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));
|
||||
|
||||
assertThat(left).isNotEqualTo(right);
|
||||
@@ -85,8 +85,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test
|
||||
public void twoParametersWithDifferenTypeAreNotEqual() {
|
||||
|
||||
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
|
||||
Parameter<String, P> right = new Parameter<String, P>(Optional.of("name"), ClassTypeInformation.from(String.class),
|
||||
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));
|
||||
|
||||
assertThat(left).isNotEqualTo(right);
|
||||
|
||||
@@ -96,8 +96,8 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
|
||||
@Test // DATACMNS-134
|
||||
public void discoversInnerClassConstructorCorrectly() {
|
||||
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class));
|
||||
PreferredConstructorDiscoverer<Inner, P> discoverer = new PreferredConstructorDiscoverer<Inner, P>(entity);
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class));
|
||||
PreferredConstructorDiscoverer<Inner, P> discoverer = new PreferredConstructorDiscoverer<>(entity);
|
||||
|
||||
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SimpleTypeHolderUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullOriginal() {
|
||||
new SimpleTypeHolder(new HashSet<Class<?>>(), null);
|
||||
new SimpleTypeHolder(new HashSet<>(), null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-31
|
||||
@@ -59,7 +59,7 @@ public class SimpleTypeHolderUnitTests {
|
||||
@Test
|
||||
public void doesNotAddDefaultConvertersIfConfigured() {
|
||||
|
||||
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<Class<?>>(), false);
|
||||
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(), false);
|
||||
|
||||
assertThat(holder.isSimpleType(UUID.class)).isFalse();
|
||||
}
|
||||
|
||||
@@ -75,20 +75,17 @@ public class AbstractMappingContextIntegrationTests<T extends PersistentProperty
|
||||
|
||||
Thread a = new Thread(() -> context.getPersistentEntity(Person.class));
|
||||
|
||||
Thread b = new Thread(new Runnable() {
|
||||
Thread b = new Thread(() -> {
|
||||
|
||||
public void run() {
|
||||
PersistentEntity<Object, T> entity = context.getRequiredPersistentEntity(Person.class);
|
||||
|
||||
PersistentEntity<Object, T> entity = context.getRequiredPersistentEntity(Person.class);
|
||||
|
||||
entity.doWithProperties((PropertyHandler<T>) persistentProperty -> {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
entity.doWithProperties((PropertyHandler<T>) persistentProperty -> {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
a.start();
|
||||
|
||||
@@ -142,9 +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")).hasValueSatisfying(it -> assertThat(it.isIdProperty()).isTrue());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-345
|
||||
@@ -155,11 +153,7 @@ public class AbstractMappingContextUnitTests {
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
|
||||
.getRequiredPersistentEntity(Sample.class);
|
||||
|
||||
assertThat(entity.getPersistentProperty("persons")).hasValueSatisfying(it -> {
|
||||
assertThat(mappingContext.getPersistentEntity(it)).hasValueSatisfying(inner -> {
|
||||
assertThat(inner.getType()).isEqualTo(Person.class);
|
||||
});
|
||||
});
|
||||
assertThat(entity.getPersistentProperty("persons")).hasValueSatisfying(it -> assertThat(mappingContext.getPersistentEntity(it)).hasValueSatisfying(inner -> assertThat(inner.getType()).isEqualTo(Person.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-380
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package org.springframework.data.mapping.context;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,7 +46,7 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
oneLeg = new DefaultPersistentPropertyPath<>(Arrays.asList(first));
|
||||
oneLeg = new DefaultPersistentPropertyPath<>(Collections.singletonList(first));
|
||||
twoLegs = new DefaultPersistentPropertyPath<>(Arrays.asList(first, second));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<
|
||||
|
||||
PersistentPropertyPath<T> extension = twoLegs.getExtensionForBaseOf(oneLeg);
|
||||
|
||||
assertThat(extension).isEqualTo(new DefaultPersistentPropertyPath<>(Arrays.asList(second)));
|
||||
assertThat(extension).isEqualTo(new DefaultPersistentPropertyPath<>(Collections.singletonList(second)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,21 +41,21 @@ public class MappingContextEventUnitTests<E extends PersistentEntity<?, P>, P ex
|
||||
@Test
|
||||
public void returnsPersistentEntityHandedToTheEvent() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.getPersistentEntity()).isEqualTo(entity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesMappingContextAsEventSource() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.getSource()).isEqualTo(mappingContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsEmittingMappingContextCorrectly() {
|
||||
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
|
||||
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
|
||||
assertThat(event.wasEmittedBy(mappingContext)).isTrue();
|
||||
assertThat(event.wasEmittedBy(otherMappingContext)).isFalse();
|
||||
}
|
||||
|
||||
@@ -65,15 +65,13 @@ public class PersistentEntitiesUnitTests {
|
||||
context.setInitialEntitySet(Collections.singleton(Sample.class));
|
||||
context.initialize();
|
||||
|
||||
PersistentEntities entities = new PersistentEntities(Arrays.asList(context));
|
||||
PersistentEntities entities = new PersistentEntities(Collections.singletonList(context));
|
||||
|
||||
assertThat(entities.getPersistentEntity(Sample.class)).isPresent();
|
||||
assertThat(entities.getPersistentEntity(Object.class)).isNotPresent();
|
||||
assertThat(entities.getManagedTypes()).contains(ClassTypeInformation.from(Sample.class));
|
||||
|
||||
assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> {
|
||||
assertThat(entities).contains(it);
|
||||
});
|
||||
assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> assertThat(entities).contains(it));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class SampleMappingContext
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <S> BasicPersistentEntity<Object, SamplePersistentProperty> createPersistentEntity(
|
||||
TypeInformation<S> typeInformation) {
|
||||
return new BasicPersistentEntity<Object, SamplePersistentProperty>((TypeInformation<Object>) typeInformation);
|
||||
return new BasicPersistentEntity<>((TypeInformation<Object>) typeInformation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,9 +92,7 @@ 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)).hasValueSatisfying(annotation -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,33 +110,25 @@ 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")).hasValueSatisfying(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")).hasValueSatisfying(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")).hasValueSatisfying(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")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-243
|
||||
@@ -149,9 +139,7 @@ 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")).hasValueSatisfying(it -> assertThat(it.isWritable()).isTrue());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-534
|
||||
@@ -162,17 +150,13 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
@Test // DATACMNS-534
|
||||
public void treatsReadOnlyAsNonWritable() {
|
||||
|
||||
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty")).hasValueSatisfying(it -> {
|
||||
assertThat(it.isWritable()).isFalse();
|
||||
});
|
||||
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty")).hasValueSatisfying(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")).hasValueSatisfying(it -> assertThat(it.isWritable()).isFalse());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-556
|
||||
@@ -208,31 +192,23 @@ 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)).hasValueSatisfying(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")).hasValueSatisfying(property -> assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(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(annotation.name()).isEqualTo("my-value");
|
||||
assertThat(annotation.value()).isEqualTo("my-value");
|
||||
});
|
||||
});
|
||||
assertThat(entity.getPersistentProperty("setter")).hasValueSatisfying(property -> assertThat(property.findAnnotation(RevisedAnnnotationWithAliasFor.class)).hasValueSatisfying(annotation -> {
|
||||
assertThat(annotation.name()).isEqualTo("my-value");
|
||||
assertThat(annotation.value()).isEqualTo("my-value");
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -159,15 +159,11 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
|
||||
Optional<SamplePersistentProperty> property = entity.getPersistentProperty(LastModifiedBy.class);
|
||||
|
||||
assertThat(property).hasValueSatisfying(it -> {
|
||||
assertThat(it.getName()).isEqualTo("field");
|
||||
});
|
||||
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("field"));
|
||||
|
||||
property = entity.getPersistentProperty(CreatedBy.class);
|
||||
|
||||
assertThat(property).hasValueSatisfying(it -> {
|
||||
assertThat(it.getName()).isEqualTo("property");
|
||||
});
|
||||
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("property"));
|
||||
|
||||
assertThat(entity.getPersistentProperty(CreatedDate.class)).isNotPresent();
|
||||
}
|
||||
@@ -253,13 +249,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
BasicPersistentEntity<Entity, T> entity = createEntity(Entity.class);
|
||||
entity.addAssociation(null);
|
||||
|
||||
entity.doWithAssociations(new SimpleAssociationHandler() {
|
||||
|
||||
@Override
|
||||
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
|
||||
Assert.fail("Expected the method to never be called!");
|
||||
}
|
||||
});
|
||||
entity.doWithAssociations((SimpleAssociationHandler) association -> Assert.fail("Expected the method to never be called!"));
|
||||
}
|
||||
|
||||
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type) {
|
||||
@@ -267,7 +257,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type, Comparator<T> comparator) {
|
||||
return new BasicPersistentEntity<S, T>(ClassTypeInformation.from(type), Optional.ofNullable(comparator));
|
||||
return new BasicPersistentEntity<>(ClassTypeInformation.from(type), Optional.ofNullable(comparator));
|
||||
}
|
||||
|
||||
@TypeAlias("foo")
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
|
||||
|
||||
private static List<Object[]> parameters(List<Class<?>> types, String propertyName, Object value) throws Exception {
|
||||
|
||||
List<Object[]> parameters = new ArrayList<Object[]>();
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
|
||||
for (Class<?> type : types) {
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests {
|
||||
private EntityInformation<Object, Serializable> getEntityInformation(Class<?> type) {
|
||||
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(type);
|
||||
return new PersistentEntityInformation<Object, Serializable>(entity);
|
||||
return new PersistentEntityInformation<>(entity);
|
||||
}
|
||||
|
||||
interface Algorithm {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
@Parameters(name = "{3}")
|
||||
public static List<Object[]> parameters() {
|
||||
|
||||
List<Object[]> parameters = new ArrayList<Object[]>();
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
List<String> propertyNames = Arrays.asList("privateField", "packageDefaultField", "protectedField", "publicField",
|
||||
"privateProperty", "packageDefaultProperty", "protectedProperty", "publicProperty", "syntheticProperty");
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
|
||||
private static List<Object[]> parameters(Object bean, List<String> propertyNames, Class<?> expectedConstructorType) {
|
||||
|
||||
List<Object[]> parameters = new ArrayList<Object[]>();
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
|
||||
for (String propertyName : propertyNames) {
|
||||
parameters.add(new Object[] { bean, propertyName, expectedConstructorType,
|
||||
@@ -128,21 +128,15 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
@Test // DATACMNS-809
|
||||
public void getPropertyShouldFailOnUnhandledProperty() {
|
||||
|
||||
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> {
|
||||
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)//
|
||||
.isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property));
|
||||
});
|
||||
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(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)//
|
||||
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty()));
|
||||
});
|
||||
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
|
||||
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty())));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-809
|
||||
|
||||
@@ -59,9 +59,7 @@ public class ConvertingPropertyAccessorUnitTests {
|
||||
Entity entity = new Entity();
|
||||
entity.id = 1L;
|
||||
|
||||
assertThat(getIdProperty()).hasValueSatisfying(it -> {
|
||||
assertThat(getAccessor(entity, CONVERSION_SERVICE).getProperty(it, String.class)).hasValue("1");
|
||||
});
|
||||
assertThat(getIdProperty()).hasValueSatisfying(it -> assertThat(getAccessor(entity, CONVERSION_SERVICE).getProperty(it, String.class)).hasValue("1"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-596
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -77,13 +76,10 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
|
||||
ParameterValueProvider<P> provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider,
|
||||
Optional.of(property));
|
||||
|
||||
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> {
|
||||
|
||||
assertThatExceptionOfType(MappingException.class)//
|
||||
.isThrownBy(() -> provider.getParameterValue(constructor.getParameters().iterator().next()))//
|
||||
.withMessageContaining("bar")//
|
||||
.withMessageContaining(Entity.class.getName());
|
||||
});
|
||||
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> assertThatExceptionOfType(MappingException.class)//
|
||||
.isThrownBy(() -> provider.getParameterValue(constructor.getParameters().iterator().next()))//
|
||||
.withMessageContaining("bar")//
|
||||
.withMessageContaining(Entity.class.getName()));
|
||||
}
|
||||
|
||||
static class Outer {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
Reference in New Issue
Block a user