|
|
|
@ -35,10 +35,10 @@ import org.springframework.data.util.ClassTypeInformation; |
|
|
|
* @author Mark Paluch |
|
|
|
* @author Mark Paluch |
|
|
|
* @author Christoph Strobl |
|
|
|
* @author Christoph Strobl |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> { |
|
|
|
class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> { |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
public void findsNoArgConstructorForClassWithoutExplicitConstructor() { |
|
|
|
void findsNoArgConstructorForClassWithoutExplicitConstructor() { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(EntityWithoutConstructor.class)).satisfies(constructor -> { |
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(EntityWithoutConstructor.class)).satisfies(constructor -> { |
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +49,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
public void findsNoArgConstructorForClassWithMultipleConstructorsAndNoArgOne() { |
|
|
|
void findsNoArgConstructorForClassWithMultipleConstructorsAndNoArgOne() { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithEmptyConstructor.class)).satisfies(constructor -> { |
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithEmptyConstructor.class)).satisfies(constructor -> { |
|
|
|
|
|
|
|
|
|
|
|
@ -60,15 +60,14 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
public void doesNotThrowExceptionForMultipleConstructorsAndNoNoArgConstructorWithoutAnnotation() { |
|
|
|
void doesNotThrowExceptionForMultipleConstructorsAndNoNoArgConstructorWithoutAnnotation() { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithMultipleConstructorsWithoutEmptyOne.class)).isNull(); |
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithMultipleConstructorsWithoutEmptyOne.class)).isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
@Test // DATACMNS-1126
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
public void usesConstructorWithAnnotationOverEveryOther() { |
|
|
|
void usesConstructorWithAnnotationOverEveryOther() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithMultipleConstructorsAndAnnotation.class)) |
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(ClassWithMultipleConstructorsAndAnnotation.class)) |
|
|
|
.satisfies(constructor -> { |
|
|
|
.satisfies(constructor -> { |
|
|
|
@ -88,7 +87,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-134, DATACMNS-1126
|
|
|
|
@Test // DATACMNS-134, DATACMNS-1126
|
|
|
|
public void discoversInnerClassConstructorCorrectly() { |
|
|
|
void discoversInnerClassConstructorCorrectly() { |
|
|
|
|
|
|
|
|
|
|
|
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class)); |
|
|
|
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class)); |
|
|
|
|
|
|
|
|
|
|
|
@ -100,7 +99,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATACMNS-1082, DATACMNS-1126
|
|
|
|
@Test // DATACMNS-1082, DATACMNS-1126
|
|
|
|
public void skipsSyntheticConstructor() { |
|
|
|
void skipsSyntheticConstructor() { |
|
|
|
|
|
|
|
|
|
|
|
PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<>( |
|
|
|
PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<>( |
|
|
|
ClassTypeInformation.from(SyntheticConstructor.class)); |
|
|
|
ClassTypeInformation.from(SyntheticConstructor.class)); |
|
|
|
@ -116,8 +115,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
@Test // GH-2313
|
|
|
|
@Test // GH-2313
|
|
|
|
void capturesEnclosingTypeParameterOfNonStaticInnerClass() { |
|
|
|
void capturesEnclosingTypeParameterOfNonStaticInnerClass() { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(NonStaticWithGenericTypeArgUsedInCtor.class)) |
|
|
|
assertThat(PreferredConstructorDiscoverer.discover(NonStaticWithGenericTypeArgUsedInCtor.class)).satisfies(ctor -> { |
|
|
|
.satisfies(ctor -> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(ctor.getParameters()).hasSize(2); |
|
|
|
assertThat(ctor.getParameters()).hasSize(2); |
|
|
|
assertThat(ctor.getParameters().get(0).getName()).isEqualTo("this$0"); |
|
|
|
assertThat(ctor.getParameters().get(0).getName()).isEqualTo("this$0"); |
|
|
|
@ -150,7 +148,7 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class EntityWithoutConstructor { |
|
|
|
private static class EntityWithoutConstructor { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -192,10 +190,9 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert |
|
|
|
|
|
|
|
|
|
|
|
static class GenericTypeArgUsedInCtor<T> { |
|
|
|
static class GenericTypeArgUsedInCtor<T> { |
|
|
|
|
|
|
|
|
|
|
|
protected GenericTypeArgUsedInCtor(T value) {} |
|
|
|
GenericTypeArgUsedInCtor(T value) {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NonStaticWithGenericTypeArgUsedInCtor<T> { |
|
|
|
class NonStaticWithGenericTypeArgUsedInCtor<T> { |
|
|
|
|
|
|
|
|
|
|
|
protected NonStaticWithGenericTypeArgUsedInCtor(T value) {} |
|
|
|
protected NonStaticWithGenericTypeArgUsedInCtor(T value) {} |
|
|
|
|