DATACMNS-809 - Polishing.

Removed DefaultPersistentPropertyAccessorFactory as it only delegates to the class generating one. Tweaked AbstractMappingContext to actually use the latter in the first place. Introduced BeanWrapperPropertyAccessorFactory to implement the default behavior of using a BeanWrapper and initialize BasicPersistentEntity to avoid a null clause in getPersistentPropertyAccessor(…).

Removed getPersistentPropertyAccessorFactory and rather rely on ReflectionTestUtils in tests to avoid additional API being exposed.

Original pull request: #159.
This commit is contained in:
Oliver Gierke
2016-05-03 16:44:38 +02:00
parent defc3c7874
commit 38a41139fc
7 changed files with 41 additions and 46 deletions

View File

@@ -15,7 +15,8 @@
*/
package org.springframework.data.mapping.model;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
@@ -35,6 +36,7 @@ import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.context.SampleMappingContext;
import org.springframework.data.mapping.context.SamplePersistentProperty;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory}
@@ -140,7 +142,8 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getPersistentEntity(bean.getClass());
assertThat(persistentEntity.getPropertyAccessorFactory(), is(instanceOf(DefaultPersistentPropertyAccessorFactory.class)));
assertThat(ReflectionTestUtils.getField(persistentEntity, "propertyAccessorFactory"),
is(instanceOf(ClassGeneratingPropertyAccessorFactory.class)));
}
private PersistentPropertyAccessor getPersistentPropertyAccessor(Object bean) {

View File

@@ -16,7 +16,8 @@
package org.springframework.data.mapping.model;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
@@ -36,6 +37,7 @@ import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.context.SampleMappingContext;
import org.springframework.data.mapping.context.SamplePersistentProperty;
import org.springframework.data.mapping.model.subpackage.TypeInOtherPackage;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory}
@@ -165,7 +167,8 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getPersistentEntity(bean.getClass());
assertThat(persistentEntity.getPropertyAccessorFactory(), is(instanceOf(DefaultPersistentPropertyAccessorFactory.class)));
assertThat(ReflectionTestUtils.getField(persistentEntity, "propertyAccessorFactory"),
is(instanceOf(ClassGeneratingPropertyAccessorFactory.class)));
}
private PersistentPropertyAccessor getPersistentPropertyAccessor(Object bean) {