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:
committed by
Oliver Gierke
parent
74fbe13f54
commit
6c65c02e78
@@ -22,10 +22,8 @@ import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -58,11 +56,6 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
@Mock PreferredConstructor<?, P> constructor;
|
||||
@Mock Parameter<?, P> parameter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
doReturn(Optional.empty()).when(entity).getPersistenceConstructor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantiatesSimpleObjectCorrectly() {
|
||||
|
||||
@@ -82,7 +75,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
@Test
|
||||
public void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
|
||||
Optional<? extends PreferredConstructor<Foo, P>> constructor = new PreferredConstructorDiscoverer<Foo, P>(Foo.class)
|
||||
PreferredConstructor<Foo, P> constructor = new PreferredConstructorDiscoverer<Foo, P>(Foo.class)
|
||||
.getConstructor();
|
||||
|
||||
doReturn(Foo.class).when(entity).getType();
|
||||
@@ -90,14 +83,14 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
|
||||
assertThat(instance.createInstance(entity, provider)).isInstanceOf(Foo.class);
|
||||
|
||||
assertThat(constructor).hasValueSatisfying(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
|
||||
assertThat(constructor)
|
||||
.satisfies(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
|
||||
}
|
||||
|
||||
@Test(expected = MappingInstantiationException.class) // DATACMNS-300, DATACMNS-578
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void throwsExceptionOnBeanInstantiationException() {
|
||||
|
||||
doReturn(Optional.empty()).when(entity).getPersistenceConstructor();
|
||||
doReturn(PersistentEntity.class).when(entity).getType();
|
||||
|
||||
this.instance.createInstance(entity, provider);
|
||||
@@ -107,7 +100,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
|
||||
public void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
|
||||
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> {
|
||||
assertThat(entity.getPersistenceConstructor()).satisfies(constructor -> {
|
||||
|
||||
Parameter<Object, P> parameter = constructor.getParameters().iterator().next();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,9 +30,10 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConfigurableTypeMapper}.
|
||||
*
|
||||
* Unit tests for {@link ConfigurableTypeInformationMapper}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProperty<T>> {
|
||||
@@ -69,7 +70,7 @@ public class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProp
|
||||
@Test
|
||||
public void readsTypeForMapKey() {
|
||||
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("1"))).hasValue(ClassTypeInformation.from(String.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("unmapped"))).isEmpty();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(ClassTypeInformation.from(String.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("unmapped"))).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -33,7 +32,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultTypeMapper}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -55,14 +54,14 @@ public class DefaultTypeMapperUnitTests {
|
||||
this.source = Collections.singletonMap("key", ALIAS.toString());
|
||||
|
||||
doReturn(ALIAS).when(accessor).readAliasFrom(source);
|
||||
doReturn(Optional.of(STRING_TYPE_INFO)).when(mapper).resolveTypeFrom(ALIAS);
|
||||
doReturn(STRING_TYPE_INFO).when(mapper).resolveTypeFrom(ALIAS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachesResolvedTypeInformation() {
|
||||
|
||||
Optional<TypeInformation<?>> information = typeMapper.readType(source);
|
||||
assertThat(information).hasValue(STRING_TYPE_INFO);
|
||||
TypeInformation<?> information = typeMapper.readType(source);
|
||||
assertThat(information).isEqualTo(STRING_TYPE_INFO);
|
||||
verify(mapper, times(1)).resolveTypeFrom(ALIAS);
|
||||
|
||||
typeMapper.readType(source);
|
||||
@@ -87,7 +86,7 @@ public class DefaultTypeMapperUnitTests {
|
||||
TypeInformation<?> barType = ClassTypeInformation.from(Bar.class);
|
||||
|
||||
doReturn(Alias.of(barType)).when(accessor).readAliasFrom(source);
|
||||
doReturn(Optional.of(barType)).when(mapper).resolveTypeFrom(Alias.of(barType));
|
||||
doReturn(barType).when(mapper).resolveTypeFrom(Alias.of(barType));
|
||||
|
||||
TypeInformation<?> result = typeMapper.readType(source, propertyType);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MappingContextTypeInformationMapper}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class MappingContextTypeInformationMapperUnitTests {
|
||||
@@ -89,12 +89,12 @@ public class MappingContextTypeInformationMapperUnitTests {
|
||||
mappingContext.initialize();
|
||||
|
||||
mapper = new MappingContextTypeInformationMapper(mappingContext);
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEmpty();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isNull();
|
||||
|
||||
PersistentEntity<?, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||
|
||||
assertThat(entity).isNotNull();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).hasValue(from(Entity.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(from(Entity.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-485
|
||||
|
||||
@@ -23,9 +23,7 @@ import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -56,11 +54,6 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
@Mock PreferredConstructor<?, P> constructor;
|
||||
@Mock Parameter<?, P> parameter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
doReturn(Optional.empty()).when(entity).getPersistenceConstructor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantiatesSimpleObjectCorrectly() {
|
||||
|
||||
@@ -78,22 +71,21 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
@Test
|
||||
public void instantiatesTypeWithPreferredConstructorUsingParameterValueProvider() {
|
||||
|
||||
Optional<? extends PreferredConstructor<Foo, P>> constructor = new PreferredConstructorDiscoverer<Foo, P>(Foo.class)
|
||||
.getConstructor();
|
||||
PreferredConstructor<Foo, P> constructor = new PreferredConstructorDiscoverer<Foo, P>(Foo.class).getConstructor();
|
||||
|
||||
doReturn(constructor).when(entity).getPersistenceConstructor();
|
||||
|
||||
Object instance = INSTANCE.createInstance(entity, provider);
|
||||
|
||||
assertThat(instance).isInstanceOf(Foo.class);
|
||||
assertThat(constructor).hasValueSatisfying(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
|
||||
assertThat(constructor)
|
||||
.satisfies(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
|
||||
}
|
||||
|
||||
@Test(expected = MappingInstantiationException.class) // DATACMNS-300
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void throwsExceptionOnBeanInstantiationException() {
|
||||
|
||||
doReturn(Optional.empty()).when(entity).getPersistenceConstructor();
|
||||
doReturn(PersistentEntity.class).when(entity).getType();
|
||||
|
||||
INSTANCE.createInstance(entity, provider);
|
||||
@@ -103,7 +95,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
|
||||
public void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
|
||||
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(it -> {
|
||||
assertThat(entity.getPersistenceConstructor()).satisfies(it -> {
|
||||
|
||||
Parameter<Object, P> parameter = it.getParameters().iterator().next();
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.data.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -26,7 +24,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SimpleTypeInformationMapper}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimpleTypeInformationMapperUnitTests {
|
||||
@@ -36,27 +34,27 @@ public class SimpleTypeInformationMapperUnitTests {
|
||||
@Test
|
||||
public void resolvesTypeByLoadingClass() {
|
||||
|
||||
Optional<TypeInformation<?>> type = mapper.resolveTypeFrom(Alias.of("java.lang.String"));
|
||||
TypeInformation<?> type = mapper.resolveTypeFrom(Alias.of("java.lang.String"));
|
||||
|
||||
TypeInformation<?> expected = ClassTypeInformation.from(String.class);
|
||||
|
||||
assertThat(type).hasValue(expected);
|
||||
assertThat(type).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForNonStringKey() {
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(new Object()))).isEmpty();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(new Object()))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForEmptyTypeKey() {
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(""))).isEmpty();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of(""))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForUnloadableClass() {
|
||||
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("Foo"))).isEmpty();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("Foo"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user