Polishing.
Move all primary interaction API into TypeInformation to prepare making all implementations package protected. Adapt all deprecated API usage in Spring Data Commons to the new one.
Benchmark results look as follows:
2.7
Mode Cnt Score Error Units
TypicalEntityReaderBenchmark.hasReadTarget thrpt 10 81982861,995 ± 269948,368 ops/s
TypicalEntityReaderBenchmark.kotlinDataClass thrpt 10 18472975,689 ± 161234,912 ops/s
TypicalEntityReaderBenchmark.kotlinDataClassWithDefaulting thrpt 10 4029631,568 ± 18990,863 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField thrpt 10 11495517,933 ± 209269,454 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndProperty thrpt 10 11192152,036 ± 249721,563 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorArgsCreation thrpt 10 18835101,279 ± 81895,338 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedFieldAccess thrpt 10 16309896,939 ± 80376,406 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedPropertyAccess thrpt 10 15471691,537 ± 52426,121 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndField thrpt 10 12080159,283 ± 49922,326 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndProperty thrpt 10 12166160,066 ± 173876,051 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorArgsCreation thrpt 10 13548906,437 ± 485944,886 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveFieldAccess thrpt 10 16457347,670 ± 64170,567 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccess thrpt 10 14115878,948 ± 57491,268 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccessWithCustomConversionRegistry thrpt 10 15137904,257 ± 51148,726 ops/s
DefaultTypeMapperBenchmark.readTyped thrpt 10 146820080,682 ± 13254238,407 ops/s
DefaultTypeMapperBenchmark.readTypedWithBaseType thrpt 10 55420351,827 ± 1888634,217 ops/s
DefaultTypeMapperBenchmark.readUntyped thrpt 10 193934847,273 ± 442867,276 ops/s
DefaultTypeMapperBenchmark.readUntypedWithBaseType thrpt 10 192032977,366 ± 4300192,665 ops/s
3.0 – Before this change
Mode Cnt Score Error Units
TypicalEntityReaderBenchmark.hasReadTarget thrpt 10 81124249,138 ± 174095,495 ops/s
TypicalEntityReaderBenchmark.kotlinDataClass thrpt 10 18685936,220 ± 243939,063 ops/s
TypicalEntityReaderBenchmark.kotlinDataClassWithDefaulting thrpt 10 4125709,048 ± 17615,890 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField thrpt 10 12277837,989 ± 96973,908 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndProperty thrpt 10 12419978,391 ± 45780,658 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorArgsCreation thrpt 10 18744593,010 ± 71655,735 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedFieldAccess thrpt 10 16497286,465 ± 41150,718 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedPropertyAccess thrpt 10 15639640,554 ± 69758,391 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndField thrpt 10 11715068,503 ± 66085,900 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndProperty thrpt 10 12159285,083 ± 58171,950 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorArgsCreation thrpt 10 13711647,512 ± 66496,271 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveFieldAccess thrpt 10 16287057,838 ± 54826,532 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccess thrpt 10 13847665,634 ± 127834,292 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccessWithCustomConversionRegistry thrpt 10 15099300,270 ± 89030,403 ops/s
DefaultTypeMapperBenchmark.readTyped thrpt 10 151893972,774 ± 494555,250 ops/s
DefaultTypeMapperBenchmark.readTypedWithBaseType thrpt 10 55869432,892 ± 389099,409 ops/s
DefaultTypeMapperBenchmark.readUntyped thrpt 10 192661151,755 ± 1075079,924 ops/s
DefaultTypeMapperBenchmark.readUntypedWithBaseType thrpt 10 192315554,269 ± 3061160,314 ops/s
3.0 – After this change
Mode Cnt Score Error Units
TypicalEntityReaderBenchmark.hasReadTarget thrpt 10 82650245,236 ± 321384,577 ops/s
TypicalEntityReaderBenchmark.kotlinDataClass thrpt 10 21304680,430 ± 396764,834 ops/s
TypicalEntityReaderBenchmark.kotlinDataClassWithDefaulting thrpt 10 4422187,275 ± 35088,721 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField thrpt 10 13345503,496 ± 180490,423 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndProperty thrpt 10 13911653,366 ± 266028,886 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorArgsCreation thrpt 10 21192316,261 ± 356534,938 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedFieldAccess thrpt 10 17533419,173 ± 49226,408 ops/s
TypicalEntityReaderBenchmark.simpleEntityGeneratedPropertyAccess thrpt 10 17393382,078 ± 114774,442 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndField thrpt 10 12867285,952 ± 62870,980 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorAndProperty thrpt 10 13208453,130 ± 272795,070 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveConstructorArgsCreation thrpt 10 14998467,714 ± 84265,782 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectiveFieldAccess thrpt 10 17365982,413 ± 115287,403 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccess thrpt 10 15503841,949 ± 123631,592 ops/s
TypicalEntityReaderBenchmark.simpleEntityReflectivePropertyAccessWithCustomConversionRegistry thrpt 10 15716685,449 ± 64686,646 ops/s
DefaultTypeMapperBenchmark.readTyped thrpt 10 154433835,941 ± 1391455,835 ops/s
DefaultTypeMapperBenchmark.readTypedWithBaseType thrpt 10 77919886,633 ± 438244,738 ops/s
DefaultTypeMapperBenchmark.readUntyped thrpt 10 194435210,217 ± 936274,571 ops/s
DefaultTypeMapperBenchmark.readUntypedWithBaseType thrpt 10 193768718,043 ± 475103,167 ops/s
Original pull request: #2572.
Related ticket: #2312.
This commit is contained in:
@@ -25,10 +25,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConfigurableTypeInformationMapper}.
|
||||
@@ -64,14 +63,14 @@ class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProperty<T>
|
||||
@Test
|
||||
void writesMapKeyForType() {
|
||||
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class))).isEqualTo(Alias.of("1"));
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(Object.class))).isEqualTo(Alias.NONE);
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(String.class))).isEqualTo(Alias.of("1"));
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(Object.class))).isEqualTo(Alias.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsTypeForMapKey() {
|
||||
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(ClassTypeInformation.from(String.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(TypeInformation.of(String.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("unmapped"))).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultTypeMapperUnitTests {
|
||||
|
||||
static final TypeInformation<String> STRING_TYPE_INFO = ClassTypeInformation.from(String.class);
|
||||
static final TypeInformation<String> STRING_TYPE_INFO = TypeInformation.of(String.class);
|
||||
static final Alias ALIAS = Alias.of(String.class.getName());
|
||||
|
||||
@Mock TypeAliasAccessor<Map<String, String>> accessor;
|
||||
@@ -88,9 +88,9 @@ class DefaultTypeMapperUnitTests {
|
||||
@Test // DATACMNS-783
|
||||
void specializesRawSourceTypeUsingGenericContext() {
|
||||
|
||||
var root = ClassTypeInformation.from(Foo.class);
|
||||
var root = TypeInformation.of(Foo.class);
|
||||
var propertyType = root.getProperty("abstractBar");
|
||||
TypeInformation<?> barType = ClassTypeInformation.from(Bar.class);
|
||||
TypeInformation<?> barType = TypeInformation.of(Bar.class);
|
||||
|
||||
doReturn(Alias.of(barType)).when(accessor).readAliasFrom(source);
|
||||
doReturn(barType).when(mapper).resolveTypeFrom(Alias.of(barType));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -28,7 +27,7 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
import org.springframework.data.util.AnnotatedTypeScanner;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MappingContextTypeInformationMapper}.
|
||||
@@ -58,7 +57,7 @@ class MappingContextTypeInformationMapperUnitTests {
|
||||
|
||||
mapper = new MappingContextTypeInformationMapper(mappingContext);
|
||||
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(Entity.class)).hasValue("foo")).isTrue();
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(Entity.class)).hasValue("foo")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +68,7 @@ class MappingContextTypeInformationMapperUnitTests {
|
||||
|
||||
mapper = new MappingContextTypeInformationMapper(mappingContext);
|
||||
|
||||
assertThat(mapper.createAliasFor(from(Entity.class)).hasValue("foo")).isTrue();
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(Entity.class)).hasValue("foo")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +78,7 @@ class MappingContextTypeInformationMapperUnitTests {
|
||||
mappingContext.initialize();
|
||||
|
||||
mapper = new MappingContextTypeInformationMapper(mappingContext);
|
||||
assertThat(mapper.createAliasFor(from(String.class)).isPresent()).isFalse();
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(String.class)).isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +93,7 @@ class MappingContextTypeInformationMapperUnitTests {
|
||||
PersistentEntity<?, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||
|
||||
assertThat(entity).isNotNull();
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(from(Entity.class));
|
||||
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(TypeInformation.of(Entity.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-485
|
||||
|
||||
@@ -39,7 +39,7 @@ class SimpleTypeInformationMapperUnitTests {
|
||||
|
||||
var type = mapper.resolveTypeFrom(Alias.of("java.lang.String"));
|
||||
|
||||
TypeInformation<?> expected = ClassTypeInformation.from(String.class);
|
||||
TypeInformation<?> expected = TypeInformation.of(String.class);
|
||||
|
||||
assertThat(type).isEqualTo(expected);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class SimpleTypeInformationMapperUnitTests {
|
||||
@Test
|
||||
void usesFullyQualifiedClassNameAsTypeKey() {
|
||||
|
||||
assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class)))
|
||||
assertThat(mapper.createAliasFor(TypeInformation.of(String.class)))
|
||||
.isEqualTo(Alias.of(String.class.getName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -38,7 +36,7 @@ class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
@Mock PersistentEntity<Object, P> entity;
|
||||
@Mock PersistentEntity<String, P> stringEntity;
|
||||
|
||||
private TypeInformation<Object> type = ClassTypeInformation.from(Object.class);
|
||||
private TypeInformation<Object> type = TypeInformation.of(Object.class);
|
||||
private Annotation[] annotations = new Annotation[0];
|
||||
|
||||
@Test
|
||||
@@ -84,7 +82,7 @@ class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
void twoParametersWithDifferenTypeAreNotEqual() {
|
||||
|
||||
var left = new Parameter<Object, P>("name", type, annotations, entity);
|
||||
var right = new Parameter<String, P>("name", ClassTypeInformation.from(String.class), annotations,
|
||||
var right = new Parameter<String, P>("name", TypeInformation.of(String.class), annotations,
|
||||
stringEntity);
|
||||
|
||||
assertThat(left).isNotEqualTo(right);
|
||||
|
||||
@@ -24,13 +24,12 @@ import java.lang.annotation.Target;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructorDiscovererUnitTests.Outer.Inner;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PreferredConstructorDiscoverer}.
|
||||
@@ -94,7 +93,7 @@ class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test // DATACMNS-134, DATACMNS-1126
|
||||
void discoversInnerClassConstructorCorrectly() {
|
||||
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class));
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(TypeInformation.of(Inner.class));
|
||||
|
||||
assertThat(PreferredConstructorDiscoverer.discover(entity)).satisfies(constructor -> {
|
||||
|
||||
@@ -107,7 +106,7 @@ class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
|
||||
void skipsSyntheticConstructor() {
|
||||
|
||||
PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<>(
|
||||
ClassTypeInformation.from(SyntheticConstructor.class));
|
||||
TypeInformation.of(SyntheticConstructor.class));
|
||||
|
||||
assertThat(PreferredConstructorDiscoverer.discover(entity)).satisfies(constructor -> {
|
||||
|
||||
@@ -222,11 +221,11 @@ class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
|
||||
|
||||
static class ClassWithMetaAnnotatedParameter {
|
||||
|
||||
ClassWithMetaAnnotatedParameter(@MyValue String value) { }
|
||||
ClassWithMetaAnnotatedParameter(@MyValue String value) {}
|
||||
}
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Value("${hello-world}")
|
||||
@interface MyValue { }
|
||||
@interface MyValue {}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -44,7 +42,7 @@ class PropertyPathUnitTests {
|
||||
|
||||
assertThat(reference.hasNext()).isFalse();
|
||||
assertThat(reference.toDotPath()).isEqualTo("userName");
|
||||
assertThat(reference.getOwningType()).isEqualTo(ClassTypeInformation.from(Foo.class));
|
||||
assertThat(reference.getOwningType()).isEqualTo(TypeInformation.of(Foo.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,8 +21,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -33,7 +31,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
*/
|
||||
public class PropertyReferenceExceptionUnitTests {
|
||||
|
||||
static final TypeInformation<Sample> TYPE_INFO = ClassTypeInformation.from(Sample.class);
|
||||
static final TypeInformation<Sample> TYPE_INFO = TypeInformation.of(Sample.class);
|
||||
static final List<PropertyPath> NO_PATHS = Collections.emptyList();
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -45,7 +44,7 @@ class AbstractMappingContextIntegrationTests<T extends PersistentProperty<T>> {
|
||||
context.setInitialEntitySet(Collections.singleton(Person.class));
|
||||
context.initialize();
|
||||
|
||||
assertThat(context.getManagedTypes()).contains(ClassTypeInformation.from(Person.class));
|
||||
assertThat(context.getManagedTypes()).contains(TypeInformation.of(Person.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-457
|
||||
|
||||
@@ -232,7 +232,7 @@ class AbstractMappingContextUnitTests {
|
||||
void shouldIgnoreKotlinOverrideCtorPropertyInSuperClass() {
|
||||
|
||||
var entity = context
|
||||
.getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyTypeWithCtor.class));
|
||||
.getPersistentEntity(TypeInformation.of(ShadowingPropertyTypeWithCtor.class));
|
||||
entity.doWithProperties((PropertyHandler<SamplePersistentProperty>) property -> {
|
||||
assertThat(property.getField().getDeclaringClass()).isIn(ShadowingPropertyTypeWithCtor.class,
|
||||
ShadowedPropertyTypeWithCtor.class);
|
||||
@@ -243,7 +243,7 @@ class AbstractMappingContextUnitTests {
|
||||
void shouldIncludeAssignableKotlinOverridePropertyInSuperClass() {
|
||||
|
||||
var entity = context
|
||||
.getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyType.class));
|
||||
.getPersistentEntity(TypeInformation.of(ShadowingPropertyType.class));
|
||||
entity.doWithProperties((PropertyHandler<SamplePersistentProperty>) property -> {
|
||||
assertThat(property.getField().getDeclaringClass()).isIn(ShadowedPropertyType.class, ShadowingPropertyType.class);
|
||||
});
|
||||
@@ -253,7 +253,7 @@ class AbstractMappingContextUnitTests {
|
||||
void shouldIncludeAssignableShadowedPropertyInSuperClass() {
|
||||
|
||||
var entity = context
|
||||
.getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyAssignable.class));
|
||||
.getPersistentEntity(TypeInformation.of(ShadowingPropertyAssignable.class));
|
||||
|
||||
assertThat(StreamUtils.createStreamFromIterator(entity.iterator())
|
||||
.filter(it -> it.getField().getDeclaringClass().equals(ShadowedPropertyAssignable.class)).findFirst() //
|
||||
@@ -271,7 +271,7 @@ class AbstractMappingContextUnitTests {
|
||||
void shouldIgnoreNonAssignableOverridePropertyInSuperClass() {
|
||||
|
||||
var entity = context
|
||||
.getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyNotAssignable.class));
|
||||
.getPersistentEntity(TypeInformation.of(ShadowingPropertyNotAssignable.class));
|
||||
entity.doWithProperties((PropertyHandler<SamplePersistentProperty>) property -> {
|
||||
assertThat(property.getField().getDeclaringClass()).isEqualTo(ShadowingPropertyNotAssignable.class);
|
||||
});
|
||||
|
||||
@@ -24,12 +24,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PersistentEntities}.
|
||||
@@ -76,7 +75,7 @@ class PersistentEntitiesUnitTests {
|
||||
|
||||
assertThat(entities.getPersistentEntity(Sample.class)).isPresent();
|
||||
assertThat(entities.getPersistentEntity(Object.class)).isNotPresent();
|
||||
assertThat(entities.getManagedTypes()).contains(ClassTypeInformation.from(Sample.class));
|
||||
assertThat(entities.getManagedTypes()).contains(TypeInformation.of(Sample.class));
|
||||
|
||||
assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> assertThat(entities).contains(it));
|
||||
}
|
||||
|
||||
@@ -35,13 +35,10 @@ import org.jmolecules.ddd.types.AggregateRoot;
|
||||
import org.jmolecules.ddd.types.Identifier;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.convert.PropertyValueConverter;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.Person;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -62,7 +59,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
typeInfo = ClassTypeInformation.from(TestClassComplex.class);
|
||||
typeInfo = TypeInformation.of(TestClassComplex.class);
|
||||
entity = new BasicPersistentEntity<>(typeInfo);
|
||||
typeHolder = new SimpleTypeHolder();
|
||||
}
|
||||
@@ -142,7 +139,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
void doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven() {
|
||||
|
||||
var field = ReflectionUtils.findField(AccessorTestClass.class, "id");
|
||||
var property = Property.of(ClassTypeInformation.from(AccessorTestClass.class), field);
|
||||
var property = Property.of(TypeInformation.of(AccessorTestClass.class), field);
|
||||
|
||||
PersistentProperty<SamplePersistentProperty> persistentProperty = new SamplePersistentProperty(property,
|
||||
getEntity(AccessorTestClass.class), typeHolder);
|
||||
@@ -247,12 +244,12 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
}
|
||||
|
||||
private <T> BasicPersistentEntity<T, SamplePersistentProperty> getEntity(Class<T> type) {
|
||||
return new BasicPersistentEntity<>(ClassTypeInformation.from(type));
|
||||
return new BasicPersistentEntity<>(TypeInformation.of(type));
|
||||
}
|
||||
|
||||
private <T> SamplePersistentProperty getProperty(Class<T> type, String name) {
|
||||
|
||||
TypeInformation<?> typeInformation = ClassTypeInformation.from(type);
|
||||
TypeInformation<?> typeInformation = TypeInformation.of(type);
|
||||
var field = Optional.ofNullable(ReflectionUtils.findField(type, name));
|
||||
var descriptor = getPropertyDescriptor(type, name);
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
@@ -49,7 +48,7 @@ import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@@ -328,7 +327,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
|
||||
assertThat(property.getPersistentEntityTypeInformation()) //
|
||||
.isNotEmpty() //
|
||||
.allMatch(it -> it.equals(ClassTypeInformation.from(Sample.class)));
|
||||
.allMatch(it -> it.equals(TypeInformation.of(Sample.class)));
|
||||
}
|
||||
|
||||
@Test // #2438
|
||||
@@ -461,8 +460,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = { FIELD, METHOD, ANNOTATION_TYPE })
|
||||
@Id
|
||||
public @interface MyId {
|
||||
}
|
||||
public @interface MyId {}
|
||||
|
||||
static class FieldAccess {
|
||||
String name;
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
@@ -59,7 +58,7 @@ import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.Person;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@@ -287,7 +286,7 @@ class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
var failed = new AtomicBoolean(false);
|
||||
|
||||
PersistentEntity<EntityWithAnnotation, T> entity = new BasicPersistentEntity<EntityWithAnnotation, T>(
|
||||
ClassTypeInformation.from(EntityWithAnnotation.class), null) {
|
||||
TypeInformation.of(EntityWithAnnotation.class), null) {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -378,7 +377,7 @@ class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
}
|
||||
|
||||
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type, Comparator<T> comparator) {
|
||||
return new BasicPersistentEntity<>(ClassTypeInformation.from(type), comparator);
|
||||
return new BasicPersistentEntity<>(TypeInformation.of(type), comparator);
|
||||
}
|
||||
|
||||
private static PersistentEntity<Object, ?> createPopulatedPersistentEntity(Class<?> type) {
|
||||
|
||||
@@ -18,7 +18,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 static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
@@ -40,7 +39,6 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.ObjectInstantiator;
|
||||
import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiatorUnitTests.Outer.Inner;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -104,7 +102,7 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
@Test // DATACMNS-134, DATACMNS-578
|
||||
void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
var entity = new BasicPersistentEntity<Inner, P>(from(Inner.class));
|
||||
var entity = new BasicPersistentEntity<Inner, P>(TypeInformation.of(Inner.class));
|
||||
assertThat(entity.getInstanceCreatorMetadata()).satisfies(constructor -> {
|
||||
|
||||
var parameter = constructor.getParameters().iterator().next();
|
||||
@@ -130,7 +128,7 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
void capturesContextOnInstantiationException() throws Exception {
|
||||
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(TypeInformation.of(Sample.class));
|
||||
|
||||
doReturn("FOO").when(provider).getParameterValue(any(Parameter.class));
|
||||
|
||||
@@ -159,8 +157,9 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
void createsInstancesWithRecursionAndSameCtorArgCountCorrectly() {
|
||||
|
||||
PersistentEntity<SampleWithReference, P> outer = new BasicPersistentEntity<>(from(SampleWithReference.class));
|
||||
PersistentEntity<Sample, P> inner = new BasicPersistentEntity<>(from(Sample.class));
|
||||
PersistentEntity<SampleWithReference, P> outer = new BasicPersistentEntity<>(
|
||||
TypeInformation.of(SampleWithReference.class));
|
||||
PersistentEntity<Sample, P> inner = new BasicPersistentEntity<>(TypeInformation.of(Sample.class));
|
||||
|
||||
doReturn(2L, "FOO").when(provider).getParameterValue(any(Parameter.class));
|
||||
|
||||
@@ -193,7 +192,8 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
void createsInstancesWithFactoryMethodCorrectly() {
|
||||
|
||||
PersistentEntity<WithFactoryMethod, P> entity = new BasicPersistentEntity<>(from(WithFactoryMethod.class));
|
||||
PersistentEntity<WithFactoryMethod, P> entity = new BasicPersistentEntity<>(
|
||||
TypeInformation.of(WithFactoryMethod.class));
|
||||
|
||||
doReturn(2L, "FOO").when(provider).getParameterValue(any(Parameter.class));
|
||||
|
||||
@@ -436,7 +436,7 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
void entityInstantiatorShouldFailForAbstractClass() {
|
||||
|
||||
assertThatExceptionOfType(MappingInstantiationException.class).isThrownBy(() -> this.instance
|
||||
.createInstance(new BasicPersistentEntity<>(ClassTypeInformation.from(AbstractDto.class)), provider));
|
||||
.createInstance(new BasicPersistentEntity<>(TypeInformation.of(AbstractDto.class)), provider));
|
||||
}
|
||||
|
||||
private void prepareMocks(Class<?> type) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.context.SampleMappingContext;
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.PersistenceCreator;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link InstanceCreatorMetadataDiscoverer}.
|
||||
@@ -33,7 +33,7 @@ class EntityCreatorMetadataDiscovererUnitTests {
|
||||
@Test
|
||||
void shouldDiscoverAnnotatedFactoryMethod() {
|
||||
|
||||
var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(FactoryMethodsPerson.class));
|
||||
var entity = new BasicPersistentEntity<>(TypeInformation.of(FactoryMethodsPerson.class));
|
||||
var creator = InstanceCreatorMetadataDiscoverer.discover(entity);
|
||||
|
||||
assertThat(creator).isInstanceOf(org.springframework.data.mapping.FactoryMethod.class);
|
||||
@@ -44,7 +44,7 @@ class EntityCreatorMetadataDiscovererUnitTests {
|
||||
@Test
|
||||
void shouldDiscoverAnnotatedConstructor() {
|
||||
|
||||
var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(ConstructorPerson.class));
|
||||
var entity = new BasicPersistentEntity<>(TypeInformation.of(ConstructorPerson.class));
|
||||
var creator = InstanceCreatorMetadataDiscoverer.discover(entity);
|
||||
|
||||
assertThat(creator).isInstanceOf(PreferredConstructor.class);
|
||||
@@ -53,7 +53,7 @@ class EntityCreatorMetadataDiscovererUnitTests {
|
||||
@Test
|
||||
void shouldDiscoverDefaultConstructor() {
|
||||
|
||||
var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Person.class));
|
||||
var entity = new BasicPersistentEntity<>(TypeInformation.of(Person.class));
|
||||
var creator = InstanceCreatorMetadataDiscoverer.discover(entity);
|
||||
|
||||
assertThat(creator).isInstanceOf(PreferredConstructor.class);
|
||||
@@ -62,7 +62,7 @@ class EntityCreatorMetadataDiscovererUnitTests {
|
||||
@Test
|
||||
void shouldRejectNonStaticFactoryMethod() {
|
||||
assertThatExceptionOfType(MappingException.class)
|
||||
.isThrownBy(() -> new BasicPersistentEntity<>(ClassTypeInformation.from(NonStaticFactoryMethod.class)));
|
||||
.isThrownBy(() -> new BasicPersistentEntity<>(TypeInformation.of(NonStaticFactoryMethod.class)));
|
||||
}
|
||||
|
||||
static class Person {
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.PersistenceCreator;
|
||||
import org.springframework.data.mapping.Parameter;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.data.mapping.FactoryMethod}.
|
||||
@@ -34,7 +34,7 @@ class FactoryMethodUnitTests {
|
||||
@Test
|
||||
void shouldCreateInstanceThroughFactoryMethod() {
|
||||
|
||||
var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(FactoryPerson.class));
|
||||
var entity = new BasicPersistentEntity<>(TypeInformation.of(FactoryPerson.class));
|
||||
|
||||
var result = instantiators.getInstantiatorFor(entity).createInstance(entity,
|
||||
new ParameterValueProvider() {
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.model.PersistentEntityParameterValueProviderUnitTests.Outer.Inner;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PersistentEntityParameterValueProvider}.
|
||||
@@ -46,7 +46,7 @@ class PersistentEntityParameterValueProviderUnitTests<P extends PersistentProper
|
||||
|
||||
Object outer = new Outer();
|
||||
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class)) {
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(TypeInformation.of(Inner.class)) {
|
||||
|
||||
@Override
|
||||
public P getPersistentProperty(String name) {
|
||||
@@ -69,7 +69,7 @@ class PersistentEntityParameterValueProviderUnitTests<P extends PersistentProper
|
||||
@Test
|
||||
void rejectsPropertyIfNameDoesNotMatch() {
|
||||
|
||||
PersistentEntity<Entity, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Entity.class));
|
||||
PersistentEntity<Entity, P> entity = new BasicPersistentEntity<>(TypeInformation.of(Entity.class));
|
||||
ParameterValueProvider<P> provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider,
|
||||
Optional.of(property));
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import lombok.Value;
|
||||
import lombok.With;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -35,17 +35,17 @@ class PropertyUnitTests {
|
||||
void shouldNotFindWitherMethod() {
|
||||
|
||||
assertThat(Property
|
||||
.of(ClassTypeInformation.from(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "id"))
|
||||
.of(TypeInformation.of(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "id"))
|
||||
.getWither()).isEmpty();
|
||||
assertThat(Property
|
||||
.of(ClassTypeInformation.from(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "name"))
|
||||
.of(TypeInformation.of(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "name"))
|
||||
.getWither()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
void shouldDiscoverWitherMethod() {
|
||||
|
||||
var property = Property.of(ClassTypeInformation.from(WitherType.class),
|
||||
var property = Property.of(TypeInformation.of(WitherType.class),
|
||||
ReflectionUtils.findField(WitherType.class, "id"));
|
||||
|
||||
assertThat(property.getWither()).isPresent().hasValueSatisfying(actual -> {
|
||||
@@ -57,7 +57,7 @@ class PropertyUnitTests {
|
||||
@Test // DATACMNS-1421
|
||||
void shouldDiscoverDerivedWitherMethod() {
|
||||
|
||||
var property = Property.of(ClassTypeInformation.from(DerivedWitherClass.class),
|
||||
var property = Property.of(TypeInformation.of(DerivedWitherClass.class),
|
||||
ReflectionUtils.findField(DerivedWitherClass.class, "id"));
|
||||
|
||||
assertThat(property.getWither()).isPresent().hasValueSatisfying(actual -> {
|
||||
@@ -70,7 +70,7 @@ class PropertyUnitTests {
|
||||
@Test // DATACMNS-1421
|
||||
void shouldNotDiscoverWitherMethodWithIncompatibleReturnType() {
|
||||
|
||||
var property = Property.of(ClassTypeInformation.from(AnotherLevel.class),
|
||||
var property = Property.of(TypeInformation.of(AnotherLevel.class),
|
||||
ReflectionUtils.findField(AnotherLevel.class, "id"));
|
||||
|
||||
assertThat(property.getWither()).isEmpty();
|
||||
@@ -110,6 +110,7 @@ class PropertyUnitTests {
|
||||
|
||||
static abstract class WitherIntermediateClass extends WitherBaseClass {
|
||||
|
||||
@Override
|
||||
abstract WitherIntermediateClass withId(String id);
|
||||
}
|
||||
|
||||
@@ -121,6 +122,7 @@ class PropertyUnitTests {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
DerivedWitherClass withId(String id) {
|
||||
return new DerivedWitherClass(id);
|
||||
}
|
||||
@@ -132,6 +134,7 @@ class PropertyUnitTests {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
DerivedWitherClass withId(String id) {
|
||||
return new AnotherLevel(id);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.mapping.model.ReflectionEntityInstantiator.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.model.ReflectionEntityInstantiatorUnitTests.Outer.Inner;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
@Test // DATACMNS-134
|
||||
void createsInnerClassInstanceCorrectly() {
|
||||
|
||||
var entity = new BasicPersistentEntity<Inner, P>(from(Inner.class));
|
||||
var entity = new BasicPersistentEntity<Inner, P>(TypeInformation.of(Inner.class));
|
||||
assertThat(entity.getInstanceCreatorMetadata()).satisfies(it -> {
|
||||
|
||||
var parameter = it.getParameters().iterator().next();
|
||||
@@ -116,7 +116,7 @@ class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
void capturesContextOnInstantiationException() throws Exception {
|
||||
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
|
||||
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(TypeInformation.of(Sample.class));
|
||||
|
||||
doReturn("FOO").when(provider).getParameterValue(any(Parameter.class));
|
||||
|
||||
|
||||
@@ -23,14 +23,12 @@ import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.querydsl.User;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
@@ -47,7 +45,7 @@ import com.querydsl.core.types.Predicate;
|
||||
*/
|
||||
class QuerydslBindingsFactoryUnitTests {
|
||||
|
||||
static final TypeInformation<?> USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
static final TypeInformation<?> USER_TYPE = TypeInformation.of(User.class);
|
||||
|
||||
QuerydslBindingsFactory factory;
|
||||
|
||||
@@ -123,7 +121,7 @@ class QuerydslBindingsFactoryUnitTests {
|
||||
void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() {
|
||||
|
||||
assertThatIllegalStateException()//
|
||||
.isThrownBy(() -> factory.createBindingsFor(ClassTypeInformation.from(ModelAndView.class)))//
|
||||
.isThrownBy(() -> factory.createBindingsFor(TypeInformation.of(ModelAndView.class)))//
|
||||
.withMessageContaining(QuerydslPredicate.class.getSimpleName())//
|
||||
.withMessageContaining("root");
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.querydsl.Address;
|
||||
import org.springframework.data.querydsl.QAddress;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.data.querydsl.QSpecialUser;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.querydsl.User;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
@@ -230,7 +229,7 @@ class QuerydslBindingsUnitTests {
|
||||
|
||||
bindings.bind(QUser.user.address.city).as("city").first(CONTAINS_BINDING);
|
||||
|
||||
var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
var path = bindings.getPropertyPath("city", TypeInformation.of(User.class));
|
||||
|
||||
assertThat(path).isNotNull();
|
||||
assertThat(bindings.isPathAvailable("city", User.class)).isTrue();
|
||||
@@ -245,14 +244,14 @@ class QuerydslBindingsUnitTests {
|
||||
bindings.including(QUser.user.address.city);
|
||||
bindings.bind(QUser.user.address.city).as("city").first(CONTAINS_BINDING);
|
||||
|
||||
var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
var path = bindings.getPropertyPath("city", TypeInformation.of(User.class));
|
||||
|
||||
assertThat(path).isNotNull();
|
||||
assertThat(bindings.isPathAvailable("city", User.class)).isTrue();
|
||||
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isTrue();
|
||||
|
||||
var propertyPath = bindings.getPropertyPath("address.city", ClassTypeInformation.from(User.class));
|
||||
var propertyPath = bindings.getPropertyPath("address.city", TypeInformation.of(User.class));
|
||||
assertThat(propertyPath).isNotNull();
|
||||
|
||||
assertAdapterWithTargetBinding(bindings.getBindingForPath(propertyPath), CONTAINS_BINDING);
|
||||
@@ -263,7 +262,7 @@ class QuerydslBindingsUnitTests {
|
||||
|
||||
bindings.bind(QUser.user.address.city).as("city").withDefaultBinding();
|
||||
|
||||
var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
var path = bindings.getPropertyPath("city", TypeInformation.of(User.class));
|
||||
assertThat(path).isNotNull();
|
||||
|
||||
assertThat(bindings.getBindingForPath(path)).isNotPresent();
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.querydsl.Address;
|
||||
import org.springframework.data.querydsl.QSpecialUser;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
@@ -32,7 +31,8 @@ import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.querydsl.User;
|
||||
import org.springframework.data.querydsl.UserWrapper;
|
||||
import org.springframework.data.querydsl.Users;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
// import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.data.util.Version;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -51,7 +51,7 @@ import com.querydsl.core.types.dsl.StringPath;
|
||||
*/
|
||||
class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
static final ClassTypeInformation<User> USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
static final TypeInformation<User> USER_TYPE = TypeInformation.of(User.class);
|
||||
static final QuerydslBindings DEFAULT_BINDINGS = new QuerydslBindings();
|
||||
static final SingleValueBinding<StringPath, String> CONTAINS_BINDING = (path, value) -> path.contains(value);
|
||||
|
||||
@@ -79,8 +79,9 @@ class QuerydslPredicateBuilderUnitTests {
|
||||
@Test // DATACMNS-669, DATACMNS-1168
|
||||
void getPredicateShouldReturnEmptyWhenPropertiesAreEmpty() {
|
||||
assertThat(
|
||||
QuerydslPredicateBuilder.isEmpty(builder.getPredicate(ClassTypeInformation.OBJECT, values, DEFAULT_BINDINGS)))
|
||||
.isTrue();
|
||||
QuerydslPredicateBuilder
|
||||
.isEmpty(builder.getPredicate(TypeInformation.of(Object.class), values, DEFAULT_BINDINGS)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // GH-2418
|
||||
@@ -89,11 +90,11 @@ class QuerydslPredicateBuilderUnitTests {
|
||||
DEFAULT_BINDINGS.bind(QUser.user.description).first(CONTAINS_BINDING);
|
||||
|
||||
values.add("description", "Linz");
|
||||
var predicate = this.builder.getPredicate(ClassTypeInformation.from(User.class), values, DEFAULT_BINDINGS);
|
||||
var predicate = this.builder.getPredicate(TypeInformation.of(User.class), values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate).hasToString("contains(user.description,Linz)");
|
||||
|
||||
predicate = this.builder.getPredicate(ClassTypeInformation.from(Address.class), values, DEFAULT_BINDINGS);
|
||||
predicate = this.builder.getPredicate(TypeInformation.of(Address.class), values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate).hasToString("address.description = Linz");
|
||||
}
|
||||
@@ -214,7 +215,7 @@ class QuerydslPredicateBuilderUnitTests {
|
||||
bindings.bind(wrapper.user.as(QSpecialUser.class).specialProperty)//
|
||||
.first(QuerydslBindingsUnitTests.ContainsBinding.INSTANCE);
|
||||
|
||||
assertThat(builder.getPredicate(ClassTypeInformation.from(UserWrapper.class), values, bindings))//
|
||||
assertThat(builder.getPredicate(TypeInformation.of(UserWrapper.class), values, bindings))//
|
||||
.isEqualTo(wrapper.user.as(QSpecialUser.class).specialProperty.contains("VALUE"));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,14 +22,12 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.util.ClassUtils;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -84,7 +82,7 @@ class DefaultRepositoryMetadataUnitTests {
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(GenericEntityRepository.class);
|
||||
TypeInformation<?> domainType = metadata.getDomainTypeInformation();
|
||||
assertThat(domainType.getType()).isEqualTo(GenericEntity.class);
|
||||
assertThat(domainType.getTypeArguments()).containsExactly(ClassTypeInformation.from(String.class));
|
||||
assertThat(domainType.getTypeArguments()).containsExactly(TypeInformation.of(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,7 +19,6 @@ import static java.util.Collections.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.repository.core.support.DummyRepositoryFactory.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -40,25 +39,23 @@ import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.RepositoryDefinition;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DummyRepositoryFactory.MyRepositoryQuery;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
|
||||
import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener.RepositoryMethodInvocation;
|
||||
import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener.RepositoryMethodInvocationResult.State;
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
|
||||
@@ -37,7 +36,7 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactoryInformation;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
* Integration test for {@link DomainClassConverter}.
|
||||
@@ -66,8 +65,8 @@ class DomainClassConverterIntegrationTests {
|
||||
beanFactory.registerBeanDefinition("postProcessor", new RootBeanDefinition(PredictingProcessor.class));
|
||||
beanFactory.registerBeanDefinition("repoFactory", new RootBeanDefinition(RepositoryFactoryBeanSupport.class));
|
||||
|
||||
doReturn(ClassTypeInformation.from(Person.class)).when(information).getDomainTypeInformation();
|
||||
doReturn(ClassTypeInformation.from(Serializable.class)).when(information).getIdTypeInformation();
|
||||
doReturn(TypeInformation.of(Person.class)).when(information).getDomainTypeInformation();
|
||||
doReturn(TypeInformation.of(Serializable.class)).when(information).getIdTypeInformation();
|
||||
doCallRealMethod().when(information).getDomainType();
|
||||
doReturn(PersonRepository.class).when(factory).getObjectType();
|
||||
doReturn(information).when(factory).getRepositoryInformation();
|
||||
|
||||
@@ -33,20 +33,18 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.NullableWrapper;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
@@ -185,7 +183,7 @@ class QueryExecutionConvertersUnitTests {
|
||||
void unwrapsPages() throws Exception {
|
||||
|
||||
var method = Sample.class.getMethod("pages");
|
||||
var returnType = ClassTypeInformation.fromReturnTypeOf(method);
|
||||
var returnType = TypeInformation.fromReturnTypeOf(method);
|
||||
|
||||
assertThat(QueryExecutionConverters.unwrapWrapperTypes(returnType).getType())
|
||||
.isEqualTo(String.class);
|
||||
@@ -207,9 +205,7 @@ class QueryExecutionConvertersUnitTests {
|
||||
for (var methodName : Arrays.asList("tryMethod", "tryForSeqMethod")) {
|
||||
|
||||
var method = Sample.class.getMethod(methodName);
|
||||
|
||||
var type = QueryExecutionConverters
|
||||
.unwrapWrapperTypes(ClassTypeInformation.fromReturnTypeOf(method));
|
||||
var type = QueryExecutionConverters.unwrapWrapperTypes(TypeInformation.fromReturnTypeOf(method));
|
||||
|
||||
assertThat(type.getType()).isEqualTo(Sample.class);
|
||||
}
|
||||
@@ -231,9 +227,7 @@ class QueryExecutionConvertersUnitTests {
|
||||
for (var methodName : Arrays.asList("tryMethod", "tryForSeqMethod")) {
|
||||
|
||||
var method = Sample.class.getMethod(methodName);
|
||||
|
||||
var type = QueryExecutionConverters
|
||||
.unwrapWrapperTypes(ClassTypeInformation.fromReturnTypeOf(method));
|
||||
var type = QueryExecutionConverters.unwrapWrapperTypes(TypeInformation.fromReturnTypeOf(method));
|
||||
|
||||
assertThat(type.getType()).isEqualTo(Sample.class);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.data.util;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import io.vavr.collection.Traversable;
|
||||
|
||||
@@ -34,7 +35,7 @@ import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.AopConfigException;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.data.mapping.Person;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoversTypeForSimpleGenericField() {
|
||||
|
||||
TypeInformation<ConcreteType> discoverer = from(ConcreteType.class);
|
||||
TypeInformation<ConcreteType> discoverer = TypeInformation.of(ConcreteType.class);
|
||||
|
||||
assertThat(discoverer.getType()).isEqualTo(ConcreteType.class);
|
||||
|
||||
@@ -63,7 +64,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoversTypeForNestedGenericField() {
|
||||
|
||||
TypeInformation<ConcreteWrapper> discoverer = from(ConcreteWrapper.class);
|
||||
TypeInformation<ConcreteWrapper> discoverer = TypeInformation.of(ConcreteWrapper.class);
|
||||
assertThat(discoverer.getType()).isEqualTo(ConcreteWrapper.class);
|
||||
|
||||
assertThat(discoverer.getProperty("wrapped")).satisfies(it -> {
|
||||
@@ -79,14 +80,14 @@ public class ClassTypeInformationUnitTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void discoversBoundType() {
|
||||
|
||||
TypeInformation<GenericTypeWithBound> information = from(GenericTypeWithBound.class);
|
||||
TypeInformation<GenericTypeWithBound> information = TypeInformation.of(GenericTypeWithBound.class);
|
||||
assertThat(information.getProperty("person")).satisfies(it -> assertThat(it.getType()).isEqualTo(Person.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversBoundTypeForSpecialization() {
|
||||
|
||||
TypeInformation<SpecialGenericTypeWithBound> information = from(SpecialGenericTypeWithBound.class);
|
||||
TypeInformation<SpecialGenericTypeWithBound> information = TypeInformation.of(SpecialGenericTypeWithBound.class);
|
||||
assertThat(information.getProperty("person"))
|
||||
.satisfies(it -> assertThat(it.getType()).isEqualTo(SpecialPerson.class));
|
||||
}
|
||||
@@ -95,7 +96,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void discoversBoundTypeForNested() {
|
||||
|
||||
TypeInformation<AnotherGenericType> information = from(AnotherGenericType.class);
|
||||
TypeInformation<AnotherGenericType> information = TypeInformation.of(AnotherGenericType.class);
|
||||
|
||||
assertThat(information.getProperty("nested"))
|
||||
.satisfies(it -> assertThat(it.getType()).isEqualTo(GenericTypeWithBound.class));
|
||||
@@ -106,7 +107,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoversArraysAndCollections() {
|
||||
|
||||
TypeInformation<StringCollectionContainer> information = from(StringCollectionContainer.class);
|
||||
TypeInformation<StringCollectionContainer> information = TypeInformation.of(StringCollectionContainer.class);
|
||||
|
||||
var array = information.getProperty("array");
|
||||
|
||||
@@ -132,7 +133,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoversMapValueType() {
|
||||
|
||||
TypeInformation<StringMapContainer> information = from(StringMapContainer.class);
|
||||
TypeInformation<StringMapContainer> information = TypeInformation.of(StringMapContainer.class);
|
||||
|
||||
var genericMap = information.getProperty("genericMap");
|
||||
|
||||
@@ -148,8 +149,8 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void typeInfoDoesNotEqualForGenericTypesWithDifferentParent() {
|
||||
|
||||
TypeInformation<ConcreteWrapper> first = from(ConcreteWrapper.class);
|
||||
TypeInformation<AnotherConcreteWrapper> second = from(AnotherConcreteWrapper.class);
|
||||
TypeInformation<ConcreteWrapper> first = TypeInformation.of(ConcreteWrapper.class);
|
||||
TypeInformation<AnotherConcreteWrapper> second = TypeInformation.of(AnotherConcreteWrapper.class);
|
||||
|
||||
assertThat(first.getProperty("wrapped").equals(second.getProperty("wrapped"))).isFalse();
|
||||
}
|
||||
@@ -157,7 +158,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void handlesPropertyFieldMismatchCorrectly() {
|
||||
|
||||
TypeInformation<PropertyGetter> from = from(PropertyGetter.class);
|
||||
TypeInformation<PropertyGetter> from = TypeInformation.of(PropertyGetter.class);
|
||||
|
||||
assertThat(from.getProperty("_name")).satisfies(it -> assertThat(it.getType()).isEqualTo(String.class));
|
||||
assertThat(from.getProperty("name")).satisfies(it -> assertThat(it.getType()).isEqualTo(byte[].class));
|
||||
@@ -166,14 +167,14 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-77
|
||||
public void returnsSameInstanceForCachedClass() {
|
||||
|
||||
TypeInformation<PropertyGetter> info = from(PropertyGetter.class);
|
||||
assertThat(from(PropertyGetter.class)).isSameAs(info);
|
||||
TypeInformation<PropertyGetter> info = TypeInformation.of(PropertyGetter.class);
|
||||
assertThat(TypeInformation.of(PropertyGetter.class)).isSameAs(info);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-39
|
||||
public void resolvesWildCardTypeCorrectly() {
|
||||
|
||||
TypeInformation<ClassWithWildCardBound> information = from(ClassWithWildCardBound.class);
|
||||
TypeInformation<ClassWithWildCardBound> information = TypeInformation.of(ClassWithWildCardBound.class);
|
||||
|
||||
var wildcard = information.getProperty("wildcard");
|
||||
|
||||
@@ -192,7 +193,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void resolvesTypeParametersCorrectly() {
|
||||
|
||||
TypeInformation<ConcreteType> information = from(ConcreteType.class);
|
||||
TypeInformation<ConcreteType> information = TypeInformation.of(ConcreteType.class);
|
||||
var superTypeInformation = information.getSuperTypeInformation(GenericType.class);
|
||||
|
||||
var parameters = superTypeInformation.getTypeArguments();
|
||||
@@ -204,7 +205,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void resolvesNestedInheritedTypeParameters() {
|
||||
|
||||
TypeInformation<SecondExtension> information = from(SecondExtension.class);
|
||||
TypeInformation<SecondExtension> information = TypeInformation.of(SecondExtension.class);
|
||||
var superTypeInformation = information.getSuperTypeInformation(Base.class);
|
||||
|
||||
var parameters = superTypeInformation.getTypeArguments();
|
||||
@@ -215,7 +216,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoveresMethodParameterTypesCorrectly() throws Exception {
|
||||
|
||||
TypeInformation<SecondExtension> information = from(SecondExtension.class);
|
||||
TypeInformation<SecondExtension> information = TypeInformation.of(SecondExtension.class);
|
||||
var method = SecondExtension.class.getMethod("foo", Base.class);
|
||||
var informations = information.getParameterTypes(method);
|
||||
var returnTypeInformation = information.getReturnType(method);
|
||||
@@ -228,51 +229,54 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test
|
||||
public void discoversImplementationBindingCorrectlyForString() throws Exception {
|
||||
|
||||
TypeInformation<TypedClient> information = from(TypedClient.class);
|
||||
TypeInformation<TypedClient> information = TypeInformation.of(TypedClient.class);
|
||||
var method = TypedClient.class.getMethod("stringMethod", GenericInterface.class);
|
||||
|
||||
var parameterType = information.getParameterTypes(method).get(0);
|
||||
|
||||
TypeInformation<StringImplementation> stringInfo = from(StringImplementation.class);
|
||||
TypeInformation<StringImplementation> stringInfo = TypeInformation.of(StringImplementation.class);
|
||||
assertThat(parameterType.isAssignableFrom(stringInfo)).isTrue();
|
||||
assertThat(stringInfo.getSuperTypeInformation(GenericInterface.class)).isEqualTo(parameterType);
|
||||
assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isFalse();
|
||||
assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isFalse();
|
||||
assertThat(parameterType
|
||||
.isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isTrue();
|
||||
.isAssignableFrom(
|
||||
TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversImplementationBindingCorrectlyForLong() throws Exception {
|
||||
|
||||
TypeInformation<TypedClient> information = from(TypedClient.class);
|
||||
TypeInformation<TypedClient> information = TypeInformation.of(TypedClient.class);
|
||||
var method = TypedClient.class.getMethod("longMethod", GenericInterface.class);
|
||||
|
||||
var parameterType = information.getParameterTypes(method).get(0);
|
||||
|
||||
assertThat(parameterType.isAssignableFrom(from(StringImplementation.class))).isFalse();
|
||||
assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isTrue();
|
||||
assertThat(parameterType.isAssignableFrom(TypeInformation.of(StringImplementation.class))).isFalse();
|
||||
assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isTrue();
|
||||
assertThat(parameterType
|
||||
.isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse();
|
||||
.isAssignableFrom(
|
||||
TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversImplementationBindingCorrectlyForNumber() throws Exception {
|
||||
|
||||
TypeInformation<TypedClient> information = from(TypedClient.class);
|
||||
TypeInformation<TypedClient> information = TypeInformation.of(TypedClient.class);
|
||||
var method = TypedClient.class.getMethod("boundToNumberMethod", GenericInterface.class);
|
||||
|
||||
var parameterType = information.getParameterTypes(method).get(0);
|
||||
|
||||
assertThat(parameterType.isAssignableFrom(from(StringImplementation.class))).isFalse();
|
||||
assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isTrue();
|
||||
assertThat(parameterType.isAssignableFrom(TypeInformation.of(StringImplementation.class))).isFalse();
|
||||
assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isTrue();
|
||||
assertThat(parameterType
|
||||
.isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse();
|
||||
.isAssignableFrom(
|
||||
TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsComponentTypeForMultiDimensionalArrayCorrectly() {
|
||||
|
||||
TypeInformation<?> information = from(String[][].class);
|
||||
TypeInformation<?> information = TypeInformation.of(String[][].class);
|
||||
|
||||
assertThat(information.getType()).isEqualTo(String[][].class);
|
||||
assertThat(information.getComponentType()).satisfies(it -> assertThat(it.getType()).isEqualTo(String[].class));
|
||||
@@ -282,27 +286,32 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-309
|
||||
public void findsGetterOnInterface() {
|
||||
|
||||
TypeInformation<Product> information = from(Product.class);
|
||||
TypeInformation<Product> information = TypeInformation.of(Product.class);
|
||||
|
||||
assertThat(information.getProperty("category.id")).isEqualTo(from(Long.class));
|
||||
assertThat(information.getProperty("category.id")).isEqualTo(TypeInformation.of(Long.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-387
|
||||
public void rejectsNullClass() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> ClassTypeInformation.from(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> TypeInformation.of((Class<?>) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-387
|
||||
public void rejectsNullResolvableType() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> TypeInformation.of((ResolvableType) null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-422
|
||||
public void returnsEmptyOptionalForRawTypesOnly() {
|
||||
|
||||
assertThat(from(MyRawIterable.class).getComponentType()).isNull();
|
||||
assertThat(from(MyIterable.class).getComponentType()).isNotNull();
|
||||
assertThat(TypeInformation.of(MyRawIterable.class).getComponentType()).isNull();
|
||||
assertThat(TypeInformation.of(MyIterable.class).getComponentType()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-440
|
||||
public void detectsSpecialMapAsMapValueType() {
|
||||
|
||||
var seriously = from(SuperGenerics.class).getProperty("seriously");
|
||||
var seriously = TypeInformation.of(SuperGenerics.class).getProperty("seriously");
|
||||
|
||||
// Type
|
||||
assertThat(seriously.getType()).isEqualTo(SortedMap.class);
|
||||
@@ -321,14 +330,14 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
@Test // DATACMNS-446
|
||||
public void createsToStringRepresentation() {
|
||||
assertThat(from(SpecialPerson.class).toString())
|
||||
assertThat(TypeInformation.of(SpecialPerson.class).toString())
|
||||
.isEqualTo("org.springframework.data.util.ClassTypeInformationUnitTests$SpecialPerson");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-590
|
||||
public void resolvesNestedGenericsToConcreteType() {
|
||||
|
||||
var rootType = from(ConcreteRoot.class);
|
||||
var rootType = TypeInformation.of(ConcreteRoot.class);
|
||||
|
||||
assertThat(rootType.getProperty("subs").getActualType().getProperty("subSub").getType())//
|
||||
.isEqualTo(ConcreteSubSub.class);
|
||||
@@ -337,7 +346,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-594
|
||||
public void considersGenericsOfTypeBounds() {
|
||||
|
||||
assertThat(from(ConcreteRootIntermediate.class)
|
||||
assertThat(TypeInformation.of(ConcreteRootIntermediate.class)
|
||||
.getProperty("intermediate.content.intermediate.content").getType())//
|
||||
.isEqualTo(Leaf.class);
|
||||
}
|
||||
@@ -345,21 +354,21 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-783, DATACMNS-853
|
||||
public void specializesTypeUsingTypeVariableContext() {
|
||||
|
||||
var root = from(Foo.class);
|
||||
var root = TypeInformation.of(Foo.class);
|
||||
|
||||
assertThat(root.getProperty("abstractBar").specialize(from(Bar.class)))//
|
||||
assertThat(root.getProperty("abstractBar").specialize(TypeInformation.of(Bar.class)))//
|
||||
.satisfies(it -> {
|
||||
assertThat(it.getType()).isEqualTo(Bar.class);
|
||||
assertThat(it.getProperty("field").getType()).isEqualTo(Character.class);
|
||||
assertThat(it.getProperty("anotherField").getType()).isEqualTo(Integer.class);
|
||||
assertThat(it.getProperty("field").getType()).isEqualTo(Character.class);
|
||||
assertThat(it.getProperty("anotherField").getType()).isEqualTo(Integer.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-783
|
||||
public void usesTargetTypeDirectlyIfNoGenericsAreInvolved() {
|
||||
|
||||
var root = ClassTypeInformation.from(Foo.class);
|
||||
ClassTypeInformation<?> from = ClassTypeInformation.from(Bar.class);
|
||||
var root = TypeInformation.of(Foo.class);
|
||||
TypeInformation<?> from = TypeInformation.of(Bar.class);
|
||||
|
||||
assertThat(root.getProperty("object").specialize(from)).isEqualTo(from);
|
||||
}
|
||||
@@ -367,12 +376,12 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-855
|
||||
public void specializedTypeEqualsAndHashCode() {
|
||||
|
||||
var root = ClassTypeInformation.from(Foo.class);
|
||||
var root = TypeInformation.of(Foo.class);
|
||||
|
||||
var abstractBar = root.getProperty("abstractBar");
|
||||
|
||||
assertThat(Pair.of(abstractBar.specialize(ClassTypeInformation.from(Bar.class)),
|
||||
abstractBar.specialize(ClassTypeInformation.from(Bar.class)))).satisfies(pair -> {
|
||||
assertThat(Pair.of(abstractBar.specialize(TypeInformation.of(Bar.class)),
|
||||
abstractBar.specialize(TypeInformation.of(Bar.class)))).satisfies(pair -> {
|
||||
assertThat(pair.getFirst()).isEqualTo(pair.getSecond());
|
||||
assertThat(pair.getSecond()).isEqualTo(pair.getFirst());
|
||||
assertThat(pair.getFirst().hashCode()).isEqualTo(pair.getSecond().hashCode());
|
||||
@@ -382,7 +391,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-896
|
||||
public void prefersLocalTypeMappingOverNestedWithSameGenericType() {
|
||||
|
||||
var information = from(Concrete.class);
|
||||
var information = TypeInformation.of(Concrete.class);
|
||||
|
||||
assertThat(information.getProperty("field").getType()).isEqualTo(Nested.class);
|
||||
}
|
||||
@@ -390,7 +399,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-940
|
||||
public void detectsVavrTraversableComponentType() {
|
||||
|
||||
var information = from(SampleTraversable.class);
|
||||
var information = TypeInformation.of(SampleTraversable.class);
|
||||
|
||||
assertThat(information.getComponentType().getType()).isAssignableFrom(Integer.class);
|
||||
}
|
||||
@@ -398,7 +407,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-940
|
||||
public void detectsVavrMapComponentAndValueType() {
|
||||
|
||||
var information = from(SampleMap.class);
|
||||
var information = TypeInformation.of(SampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType()).isAssignableFrom(String.class);
|
||||
|
||||
@@ -408,8 +417,8 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-1138
|
||||
public void usesTargetTypeForWildcardedBaseOnSpecialization() {
|
||||
|
||||
var wrapper = from(WildcardedWrapper.class);
|
||||
var concrete = from(SomeConcrete.class);
|
||||
var wrapper = TypeInformation.of(WildcardedWrapper.class);
|
||||
var concrete = TypeInformation.of(SomeConcrete.class);
|
||||
|
||||
var property = wrapper.getRequiredProperty("wildcarded");
|
||||
|
||||
@@ -419,14 +428,14 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-1571
|
||||
public void considersGenericsOfTypeToSpecializeToIfFullyResolved() {
|
||||
|
||||
TypeInformation<StoredEvent> storeEvent = ClassTypeInformation.from(StoredEvent.class);
|
||||
TypeInformation<StoredEvent> storeEvent = TypeInformation.of(StoredEvent.class);
|
||||
assertThat(storeEvent.getType()).isEqualTo(StoredEvent.class);
|
||||
|
||||
var domainEvent = (TypeInformation<DomainEvent>) storeEvent.getProperty("event");
|
||||
assertThat(domainEvent.getType()).isEqualTo(DomainEvent.class);
|
||||
|
||||
var specialized = domainEvent
|
||||
.specialize(ClassTypeInformation.from(OfferCreated.class));
|
||||
.specialize(TypeInformation.of(OfferCreated.class));
|
||||
|
||||
assertThat(specialized.getType()).isEqualTo(OfferCreated.class);
|
||||
assertThat(specialized.getProperty("aggregateId").getType()).isEqualTo(Long.class);
|
||||
@@ -436,14 +445,14 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-1571
|
||||
public void mergesGenericsFromContextAndProvidedDefaultOnSpecialization() {
|
||||
|
||||
TypeInformation<StoredEvent> storeEvent = ClassTypeInformation.from(StoredEvent.class);
|
||||
TypeInformation<StoredEvent> storeEvent = TypeInformation.of(StoredEvent.class);
|
||||
assertThat(storeEvent.getType()).isEqualTo(StoredEvent.class);
|
||||
|
||||
var domainEvent = (TypeInformation<DomainEvent>) storeEvent.getProperty("event");
|
||||
assertThat(domainEvent.getType()).isEqualTo(DomainEvent.class);
|
||||
|
||||
var specialized = domainEvent
|
||||
.specialize(ClassTypeInformation.from(GenericEvent.class));
|
||||
.specialize(TypeInformation.of(GenericEvent.class));
|
||||
|
||||
assertThat(specialized.getType()).isEqualTo(GenericEvent.class);
|
||||
assertThat(specialized.getProperty("aggregateId").getType()).isEqualTo(Long.class);
|
||||
@@ -453,7 +462,7 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-1828
|
||||
void discoversMapKeyAndValueTypeFromTypedMap() {
|
||||
|
||||
TypeInformation<TypeWithTypedMap> information = from(TypeWithTypedMap.class);
|
||||
TypeInformation<TypeWithTypedMap> information = TypeInformation.of(TypeWithTypedMap.class);
|
||||
|
||||
var typedMap = information.getProperty("typedMap");
|
||||
|
||||
@@ -477,20 +486,21 @@ public class ClassTypeInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // GH-2485
|
||||
public void proxyTypeInformationShouldNotEqualUserClassTypeInfo () {
|
||||
public void proxyTypeInformationShouldNotEqualUserClassTypeInfo() {
|
||||
|
||||
ClassTypeInformation<Leaf> typeInfoLeaf = from(Leaf.class);
|
||||
ClassTypeInformation<Leaf$$SpringProxy$873fa2e> typeInformationLeafProxy = from(Leaf$$SpringProxy$873fa2e.class);
|
||||
var typeInfoLeaf = TypeInformation.of(Leaf.class);
|
||||
var typeInformationLeafProxy = TypeInformation
|
||||
.of(Leaf$$SpringProxy$873fa2e.class);
|
||||
|
||||
assertThat(typeInfoLeaf).isNotEqualTo(typeInformationLeafProxy);
|
||||
}
|
||||
|
||||
@Test // GH-2312
|
||||
@Test // GH-2312
|
||||
void typeInfoShouldPreserveGenericParameter() {
|
||||
|
||||
TypeInformation<Wrapper> wrapperTypeInfo = ClassTypeInformation.from(Wrapper.class);
|
||||
TypeInformation<?> fieldTypeInfo = wrapperTypeInfo.getProperty("field");
|
||||
TypeInformation<?> valueTypeInfo = fieldTypeInfo.getProperty("value");
|
||||
var wrapperTypeInfo = TypeInformation.of(Wrapper.class);
|
||||
var fieldTypeInfo = wrapperTypeInfo.getProperty("field");
|
||||
var valueTypeInfo = fieldTypeInfo.getProperty("value");
|
||||
|
||||
assertThat(valueTypeInfo.getType()).isEqualTo(Leaf.class);
|
||||
}
|
||||
@@ -706,7 +716,7 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
static class SomeConcrete extends SomeGeneric<String> {}
|
||||
|
||||
static class GenericExtendingSomeGeneric<T> extends SomeGeneric<T> { }
|
||||
static class GenericExtendingSomeGeneric<T> extends SomeGeneric<T> {}
|
||||
|
||||
static class Wrapper {
|
||||
GenericExtendingSomeGeneric<Leaf> field;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DataCmns511Tests {
|
||||
@Test // DATACMNS-511
|
||||
public void detectsEqualTypeVariableTypeInformationInstances() {
|
||||
|
||||
var createdBy = ClassTypeInformation.from(AbstractRole.class).getProperty("createdBy");
|
||||
var createdBy = TypeInformation.of(AbstractRole.class).getProperty("createdBy");
|
||||
|
||||
assertThat(createdBy.getProperty("roles").getActualType().getProperty("createdBy"))//
|
||||
.satisfies(second -> {
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
package org.springframework.data.util;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -31,8 +28,8 @@ import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -45,11 +42,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TypeDiscovererUnitTests {
|
||||
|
||||
private static final Map<TypeVariable<?>, Type> EMPTY_MAP = Collections.emptyMap();
|
||||
|
||||
@Mock Map<TypeVariable<?>, Type> firstMap;
|
||||
@Mock Map<TypeVariable<?>, Type> secondMap;
|
||||
|
||||
@Test
|
||||
void rejectsNullType() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new TypeDiscoverer<>((ResolvableType) null));
|
||||
@@ -58,27 +50,17 @@ public class TypeDiscovererUnitTests {
|
||||
@Test
|
||||
void isNotEqualIfTypesDiffer() {
|
||||
|
||||
var objectTypeInfo = new TypeDiscoverer<Object>(Object.class);
|
||||
var stringTypeInfo = new TypeDiscoverer<String>(String.class);
|
||||
var objectTypeInfo = TypeInformation.of(Object.class);
|
||||
var stringTypeInfo = TypeInformation.of(String.class);
|
||||
|
||||
assertThat(objectTypeInfo.equals(stringTypeInfo)).isFalse();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// void isNotEqualIfTypeVariableMapsDiffer() {
|
||||
//
|
||||
// assertThat(firstMap.equals(secondMap)).isFalse();
|
||||
//
|
||||
// var first = new TypeDiscoverer<Object>(Object.class);
|
||||
// var second = new TypeDiscoverer<Object>(Object.class);
|
||||
//
|
||||
// assertThat(first.equals(second)).isFalse();
|
||||
// }
|
||||
|
||||
@Test
|
||||
void dealsWithTypesReferencingThemselves() {
|
||||
|
||||
TypeInformation<SelfReferencing> information = from(SelfReferencing.class);
|
||||
var information = TypeInformation.of(SelfReferencing.class);
|
||||
|
||||
var first = information.getProperty("parent").getMapValueType();
|
||||
var second = first.getProperty("map").getMapValueType();
|
||||
|
||||
@@ -88,7 +70,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test
|
||||
void dealsWithTypesReferencingThemselvesInAMap() {
|
||||
|
||||
TypeInformation<SelfReferencingMap> information = from(SelfReferencingMap.class);
|
||||
var information = TypeInformation.of(SelfReferencingMap.class);
|
||||
var property = information.getProperty("map");
|
||||
|
||||
assertThat(property.getMapValueType()).isEqualTo(information);
|
||||
@@ -97,7 +79,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test
|
||||
void returnsComponentAndValueTypesForMapExtensions() {
|
||||
|
||||
TypeInformation<?> discoverer = new TypeDiscoverer<>(CustomMap.class);
|
||||
TypeInformation<?> discoverer = TypeInformation.of(CustomMap.class);
|
||||
|
||||
assertThat(discoverer.getMapValueType().getType()).isEqualTo(Locale.class);
|
||||
assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class);
|
||||
@@ -106,7 +88,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test
|
||||
void returnsComponentTypeForCollectionExtension() {
|
||||
|
||||
var discoverer = new TypeDiscoverer<CustomCollection>(CustomCollection.class);
|
||||
var discoverer = TypeInformation.of(CustomCollection.class);
|
||||
|
||||
assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class);
|
||||
}
|
||||
@@ -114,7 +96,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test
|
||||
void returnsComponentTypeForArrays() {
|
||||
|
||||
var discoverer = new TypeDiscoverer<String[]>(String[].class);
|
||||
var discoverer = TypeInformation.of(String[].class);
|
||||
|
||||
assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class);
|
||||
}
|
||||
@@ -122,7 +104,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test // DATACMNS-57
|
||||
void discoveresConstructorParameterTypesCorrectly() throws NoSuchMethodException, SecurityException {
|
||||
|
||||
var discoverer = new TypeDiscoverer<GenericConstructors>(GenericConstructors.class);
|
||||
var discoverer = TypeInformation.of(GenericConstructors.class);
|
||||
var constructor = GenericConstructors.class.getConstructor(List.class, Locale.class);
|
||||
var types = discoverer.getParameterTypes(constructor);
|
||||
|
||||
@@ -135,7 +117,7 @@ public class TypeDiscovererUnitTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void returnsNullForComponentAndValueTypesForRawMaps() {
|
||||
|
||||
var discoverer = new TypeDiscoverer<Map>(Map.class);
|
||||
var discoverer = TypeInformation.of(Map.class);
|
||||
|
||||
assertThat(discoverer.getComponentType()).isNotNull();
|
||||
assertThat(discoverer.getMapValueType()).isNotNull();
|
||||
@@ -145,8 +127,8 @@ public class TypeDiscovererUnitTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void doesNotConsiderTypeImplementingIterableACollection() {
|
||||
|
||||
var discoverer = new TypeDiscoverer<Person>(Person.class);
|
||||
TypeInformation reference = from(Address.class);
|
||||
var discoverer = TypeInformation.of(Person.class);
|
||||
TypeInformation reference = TypeInformation.of(Address.class);
|
||||
|
||||
var addresses = discoverer.getProperty("addresses");
|
||||
|
||||
@@ -166,7 +148,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test // DATACMNS-1342, DATACMNS-1430
|
||||
void considersStreamableToBeCollectionLike() {
|
||||
|
||||
TypeInformation<SomeStreamable> type = from(SomeStreamable.class);
|
||||
TypeInformation<SomeStreamable> type = TypeInformation.of(SomeStreamable.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
assertThat(type.getRequiredProperty("streamable").isCollectionLike()).isTrue();
|
||||
@@ -175,7 +157,7 @@ public class TypeDiscovererUnitTests {
|
||||
@Test // DATACMNS-1419
|
||||
void detectsSubTypes() {
|
||||
|
||||
var type = from(Set.class);
|
||||
var type = TypeInformation.of(Set.class);
|
||||
|
||||
assertThat(type.isSubTypeOf(Collection.class)).isTrue();
|
||||
assertThat(type.isSubTypeOf(Set.class)).isFalse();
|
||||
@@ -196,124 +178,115 @@ public class TypeDiscovererUnitTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldNoGenericsInfoShouldBeEqual() {
|
||||
|
||||
Field addresses = ReflectionUtils.findField(Person.class, "addresses");
|
||||
var addresses = ReflectionUtils.findField(Person.class, "addresses");
|
||||
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class));
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class));
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses, Person.class));
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses, Person.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldNoGenericsWhenInherited() {
|
||||
|
||||
Field addresses = ReflectionUtils.findField(Person.class, "addresses");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class));
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses, TypeExtendingPerson.class));
|
||||
var addresses = ReflectionUtils.findField(Person.class, "addresses");
|
||||
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses, Person.class));
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses, TypeExtendingPerson.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldNoGenericsOnDifferentTypes() {
|
||||
|
||||
Field addresses1 = ReflectionUtils.findField(Person.class, "addresses");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses1, Person.class));
|
||||
var addresses1 = ReflectionUtils.findField(Person.class, "addresses");
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses1, Person.class));
|
||||
|
||||
Field addresses2 = ReflectionUtils.findField(OtherPerson.class, "addresses");
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses2, OtherPerson.class));
|
||||
var addresses2 = ReflectionUtils.findField(OtherPerson.class, "addresses");
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses2, OtherPerson.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldWithGenerics() {
|
||||
|
||||
Field field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, GenericPerson.class));
|
||||
var field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, GenericPerson.class));
|
||||
|
||||
Field field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, GenericPerson.class));
|
||||
var field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, GenericPerson.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldWithGenericsSet() {
|
||||
|
||||
Field field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class));
|
||||
var field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class));
|
||||
|
||||
Field field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class));
|
||||
var field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldWithDifferentGenericsSet() {
|
||||
|
||||
Field field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class));
|
||||
var field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class));
|
||||
|
||||
Field field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithAddress.class));
|
||||
var field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithAddress.class));
|
||||
|
||||
assertThat(discoverer1).isNotEqualTo(discoverer2);
|
||||
assertThat(discoverer1.hashCode()).isNotEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void sameFieldWithDifferentNoGenericsAndObjectOneSet() {
|
||||
|
||||
Field field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, GenericPerson.class));
|
||||
var field1 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, GenericPerson.class));
|
||||
|
||||
Field field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class));
|
||||
var field2 = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class));
|
||||
|
||||
assertThat(discoverer1).isEqualTo(discoverer2); // TODO: notEquals
|
||||
assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
// GH-2312
|
||||
@Test // GH-2312
|
||||
void genericFieldOfType() {
|
||||
|
||||
Field field = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
TypeDiscoverer<Object> discoverer = new TypeDiscoverer<>(ResolvableType.forField(field, TypeExtendingGenericPersonWithAddress.class));
|
||||
var field = ReflectionUtils.findField(GenericPerson.class, "value");
|
||||
var discoverer = TypeInformation.of(ResolvableType.forField(field, TypeExtendingGenericPersonWithAddress.class));
|
||||
|
||||
assertThat(discoverer).isEqualTo(ClassTypeInformation.from(Address.class));
|
||||
assertThat(discoverer.hashCode()).isEqualTo(ClassTypeInformation.from(Address.class).hashCode());
|
||||
assertThat(discoverer).isEqualTo(TypeInformation.of(Address.class));
|
||||
assertThat(discoverer.hashCode()).isEqualTo(TypeInformation.of(Address.class).hashCode());
|
||||
}
|
||||
|
||||
@Test // #2511
|
||||
void considerVavrMapToBeAMap() {
|
||||
|
||||
var type = from(io.vavr.collection.Map.class);
|
||||
|
||||
assertThat(type.isMap()).isTrue();
|
||||
assertThat(TypeInformation.of(io.vavr.collection.Map.class).isMap()).isTrue();
|
||||
}
|
||||
|
||||
@Test // #2517
|
||||
void returnsComponentAndValueTypesForVavrMapExtensions() {
|
||||
|
||||
var discoverer = new TypeDiscoverer<>(CustomVavrMap.class);
|
||||
var discoverer = TypeInformation.of(CustomVavrMap.class);
|
||||
|
||||
assertThat(discoverer.getMapValueType().getType()).isEqualTo(Locale.class);
|
||||
assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class);
|
||||
@@ -321,26 +294,36 @@ public class TypeDiscovererUnitTests {
|
||||
|
||||
@Test // #2511
|
||||
void considerVavrSetToBeCollectionLike() {
|
||||
|
||||
var type = from(io.vavr.collection.Set.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
assertThat(TypeInformation.of(io.vavr.collection.Set.class).isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test // #2511
|
||||
void considerVavrSeqToBeCollectionLike() {
|
||||
|
||||
var type = from(io.vavr.collection.Seq.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
assertThat(TypeInformation.of(io.vavr.collection.Seq.class).isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test // #2511
|
||||
void considerVavrListToBeCollectionLike() {
|
||||
assertThat(TypeInformation.of(io.vavr.collection.List.class).isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
var type = from(io.vavr.collection.List.class);
|
||||
@Test
|
||||
void typeInfoShouldPreserveGenericParameter() {
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
TypeInformation<Wrapper> wrapperTypeInfo = TypeInformation.of(Wrapper.class);
|
||||
TypeInformation<?> fieldTypeInfo = wrapperTypeInfo.getProperty("field");
|
||||
TypeInformation<?> valueTypeInfo = fieldTypeInfo.getProperty("value");
|
||||
|
||||
assertThat(valueTypeInfo.getType()).isEqualTo(Leaf.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsMapKeyAndValueOnEnumMaps() {
|
||||
|
||||
TypeInformation<?> map = TypeInformation.of(EnumMapWrapper.class).getProperty("map");
|
||||
|
||||
assertThat(map.getComponentType().getType()).isEqualTo(Autowire.class);
|
||||
assertThat(map.getMapValueType().getType()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
class Person {
|
||||
@@ -369,7 +352,6 @@ public class TypeDiscovererUnitTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract class Addresses implements Iterable<Address> {
|
||||
|
||||
}
|
||||
@@ -415,4 +397,22 @@ public class TypeDiscovererUnitTests {
|
||||
}
|
||||
|
||||
interface CustomVavrMap extends io.vavr.collection.Map<String, Locale> {}
|
||||
|
||||
// #2312
|
||||
|
||||
class SomeGeneric<T> {
|
||||
T value;
|
||||
}
|
||||
|
||||
class GenericExtendingSomeGeneric<T> extends SomeGeneric<T> {}
|
||||
|
||||
class Wrapper {
|
||||
GenericExtendingSomeGeneric<Leaf> field;
|
||||
}
|
||||
|
||||
class Leaf {}
|
||||
|
||||
class EnumMapWrapper {
|
||||
EnumMap<Autowire, String> map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.web.querydsl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver.*;
|
||||
import static org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolverSupport.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -26,7 +26,6 @@ import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
|
||||
import org.springframework.data.querydsl.binding.QuerydslBindings;
|
||||
import org.springframework.data.querydsl.binding.QuerydslBindingsFactory;
|
||||
import org.springframework.data.querydsl.binding.QuerydslPredicate;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -210,15 +208,15 @@ class QuerydslPredicateArgumentResolverUnitTests {
|
||||
TypeInformation<?> type = ReflectionTestUtils.invokeMethod(resolver, "extractTypeInfo",
|
||||
getMethodParameterFor("predicateWithoutAnnotation", Predicate.class), MergedAnnotation.missing());
|
||||
|
||||
assertThat(type).isEqualTo(ClassTypeInformation.from(User.class));
|
||||
assertThat(type).isEqualTo(TypeInformation.of(User.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings("rawtypes")
|
||||
void detectsDomainTypesCorrectly() {
|
||||
|
||||
TypeInformation USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
TypeInformation MODELA_AND_VIEW_TYPE = ClassTypeInformation.from(ModelAndView.class);
|
||||
TypeInformation USER_TYPE = TypeInformation.of(User.class);
|
||||
TypeInformation MODELA_AND_VIEW_TYPE = TypeInformation.of(ModelAndView.class);
|
||||
|
||||
assertThat(extractTypeInfo(getMethodParameterFor("forEntity"), MergedAnnotation.missing())).isEqualTo(USER_TYPE);
|
||||
assertThat(extractTypeInfo(getMethodParameterFor("forResourceOfUser"), MergedAnnotation.missing()))
|
||||
|
||||
Reference in New Issue
Block a user