use of org.springframework.data.mapping.model.BasicPersistentEntity in project spring-data-commons by spring-projects.
the class ReflectionEntityInstantiatorUnitTests method createsInnerClassInstanceCorrectly.
// DATACMNS-134
@Test
public void createsInnerClassInstanceCorrectly() {
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
assertThat(entity.getPersistenceConstructor()).satisfies(it -> {
Parameter<Object, P> parameter = it.getParameters().iterator().next();
Object outer = new Outer();
when(provider.getParameterValue(parameter)).thenReturn(outer);
Inner instance = INSTANCE.createInstance(entity, provider);
assertThat(instance).isNotNull();
// Hack to check synthetic field as compiles create different field names (e.g. this$0, this$1)
ReflectionUtils.doWithFields(Inner.class, field -> {
if (field.isSynthetic() && field.getName().startsWith("this$")) {
ReflectionUtils.makeAccessible(field);
assertThat(ReflectionUtils.getField(field, instance)).isEqualTo(outer);
}
});
});
}
Aggregations