Improve ClassGeneratingEntityInstantiator error message if the to be instantiated type is abstract.
We now throw MappingInstantiationException with a nested BeanInstantiationException in alignment to ReflectionEntityInstantiator when attempting to create a new instance of an abstract class. Closes #2348.
This commit is contained in:
@@ -39,6 +39,7 @@ import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
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.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -374,6 +375,13 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
assertThat(this.instance.shouldUseReflectionEntityInstantiator(entity)).isTrue();
|
||||
}
|
||||
|
||||
@Test // GH-2348
|
||||
void entityInstantiatorShouldFailForAbstractClass() {
|
||||
|
||||
assertThatExceptionOfType(MappingInstantiationException.class).isThrownBy(() -> this.instance
|
||||
.createInstance(new BasicPersistentEntity<>(ClassTypeInformation.from(AbstractDto.class)), provider));
|
||||
}
|
||||
|
||||
private void prepareMocks(Class<?> type) {
|
||||
|
||||
doReturn(type).when(entity).getType();
|
||||
@@ -519,4 +527,8 @@ class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProperty<P>
|
||||
ClassWithPackagePrivateConstructor() {}
|
||||
}
|
||||
|
||||
public static abstract class AbstractDto {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user