use of org.springframework.data.mapping.model.MappingInstantiationException in project spring-data-commons by spring-projects.
the class ClassGeneratingEntityInstantiatorUnitTests method capturesContextOnInstantiationException.
// DATACMNS-283, DATACMNS-578
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void capturesContextOnInstantiationException() throws Exception {
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
doReturn("FOO").when(provider).getParameterValue(any(Parameter.class));
Constructor constructor = Sample.class.getConstructor(Long.class, String.class);
List<Object> parameters = Arrays.asList("FOO", "FOO");
try {
this.instance.createInstance(entity, provider);
fail("Expected MappingInstantiationException!");
} catch (MappingInstantiationException o_O) {
assertThat(o_O.getConstructor()).hasValue(constructor);
assertThat(o_O.getConstructorArguments()).isEqualTo(parameters);
assertThat(o_O.getEntityType()).hasValue(Sample.class);
assertThat(o_O.getMessage()).contains(Sample.class.getName());
assertThat(o_O.getMessage()).contains(Long.class.getName());
assertThat(o_O.getMessage()).contains(String.class.getName());
assertThat(o_O.getMessage()).contains("FOO");
}
}
use of org.springframework.data.mapping.model.MappingInstantiationException in project spring-data-commons by spring-projects.
the class ReflectionEntityInstantiatorUnitTests method capturesContextOnInstantiationException.
// DATACMNS-283
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void capturesContextOnInstantiationException() throws Exception {
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
doReturn("FOO").when(provider).getParameterValue(any(Parameter.class));
Constructor constructor = Sample.class.getConstructor(Long.class, String.class);
List<Object> parameters = Arrays.asList("FOO", "FOO");
try {
INSTANCE.createInstance(entity, provider);
fail("Expected MappingInstantiationException!");
} catch (MappingInstantiationException o_O) {
assertThat(o_O.getConstructor()).hasValue(constructor);
assertThat(o_O.getConstructorArguments()).isEqualTo(parameters);
assertThat(o_O.getEntityType()).hasValue(Sample.class);
assertThat(o_O.getMessage()).contains(Sample.class.getName());
assertThat(o_O.getMessage()).contains(Long.class.getName());
assertThat(o_O.getMessage()).contains(String.class.getName());
assertThat(o_O.getMessage()).contains("FOO");
}
}
Aggregations