diff --git a/pom.xml b/pom.xml
index 8837278a..ff00808a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
io.beanmapper
beanmapper
- 3.0.1
+ 3.0.2-SNAPSHOT
jar
42 Bean Mapper
Easy-to-use bean mapper for conversion from form to object to view
diff --git a/src/main/java/io/beanmapper/config/BeanMapperBuilder.java b/src/main/java/io/beanmapper/config/BeanMapperBuilder.java
index 1bd96a3a..823f7828 100644
--- a/src/main/java/io/beanmapper/config/BeanMapperBuilder.java
+++ b/src/main/java/io/beanmapper/config/BeanMapperBuilder.java
@@ -6,6 +6,8 @@
import io.beanmapper.BeanMapper;
import io.beanmapper.annotations.BeanCollectionUsage;
import io.beanmapper.annotations.LogicSecuredCheck;
+import io.beanmapper.core.BeanMatchStore;
+import io.beanmapper.core.BeanMatchStoreFactory;
import io.beanmapper.core.collections.CollectionHandler;
import io.beanmapper.core.collections.ListCollectionHandler;
import io.beanmapper.core.collections.MapCollectionHandler;
@@ -39,7 +41,11 @@ public class BeanMapperBuilder {
private List customCollectionHandlers = new ArrayList<>();
public BeanMapperBuilder() {
- this.configuration = new CoreConfiguration();
+ this(BeanMatchStore::new);
+ }
+
+ public BeanMapperBuilder(BeanMatchStoreFactory beanMatchStoreFactory) {
+ this.configuration = new CoreConfiguration(beanMatchStoreFactory);
}
public BeanMapperBuilder(Configuration configuration) {
diff --git a/src/main/java/io/beanmapper/config/CoreConfiguration.java b/src/main/java/io/beanmapper/config/CoreConfiguration.java
index 0ff1fbd5..f4ff2e0c 100644
--- a/src/main/java/io/beanmapper/config/CoreConfiguration.java
+++ b/src/main/java/io/beanmapper/config/CoreConfiguration.java
@@ -8,6 +8,7 @@
import io.beanmapper.annotations.BeanCollectionUsage;
import io.beanmapper.annotations.LogicSecuredCheck;
import io.beanmapper.core.BeanMatchStore;
+import io.beanmapper.core.BeanMatchStoreFactory;
import io.beanmapper.core.collections.CollectionHandler;
import io.beanmapper.core.constructor.BeanInitializer;
import io.beanmapper.core.constructor.DefaultBeanInitializer;
@@ -19,7 +20,6 @@
import io.beanmapper.exceptions.BeanConfigurationOperationNotAllowedException;
public class CoreConfiguration implements Configuration {
-
/**
* Initializes the beans.
*/
@@ -40,13 +40,13 @@ public class CoreConfiguration implements Configuration {
* Contains a store of matches for source and target class pairs. A pair is created only
* once and reused every time thereafter.
*/
- private BeanMatchStore beanMatchStore = new BeanMatchStore(collectionHandlerStore, beanUnproxy);
+ private final BeanMatchStore beanMatchStore;
/**
* Contains a store of classes that are generated by using the MapToDynamicClassStrategy.
* Every generated class is a downsized source class or a downsized target class.
*/
- private ClassStore classStore = new ClassStore();
+ private final ClassStore classStore;
/**
* The list of packages (and subpackages) containing classes which are eligible for mapping.
@@ -99,6 +99,11 @@ public class CoreConfiguration implements Configuration {
*/
private Boolean useNullValue = false;
+ public CoreConfiguration(BeanMatchStoreFactory beanMatchStoreFactory) {
+ this.beanMatchStore = beanMatchStoreFactory.create(collectionHandlerStore, beanUnproxy);
+ this.classStore = new ClassStore(beanMatchStoreFactory);
+ }
+
@Override
public List getDownsizeTarget() { return null; }
diff --git a/src/main/java/io/beanmapper/core/BeanMatchStore.java b/src/main/java/io/beanmapper/core/BeanMatchStore.java
index 8e6ae908..56fdbae5 100644
--- a/src/main/java/io/beanmapper/core/BeanMatchStore.java
+++ b/src/main/java/io/beanmapper/core/BeanMatchStore.java
@@ -35,11 +35,18 @@ public class BeanMatchStore {
private final BeanUnproxy beanUnproxy;
+ private final PropertyAccessors propertyAccessors;
+
private Map> store = new TreeMap>();
public BeanMatchStore(CollectionHandlerStore collectionHandlerStore, BeanUnproxy beanUnproxy) {
this.collectionHandlerStore = collectionHandlerStore;
this.beanUnproxy = beanUnproxy;
+ this.propertyAccessors = createPropertyAccessors();
+ }
+
+ protected PropertyAccessors createPropertyAccessors() {
+ return new PropertyAccessors();
}
public void validateStrictBeanPairs(List beanPairs) {
@@ -122,7 +129,7 @@ private BeanMatch determineBeanMatch(BeanPair beanPair,
private Map getAllFields(Map ourNodes, Map otherNodes, Map aliases, Class> ourType, Class> otherType, BeanProperty precedingBeanProperty, BeanPropertyMatchupDirection matchupDirection) {
Map ourCurrentNodes = ourNodes;
- List accessors = PropertyAccessors.getAll(ourType);
+ List accessors = propertyAccessors.getAll(ourType);
for (PropertyAccessor accessor : accessors) {
BeanPropertyAccessType accessType = matchupDirection.accessType(accessor);
@@ -144,7 +151,7 @@ private Map getAllFields(Map ourNode
BeanProperty currentBeanProperty = null;
try {
currentBeanProperty = new BeanPropertyCreator(
- matchupDirection, ourType, accessor.getName()).determineNodesForPath(precedingBeanProperty);
+ matchupDirection, ourType, propertyAccessors, accessor.getName()).determineNodesForPath(precedingBeanProperty);
currentBeanProperty.setMustMatch(beanPropertyWrapper.isMustMatch());
} catch (BeanNoSuchPropertyException e) {
throw new BeanMissingPathException(ourType, accessor.getName(), e);
@@ -187,6 +194,8 @@ private Map getAllFields(Map ourNode
return ourCurrentNodes;
}
+
+
private void handleBeanLogicSecuredAnnotation(BeanProperty beanProperty, BeanLogicSecured beanLogicSecured) {
if (beanLogicSecured == null) {
return;
@@ -265,7 +274,7 @@ private BeanPropertyWrapper dealWithBeanProperty(
try {
otherNodes.put(
wrapper.getName(),
- new BeanPropertyCreator(matchupDirection.getInverse(), otherType, wrapper.getName())
+ new BeanPropertyCreator(matchupDirection.getInverse(), otherType, propertyAccessors, wrapper.getName())
.determineNodesForPath());
} catch (BeanNoSuchPropertyException err) {
// Acceptable, might have been tagged as @BeanProperty as well
diff --git a/src/main/java/io/beanmapper/core/BeanMatchStoreFactory.java b/src/main/java/io/beanmapper/core/BeanMatchStoreFactory.java
new file mode 100644
index 00000000..32f27b59
--- /dev/null
+++ b/src/main/java/io/beanmapper/core/BeanMatchStoreFactory.java
@@ -0,0 +1,8 @@
+package io.beanmapper.core;
+
+import io.beanmapper.config.CollectionHandlerStore;
+import io.beanmapper.core.unproxy.BeanUnproxy;
+
+public interface BeanMatchStoreFactory {
+ BeanMatchStore create(CollectionHandlerStore collectionHandlerStore, BeanUnproxy beanUnproxy);
+}
diff --git a/src/main/java/io/beanmapper/core/BeanPropertyCreator.java b/src/main/java/io/beanmapper/core/BeanPropertyCreator.java
index 8229a9b3..bec4ce06 100644
--- a/src/main/java/io/beanmapper/core/BeanPropertyCreator.java
+++ b/src/main/java/io/beanmapper/core/BeanPropertyCreator.java
@@ -14,9 +14,12 @@ public class BeanPropertyCreator {
private final Route route;
- public BeanPropertyCreator(BeanPropertyMatchupDirection matchupDirection, Class> baseClass, String path) {
+ private final PropertyAccessors propertyAccessors;
+
+ public BeanPropertyCreator(BeanPropertyMatchupDirection matchupDirection, Class> baseClass, PropertyAccessors propertyAccessors, String path) {
this.matchupDirection = matchupDirection;
this.baseClass = baseClass;
+ this.propertyAccessors = propertyAccessors;
this.route = new Route(path);
}
@@ -66,7 +69,7 @@ private BeanProperty getFirstBeanProperty(Stack beanProperties) {
private void traversePath(Stack beanProperties) {
Class> currentBaseClass = baseClass;
for (String node : route.getRoute()) {
- final PropertyAccessor property = PropertyAccessors.findProperty(currentBaseClass, node);
+ final PropertyAccessor property = propertyAccessors.findProperty(currentBaseClass, node);
if (property == null) {
throw new BeanNoSuchPropertyException("Property '" + node + "' does not exist in: " + currentBaseClass.getSimpleName());
}
diff --git a/src/main/java/io/beanmapper/core/inspector/PropertyAccessors.java b/src/main/java/io/beanmapper/core/inspector/PropertyAccessors.java
index 947c77c4..d0601328 100644
--- a/src/main/java/io/beanmapper/core/inspector/PropertyAccessors.java
+++ b/src/main/java/io/beanmapper/core/inspector/PropertyAccessors.java
@@ -30,7 +30,7 @@ public class PropertyAccessors {
* @param beanClass the bean class
* @return the property accessors of that bean
*/
- public static List getAll(Class> beanClass) {
+ public List getAll(Class> beanClass) {
Map descriptors = findPropertyDescriptors(beanClass);
Map fields = findAllFields(beanClass);
@@ -47,11 +47,11 @@ public static List getAll(Class> beanClass) {
return accessors;
}
- private static Map findPropertyDescriptors(Class> clazz) {
+ private Map findPropertyDescriptors(Class> clazz) {
try {
- BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
Map result = new HashMap();
- for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
+ PropertyDescriptor[] propertyDescriptors = extractPropertyDescriptors(clazz);
+ for (PropertyDescriptor descriptor : propertyDescriptors) {
result.put(descriptor.getName(), descriptor);
}
result.remove(CLASS_PROPERTY);
@@ -64,7 +64,12 @@ private static Map findPropertyDescriptors(Class>
}
}
- private static void addParentInterfaceProperties(Class> clazz, Map result) {
+ protected PropertyDescriptor[] extractPropertyDescriptors(Class> clazz) throws IntrospectionException {
+ BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+ return beanInfo.getPropertyDescriptors();
+ }
+
+ private void addParentInterfaceProperties(Class> clazz, Map result) {
for (Class> parent : clazz.getInterfaces()) {
result.putAll(findPropertyDescriptors(parent));
}
@@ -87,7 +92,7 @@ private static Map findAllFields(Class> clazz) {
* @param propertyName the property name
* @return the accessor that can manage the property
*/
- public static PropertyAccessor findProperty(Class> beanClass, String propertyName) {
+ public PropertyAccessor findProperty(Class> beanClass, String propertyName) {
PropertyAccessor result = null;
PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, propertyName);
Field field = findField(beanClass, propertyName);
@@ -97,7 +102,7 @@ public static PropertyAccessor findProperty(Class> beanClass, String propertyN
return result;
}
- private static PropertyDescriptor findPropertyDescriptor(Class> beanClass, String propertyName) {
+ private PropertyDescriptor findPropertyDescriptor(Class> beanClass, String propertyName) {
Map descriptors = findPropertyDescriptors(beanClass);
return descriptors.get(propertyName);
}
diff --git a/src/main/java/io/beanmapper/dynclass/ClassGenerator.java b/src/main/java/io/beanmapper/dynclass/ClassGenerator.java
index e3df0278..a3c2b27d 100644
--- a/src/main/java/io/beanmapper/dynclass/ClassGenerator.java
+++ b/src/main/java/io/beanmapper/dynclass/ClassGenerator.java
@@ -5,6 +5,7 @@
import io.beanmapper.annotations.BeanCollection;
import io.beanmapper.config.StrictMappingProperties;
import io.beanmapper.core.BeanMatchStore;
+import io.beanmapper.core.BeanMatchStoreFactory;
import io.beanmapper.core.BeanProperty;
import io.beanmapper.core.converter.collections.BeanCollectionInstructions;
import javassist.CannotCompileException;
@@ -26,8 +27,8 @@ public class ClassGenerator {
private static Integer GENERATED_CLASS_PREFIX = 0;
private BeanMatchStore beanMatchStore;
- public ClassGenerator() {
- this.beanMatchStore = new BeanMatchStore(null, null);
+ public ClassGenerator(BeanMatchStoreFactory beanMatchStoreFactory) {
+ this.beanMatchStore = beanMatchStoreFactory.create(null, null);
this.classPool = ClassPool.getDefault();
}
diff --git a/src/main/java/io/beanmapper/dynclass/ClassStore.java b/src/main/java/io/beanmapper/dynclass/ClassStore.java
index 411b92b1..0c2ff1ff 100644
--- a/src/main/java/io/beanmapper/dynclass/ClassStore.java
+++ b/src/main/java/io/beanmapper/dynclass/ClassStore.java
@@ -5,6 +5,7 @@
import java.util.TreeMap;
import io.beanmapper.config.StrictMappingProperties;
+import io.beanmapper.core.BeanMatchStoreFactory;
import io.beanmapper.exceptions.BeanDynamicClassGenerationException;
public class ClassStore {
@@ -16,8 +17,8 @@ public class ClassStore {
CACHE = new TreeMap>>();
}
- public ClassStore() {
- this.classGenerator = new ClassGenerator();
+ public ClassStore(BeanMatchStoreFactory beanMatchStoreFactory) {
+ this.classGenerator = new ClassGenerator(beanMatchStoreFactory);
}
public Class> getOrCreateGeneratedClass(
diff --git a/src/test/java/io/beanmapper/config/CoreConfigurationTest.java b/src/test/java/io/beanmapper/config/CoreConfigurationTest.java
index d23c521d..63673f00 100644
--- a/src/test/java/io/beanmapper/config/CoreConfigurationTest.java
+++ b/src/test/java/io/beanmapper/config/CoreConfigurationTest.java
@@ -4,47 +4,51 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import io.beanmapper.core.BeanMatchStore;
+import io.beanmapper.core.BeanMatchStoreFactory;
import io.beanmapper.exceptions.BeanConfigurationOperationNotAllowedException;
import org.junit.Test;
public class CoreConfigurationTest {
+ private BeanMatchStoreFactory beanMatchStoreFactory = BeanMatchStore::new;
+
@Test(expected = BeanConfigurationOperationNotAllowedException.class)
public void setParent() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
configuration.setParent(null);
}
@Test(expected = BeanConfigurationOperationNotAllowedException.class)
public void setTarget() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
configuration.setTarget("Hello world");
}
@Test
public void determineTargetClass_noTargetSet() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
assertNull(configuration.determineTargetClass());
}
@Test
public void addNullPackagePrefix() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
configuration.addPackagePrefix((Class>)null);
assertEquals(0, configuration.getPackagePrefixes().size());
}
@Test
public void addWithoutDefaultConverters() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
configuration.withoutDefaultConverters();
assertFalse(configuration.isAddDefaultConverters());
}
@Test
public void singleMapRunProperties() {
- CoreConfiguration configuration = new CoreConfiguration();
+ CoreConfiguration configuration = new CoreConfiguration(beanMatchStoreFactory);
assertNull(configuration.getDownsizeSource());
assertNull(configuration.getDownsizeTarget());
assertNull(configuration.getTargetClass());
diff --git a/src/test/java/io/beanmapper/core/BeanPropertyTest.java b/src/test/java/io/beanmapper/core/BeanPropertyTest.java
index 6fd1be44..f472072a 100644
--- a/src/test/java/io/beanmapper/core/BeanPropertyTest.java
+++ b/src/test/java/io/beanmapper/core/BeanPropertyTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import io.beanmapper.core.inspector.PropertyAccessors;
import io.beanmapper.testmodel.nested_classes.Layer1;
import io.beanmapper.testmodel.nested_classes.Layer1Result;
@@ -12,7 +13,7 @@ public class BeanPropertyTest {
@Test
public void determineNodes() {
- BeanProperty beanProperty = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanProperty = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
assertEquals("layer2", beanProperty.getCurrentAccessor().getName());
assertNotNull("the 'layer2' node must refer to the 'layer3' node", beanProperty.getNext());
assertEquals("layer3", beanProperty.getNext().getCurrentAccessor().getName());
@@ -23,7 +24,7 @@ public void determineNodes() {
@Test
public void getObject() {
Layer1 layer1 = Layer1.createNestedClassObject();
- BeanProperty beanProperty = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanProperty = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
Object object = beanProperty.getObject(layer1);
assertEquals(String.class, object.getClass());
assertEquals("name3", object);
@@ -32,9 +33,9 @@ public void getObject() {
@Test
public void writeObjectToNewTarget() {
Layer1 layer1 = Layer1.createNestedClassObject();
- BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
Object source = beanPropertyForSource.getObject(layer1);
- BeanProperty beanPropertyForTarget = new BeanPropertyCreator(BeanPropertyMatchupDirection.TARGET_TO_SOURCE, Layer1Result.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanPropertyForTarget = new BeanPropertyCreator(BeanPropertyMatchupDirection.TARGET_TO_SOURCE, Layer1Result.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
Layer1Result target = (Layer1Result) beanPropertyForTarget.writeObject(source, new Layer1Result(), null, null);
assertEquals("name3", target.getLayer2().getLayer3().getName3());
}
@@ -43,16 +44,16 @@ public void writeObjectToNewTarget() {
public void writeObjectToExistingTarget() {
Layer1 layer1 = Layer1.createNestedClassObject();
Layer1Result existingTarget = Layer1Result.createNestedClassObject();
- BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
Object source = beanPropertyForSource.getObject(layer1);
- BeanProperty beanPropertyForTarget = new BeanPropertyCreator(BeanPropertyMatchupDirection.TARGET_TO_SOURCE, Layer1Result.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanPropertyForTarget = new BeanPropertyCreator(BeanPropertyMatchupDirection.TARGET_TO_SOURCE, Layer1Result.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
Layer1Result target = (Layer1Result) beanPropertyForTarget.writeObject(source, existingTarget, null, null);
assertEquals("name3", target.getLayer2().getLayer3().getName3());
}
@Test
public void getName() {
- BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, "layer2.layer3.name3").determineNodesForPath();
+ BeanProperty beanPropertyForSource = new BeanPropertyCreator(BeanPropertyMatchupDirection.SOURCE_TO_TARGET, Layer1.class, new PropertyAccessors(), "layer2.layer3.name3").determineNodesForPath();
assertEquals("layer2.layer3.name3", beanPropertyForSource.getName());
}
diff --git a/src/test/java/io/beanmapper/core/converter/collections/BeanCollectionInstructionsTest.java b/src/test/java/io/beanmapper/core/converter/collections/BeanCollectionInstructionsTest.java
index bffa0224..12b2e864 100644
--- a/src/test/java/io/beanmapper/core/converter/collections/BeanCollectionInstructionsTest.java
+++ b/src/test/java/io/beanmapper/core/converter/collections/BeanCollectionInstructionsTest.java
@@ -13,6 +13,7 @@
import io.beanmapper.core.BeanPropertyCreator;
import io.beanmapper.core.BeanPropertyMatchupDirection;
+import io.beanmapper.core.inspector.PropertyAccessors;
import org.junit.Test;
public class BeanCollectionInstructionsTest {
@@ -27,11 +28,13 @@ public void onlyTargetSideGenericSupplied() {
BeanProperty sourceBeanProperty = new BeanPropertyCreator(
BeanPropertyMatchupDirection.SOURCE_TO_TARGET,
SourceClassContainingList.class,
+ new PropertyAccessors(),
"list")
.determineNodesForPath();
BeanProperty targetBeanProperty = new BeanPropertyCreator(
BeanPropertyMatchupDirection.SOURCE_TO_TARGET,
TargetClassContainingList.class,
+ new PropertyAccessors(),
"list")
.determineNodesForPath();
@@ -54,11 +57,13 @@ public void sourceSideSuppliesInstructionsAndTargetSideGeneric() {
BeanProperty sourceBeanProperty = new BeanPropertyCreator(
BeanPropertyMatchupDirection.SOURCE_TO_TARGET,
SourceClassContainingList.class,
+ new PropertyAccessors(),
"list")
.determineNodesForPath();
BeanProperty targetBeanProperty = new BeanPropertyCreator(
BeanPropertyMatchupDirection.SOURCE_TO_TARGET,
TargetClassContainingList.class,
+ new PropertyAccessors(),
"list")
.determineNodesForPath();
diff --git a/src/test/java/io/beanmapper/core/generics/BeanPropertyClassTest.java b/src/test/java/io/beanmapper/core/generics/BeanPropertyClassTest.java
index 8aa36d57..92bee4d2 100644
--- a/src/test/java/io/beanmapper/core/generics/BeanPropertyClassTest.java
+++ b/src/test/java/io/beanmapper/core/generics/BeanPropertyClassTest.java
@@ -95,7 +95,7 @@ private BeanPropertyClass extractBeanPropertyClass(
BeanPropertyMatchupDirection direction,
Class containingClass,
String property) {
- PropertyAccessor sourceAccessor = PropertyAccessors.findProperty(containingClass, property);
+ PropertyAccessor sourceAccessor = new PropertyAccessors().findProperty(containingClass, property);
DirectedBeanProperty directedBeanProperty = new DirectedBeanProperty(
direction,
sourceAccessor,
diff --git a/src/test/java/io/beanmapper/core/generics/DirectedBeanPropertyTest.java b/src/test/java/io/beanmapper/core/generics/DirectedBeanPropertyTest.java
index f6308f88..a518874c 100644
--- a/src/test/java/io/beanmapper/core/generics/DirectedBeanPropertyTest.java
+++ b/src/test/java/io/beanmapper/core/generics/DirectedBeanPropertyTest.java
@@ -101,7 +101,7 @@ private DirectedBeanProperty getDirectedBeanProperty(
Class containingClass,
BeanPropertyMatchupDirection sourceToTarget,
String property) {
- PropertyAccessor accessor = PropertyAccessors.findProperty(containingClass, property);
+ PropertyAccessor accessor = new PropertyAccessors().findProperty(containingClass, property);
return new DirectedBeanProperty(
sourceToTarget,
accessor,
diff --git a/src/test/java/io/beanmapper/core/inspector/BeanPropertyAccessTypeTest.java b/src/test/java/io/beanmapper/core/inspector/BeanPropertyAccessTypeTest.java
index 97a86635..45a17922 100644
--- a/src/test/java/io/beanmapper/core/inspector/BeanPropertyAccessTypeTest.java
+++ b/src/test/java/io/beanmapper/core/inspector/BeanPropertyAccessTypeTest.java
@@ -9,15 +9,17 @@
public class BeanPropertyAccessTypeTest {
+ private PropertyAccessors propertyAccessors = new PropertyAccessors();
+
@Test
public void fieldInSourceCannotBeAccessed() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(NoAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(NoAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.NO_ACCESS, BeanPropertyMatchupDirection.SOURCE_TO_TARGET.accessType(accessor));
}
@Test
public void fieldInTargetCannotBeAccessed() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(NoAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(NoAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.NO_ACCESS, BeanPropertyMatchupDirection.TARGET_TO_SOURCE.accessType(accessor));
}
@@ -27,13 +29,13 @@ private class NoAccessToField {
@Test
public void fieldInSourceAccessedByGetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(GetterSetterAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(GetterSetterAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.GETTER, BeanPropertyMatchupDirection.SOURCE_TO_TARGET.accessType(accessor));
}
@Test
public void fieldInTargetAccessedBySetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(GetterSetterAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(GetterSetterAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.SETTER, BeanPropertyMatchupDirection.TARGET_TO_SOURCE.accessType(accessor));
}
@@ -45,13 +47,13 @@ private class GetterSetterAccessToField {
@Test
public void fieldInSourceAccessedByField() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(FieldAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(FieldAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.FIELD, BeanPropertyMatchupDirection.SOURCE_TO_TARGET.accessType(accessor));
}
@Test
public void fieldInTargetAccessedByField() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(FieldAccessToField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(FieldAccessToField.class, "name");
assertEquals(BeanPropertyAccessType.FIELD, BeanPropertyMatchupDirection.TARGET_TO_SOURCE.accessType(accessor));
}
@@ -61,13 +63,13 @@ private class FieldAccessToField {
@Test
public void getterInSourceAccessed() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(OnlyGetterSetterNoField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(OnlyGetterSetterNoField.class, "name");
assertEquals(BeanPropertyAccessType.GETTER, BeanPropertyMatchupDirection.SOURCE_TO_TARGET.accessType(accessor));
}
@Test
public void setterInTargetAccessed() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(OnlyGetterSetterNoField.class, "name");
+ PropertyAccessor accessor = propertyAccessors.findProperty(OnlyGetterSetterNoField.class, "name");
assertEquals(BeanPropertyAccessType.SETTER, BeanPropertyMatchupDirection.TARGET_TO_SOURCE.accessType(accessor));
}
diff --git a/src/test/java/io/beanmapper/core/inspector/PropertyAccessorTest.java b/src/test/java/io/beanmapper/core/inspector/PropertyAccessorTest.java
index d718b1bc..cfccabd9 100644
--- a/src/test/java/io/beanmapper/core/inspector/PropertyAccessorTest.java
+++ b/src/test/java/io/beanmapper/core/inspector/PropertyAccessorTest.java
@@ -18,6 +18,8 @@
public class PropertyAccessorTest {
private BeanWithProperties bean;
+
+ private PropertyAccessors propertyAccessors = new PropertyAccessors();
@Before
public void setUp() {
@@ -26,7 +28,7 @@ public void setUp() {
@Test
public void testField() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "myField");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "myField");
Assert.assertEquals("myField", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("a", accessor.findAnnotation(BeanProperty.class).name());
@@ -42,7 +44,7 @@ public void testField() {
@Test
public void testFieldWithGetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithGetter");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithGetter");
Assert.assertEquals("myPropertyWithGetter", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("bb", accessor.findAnnotation(BeanProperty.class).name());
@@ -57,7 +59,7 @@ public void testFieldWithGetter() {
@Test
public void testFieldWithSetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithSetter");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithSetter");
Assert.assertEquals("myPropertyWithSetter", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("cc", accessor.findAnnotation(BeanProperty.class).name());
@@ -72,7 +74,7 @@ public void testFieldWithSetter() {
@Test
public void testFieldWithGetterAndSetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithGetterAndSetter");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "myPropertyWithGetterAndSetter");
Assert.assertEquals("myPropertyWithGetterAndSetter", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("dd", accessor.findAnnotation(BeanProperty.class).name());
@@ -88,7 +90,7 @@ public void testFieldWithGetterAndSetter() {
@Test
public void testGetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "myGetter");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "myGetter");
Assert.assertEquals("myGetter", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("e", accessor.findAnnotation(BeanProperty.class).name());
@@ -98,7 +100,7 @@ public void testGetter() {
@Test
public void testSetter() {
- PropertyAccessor accessor = PropertyAccessors.findProperty(BeanWithProperties.class, "mySetter");
+ PropertyAccessor accessor = propertyAccessors.findProperty(BeanWithProperties.class, "mySetter");
Assert.assertEquals("mySetter", accessor.getName());
Assert.assertEquals(String.class, accessor.getType());
Assert.assertEquals("f", accessor.findAnnotation(BeanProperty.class).name());
@@ -108,7 +110,7 @@ public void testSetter() {
@Test
public void testUnknownProperty() {
- Assert.assertNull(PropertyAccessors.findProperty(BeanWithProperties.class, "unknown"));
+ Assert.assertNull(propertyAccessors.findProperty(BeanWithProperties.class, "unknown"));
}
@SuppressWarnings("unused")
diff --git a/src/test/java/io/beanmapper/dynclass/ClassGeneratorTest.java b/src/test/java/io/beanmapper/dynclass/ClassGeneratorTest.java
index bef1493e..90eb9346 100644
--- a/src/test/java/io/beanmapper/dynclass/ClassGeneratorTest.java
+++ b/src/test/java/io/beanmapper/dynclass/ClassGeneratorTest.java
@@ -7,6 +7,7 @@
import java.util.List;
import io.beanmapper.config.BeanMapperBuilder;
+import io.beanmapper.core.BeanMatchStore;
import io.beanmapper.dynclass.model.Person;
import org.junit.Test;
@@ -15,7 +16,7 @@ public class ClassGeneratorTest extends AbstractConcurrentTest {
@Test
public void shouldNotFailConcurrently() throws Exception {
- final ClassGenerator gen = new ClassGenerator();
+ final ClassGenerator gen = new ClassGenerator(BeanMatchStore::new);
final List results = Collections.synchronizedList(new ArrayList());
final Runnable r = new Runnable() {
diff --git a/src/test/java/io/beanmapper/dynclass/ClassStoreTest.java b/src/test/java/io/beanmapper/dynclass/ClassStoreTest.java
index ead829ff..a7445809 100644
--- a/src/test/java/io/beanmapper/dynclass/ClassStoreTest.java
+++ b/src/test/java/io/beanmapper/dynclass/ClassStoreTest.java
@@ -7,6 +7,7 @@
import java.util.concurrent.CopyOnWriteArraySet;
import io.beanmapper.config.BeanMapperBuilder;
+import io.beanmapper.core.BeanMatchStore;
import io.beanmapper.dynclass.model.Person;
import org.junit.Before;
@@ -18,7 +19,7 @@ public class ClassStoreTest extends AbstractConcurrentTest {
@Before
public void init() {
- store = new ClassStore();
+ store = new ClassStore(BeanMatchStore::new);
}
@Test