├── .checkstyle ├── .github └── workflows │ ├── build.yml │ └── publish.yml ├── .gitignore ├── .idea └── checkstyle-idea.xml ├── CONTRIBUTE.md ├── LICENSE ├── README.md ├── pom.xml ├── shared ├── checkstyle │ └── checkstyle.xml └── eclipse-formatter │ └── eclipse-formatter-config.xml └── src ├── main └── java │ └── com │ └── remondis │ └── remap │ ├── AssertConfiguration.java │ ├── AssertMapping.java │ ├── AssertVerification.java │ ├── BidirectionalMapper.java │ ├── ClassHierarchyIterator.java │ ├── FieldSelector.java │ ├── GenericParameterContext.java │ ├── InterceptionHandler.java │ ├── InternalMapper.java │ ├── InvocationSensor.java │ ├── Lang.java │ ├── MapTransformation.java │ ├── MappedResult.java │ ├── Mapper.java │ ├── MapperAdapter.java │ ├── Mapping.java │ ├── MappingConfiguration.java │ ├── MappingException.java │ ├── MappingModel.java │ ├── MappingOperation.java │ ├── OmitTransformation.java │ ├── Projection.java │ ├── Properties.java │ ├── PropertyPathAndApplyBuilder.java │ ├── PropertyPathAndApplyCollectionBuilder.java │ ├── PropertyPathCollectionTransformation.java │ ├── PropertyPathTransformation.java │ ├── ReassignAssertBuilder.java │ ├── ReassignBuilder.java │ ├── ReassignTransformation.java │ ├── ReflectionUtil.java │ ├── ReplaceAssertBuilder.java │ ├── ReplaceBuilder.java │ ├── ReplaceCollectionAssertBuilder.java │ ├── ReplaceCollectionBuilder.java │ ├── ReplaceCollectionTransformation.java │ ├── ReplaceTransformation.java │ ├── RestructureAssertBuilder.java │ ├── RestructureBuilder.java │ ├── RestructureTransformation.java │ ├── RestructureVerification.java │ ├── RestructuringAssertConfiguration.java │ ├── SetAssertBuilder.java │ ├── SetBuilder.java │ ├── SetSupplierTransformation.java │ ├── SetTransformation.java │ ├── SetValueTransformation.java │ ├── SkipWhenNullTransformation.java │ ├── Target.java │ ├── Transformation.java │ ├── TypeMapping.java │ ├── TypedPropertyDescriptor.java │ ├── TypedSelector.java │ ├── Types.java │ └── utils │ ├── mapOver │ └── MapOver.java │ └── propertywalker │ ├── BiPropertyVisitor.java │ ├── BiRecursivePropertyWalker.java │ ├── GetSet.java │ ├── PropertyAccess.java │ └── VisitorFunction.java └── test └── java └── com └── remondis ├── extern └── usecase │ └── metamodel │ ├── Destination.java │ ├── MetaModelFeatureTest.java │ ├── NestedDestination.java │ ├── NestedSource.java │ └── Source.java └── remap ├── BiRecursivePropertyWalkerTest.java ├── DummyDto.java ├── InvocationSensorTest.java ├── MapperTest.java ├── PropertiesTest.java ├── StringDto.java ├── assertion ├── A.java ├── AResource.java ├── B.java ├── BResource.java └── omitOthersAssert │ ├── BeanEmpty.java │ ├── BeanWithFields.java │ └── OmitOthersAssertionTest.java ├── basic ├── A.java ├── AReassign.java ├── AResource.java ├── AResourceReassign.java ├── AResourceWithOneMoreDestinationField.java ├── AResourceWithOneMoreSourceField.java ├── AWithOneMoreDestinationField.java ├── AWithOneMoreSourceField.java ├── AssertMappingTest.java ├── B.java ├── BResource.java ├── FlatCollectionMappingTest.java ├── MapIterableTest.java └── MapperTest.java ├── builder ├── BuilderModel.java ├── BuilderTest.java └── DestinationModel.java ├── collections ├── A.java ├── AResource.java ├── CollectionsTest.java ├── fromSetToList │ ├── A.java │ ├── A1.java │ ├── A2.java │ ├── AMapped.java │ └── FromSetToListTest.java ├── listAndMaps │ ├── A.java │ ├── AResource.java │ ├── B.java │ ├── BResource.java │ └── ListAndMapsTest.java └── nestedCollections │ ├── A.java │ ├── AResource.java │ └── NestedCollectionsTest.java ├── copyObjects ├── A.java ├── AResource.java ├── B.java └── CopyObjectTest.java ├── defaultMethods ├── DefaultMethodTest.java ├── DestinationBean.java ├── Interface.java ├── SourceBean.java └── SourceBeanWithDefaults.java ├── demo ├── Customer.java ├── DemoTest.java ├── Gender.java ├── Person.java └── v2 │ ├── Address.java │ ├── MapPersonTest.java │ ├── Person.java │ └── PersonView.java ├── enums ├── AnotherResource.java ├── EnumsTest.java ├── Gender.java ├── Gender2.java ├── Person.java └── PersonResource.java ├── flatCollectionMapping ├── DemoTest.java ├── Destination.java ├── Id.java └── Source.java ├── fluent ├── ChainedSetterTest.java └── FluentSetterDto.java ├── generics ├── Bean.java ├── Bean2.java ├── GenericsTest.java ├── Identifiable.java └── IdentifiableImpl.java ├── implicitMappings ├── customTypeConversions │ ├── A.java │ ├── AResource.java │ └── CustomTypeConversionsTest.java ├── differentFieldNames │ ├── A.java │ ├── AResource.java │ ├── B.java │ ├── BResource.java │ └── ImplicitMappingTest.java ├── sameFieldAndType │ ├── A.java │ ├── AResource.java │ ├── B.java │ └── ImplicitMappingTest.java └── sameFieldNames │ ├── A.java │ ├── AResource.java │ ├── B.java │ ├── BResource.java │ └── ImplicitMappingTest.java ├── inheritance ├── Child.java ├── ChildInterface.java ├── ChildResource.java ├── MapperTest.java ├── Parent.java ├── ParentInterface.java └── ParentResource.java ├── interfaceMapping ├── EntityA.java ├── EntityADTO.java ├── EntityMappingTest.java ├── EntityWithIdDTO.java └── HasId.java ├── interfaces ├── DestImpl.java ├── Destination.java ├── MapperTest.java ├── Source.java └── SrcImpl.java ├── mapInto ├── Address.java ├── AddressLite.java ├── MapperTest.java ├── Person.java └── PersonLite.java ├── maps ├── A.java ├── AResource.java ├── MapsTest.java ├── incompatibleListMapTypeValidation │ ├── A.java │ ├── AMapped.java │ ├── B.java │ ├── BMapped.java │ ├── C.java │ ├── CMapped.java │ └── TypeValidationTest.java ├── listMapTypeValidation │ ├── A.java │ ├── AMapped.java │ ├── B.java │ ├── BMapped.java │ ├── C.java │ ├── CMapped.java │ └── TypeValidationTest.java ├── nested │ ├── A.java │ ├── A1.java │ ├── A1Mapped.java │ ├── A2.java │ ├── A2Mapped.java │ ├── A3.java │ ├── A3Mapped.java │ ├── AMapped.java │ └── MapsTest.java └── reassign │ ├── A.java │ ├── AMapped.java │ ├── B.java │ └── ReassignTest.java ├── multimapping ├── reassign │ ├── A.java │ ├── AResource.java │ └── MapperTest.java └── replace │ ├── A.java │ ├── AResource.java │ ├── B.java │ └── MapperTest.java ├── noImplicitMappings ├── A.java ├── B.java └── NoImplicitMappingsTest.java ├── nullvalues ├── A.java ├── AResource.java ├── B.java ├── BResource.java └── MapperTest.java ├── omitOthers ├── A.java ├── AResource.java └── MapperTest.java ├── propertypathmapping ├── Address.java ├── Person.java ├── PersonView.java ├── PropertyPathTest.java ├── collections │ ├── CollectionDestination.java │ ├── CollectionSource.java │ └── PropertyPathCollectionTest.java └── withtransformation │ ├── PersonView.java │ ├── PropertyPathWithTransformationTest.java │ └── collections │ ├── Person.java │ ├── PersonView.java │ └── PropertyPathWithTransformationCollectionTest.java ├── regression ├── booleanObjectBug │ ├── A.java │ ├── B.java │ └── MapperTest.java ├── capitalLetterBug │ ├── A.java │ ├── AResource.java │ └── MapperTest.java ├── implicitPrimitiveToWrapperMappingBug │ ├── BoolPrimitive.java │ ├── BoolWrapper.java │ ├── IntPrimitive.java │ ├── IntWrapper.java │ └── MappingTest.java ├── methodCallsInConstructor │ ├── A.java │ └── MethodCallsInConstructorTest.java ├── noBeanCopyBug │ ├── A.java │ ├── AResource.java │ └── NoBeanCopyBug.java ├── npeDenyAlreadyOmitted │ ├── A.java │ ├── AResource.java │ └── MapperTest.java ├── npeOnUnmappedReadOnlyProperty │ ├── A.java │ ├── B.java │ └── MapperTest.java ├── omitCustomGet │ ├── Bar.java │ ├── Foo.java │ ├── FooMapped.java │ └── MapperTest.java ├── omitOthersOmitsImplicitMappings │ ├── A.java │ ├── B.java │ └── MapperTest.java ├── omitReadOnlyGetterBug │ ├── A.java │ ├── B.java │ └── MapperTest.java ├── replaceOnCollectionBug │ ├── A.java │ ├── AFlat.java │ ├── AResource.java │ └── ReplaceOnCollectionsTest.java ├── typeMappingForCollectionsBug │ ├── A.java │ ├── B.java │ └── MapperTest.java └── useMapperTwice │ ├── A.java │ ├── AMapped.java │ ├── B.java │ ├── BMapped.java │ └── UseMapperTwiceTest.java ├── restructure ├── Address.java ├── Bean.java ├── RestructureTest.java ├── RestructuredBean.java ├── demo │ ├── Address.java │ ├── Family.java │ ├── Person.java │ ├── PersonFlat.java │ └── RestructuringDemoTest.java └── ndepth │ ├── Bean2.java │ ├── NdepthRestructureTest.java │ └── Person.java ├── setOperation ├── A.java ├── B.java └── SetOperationTest.java ├── spring └── SpringExampleTest.java ├── test └── MapperTests.java ├── utils └── mapOver │ └── MapOverTest.java ├── visibility ├── C.java ├── CResource.java └── VisibilityTest.java └── writeNull ├── Destination.java ├── Source.java └── WriteNullTest.java /.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' 7 | - '!master' # excludes master, master is configured by publish action. 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Set up JDK 17 15 | uses: actions/setup-java@v2 16 | with: 17 | java-version: '17' 18 | distribution: 'adopt' 19 | # Step that does that actual cache save and restore 20 | - uses: actions/cache@v1 21 | with: 22 | path: ~/.m2/repository 23 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 24 | restore-keys: | 25 | ${{ runner.os }}-maven- 26 | - name: Build with Maven 27 | run: mvn --batch-mode --update-snapshots verify -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish package to the Maven Central Repository 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up Maven Central Repository 13 | uses: actions/setup-java@v2 14 | with: 15 | java-version: '17' 16 | distribution: 'adopt' 17 | server-id: ossrh 18 | server-username: MAVEN_USERNAME 19 | server-password: MAVEN_PASSWORD 20 | - name: Create Key File 21 | run: echo "$GPG_PRIVATE_KEY" > secret.asc 22 | env: 23 | GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} 24 | - name: Import GPG Key 25 | run: gpg --import --batch secret.asc 26 | # Step that does that actual cache save and restore 27 | - uses: actions/cache@v1 28 | with: 29 | path: ~/.m2/repository 30 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 31 | restore-keys: | 32 | ${{ runner.os }}-maven- 33 | - name: Publish package 34 | run: mvn --batch-mode deploy -Psign 35 | env: 36 | MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} 37 | MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .settings/ 3 | .classpath 4 | .project 5 | bin/ 6 | .gradle 7 | 8 | # IntelliJ config files 9 | .idea/**/* 10 | !.idea/checkstyle-idea.xml 11 | !.idea/inspectionProfiles/Project_Default.xml 12 | classes/**/* 13 | **/node_modules 14 | **/*.iml 15 | **/*.ipr 16 | **/*.iws 17 | 18 | **/build 19 | out 20 | *.log 21 | 22 | /.gradle/ 23 | .checkstyle -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/AssertMapping.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * This is the ReMap API entrypoint to create instances of {@link Mapper}. 5 | * 6 | * @author schuettec 7 | * 8 | */ 9 | public class AssertMapping { 10 | 11 | /** 12 | * Creates a new specification of assertions that are to be checked for the specified mapper instance. 13 | * 14 | * @param mapper 15 | * The {@link Mapper} instance. 16 | * @return Returns a new {@link AssertConfiguration} for method changing. 17 | */ 18 | public static AssertConfiguration of(Mapper mapper) { 19 | return new AssertConfiguration(mapper); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/AssertVerification.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * Interface to implement custom verification tasks evaluated by {@link AssertConfiguration#ensure()}. Use this method 5 | * for verifications of mapping operations that cannot be performed using {@link Transformation#equals(Object)}. 6 | */ 7 | @FunctionalInterface 8 | public interface AssertVerification { 9 | /** 10 | * @throws AssertionError Throws an {@link AssertionError} if the verification failed. Please use user-friendly text 11 | * messages that explain the expected and actual state. 12 | */ 13 | public void verify() throws AssertionError; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/ClassHierarchyIterator.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import static java.util.Objects.nonNull; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Iterator that enables to interate over the complete class hierarchy of a type including superclasses and interfaces. 9 | */ 10 | public class ClassHierarchyIterator implements Iterator> { 11 | private Queue> remaining = new LinkedList<>(); 12 | private Set> visited = new LinkedHashSet<>(); 13 | 14 | public ClassHierarchyIterator(Class initial) { 15 | append(initial); 16 | } 17 | 18 | private void append(Class toAppend) { 19 | if (nonNull(toAppend) && !visited.contains(toAppend)) { 20 | remaining.add(toAppend); 21 | visited.add(toAppend); 22 | } 23 | } 24 | 25 | @Override 26 | public boolean hasNext() { 27 | return remaining.size() > 0; 28 | } 29 | 30 | @Override 31 | public Class next() { 32 | if (!hasNext()) { 33 | throw new NoSuchElementException(); 34 | } 35 | Class polled = remaining.poll(); 36 | append(polled.getSuperclass()); 37 | for (Class superInterface : polled.getInterfaces()) { 38 | append(superInterface); 39 | } 40 | return polled; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/FieldSelector.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * This class defines the lambda that receives an object of either a source or destination type. The lambda is 5 | * implemented with calling the get-method to select the corresponding property. The mapping framework then detects the 6 | * get-method invocation on the destination object and selects the corresponding property for further mapping 7 | * configuration. The mapping configuration is specified with the surrounding configuration method like {@link 8 | * MappingConfiguration#omitInDestination(FieldSelector)},{@link MappingConfiguration#omitInSource(FieldSelector)} . 9 | * 10 | * @param The object type selecting a field on. 11 | * @author schuettec 12 | */ 13 | @FunctionalInterface 14 | public interface FieldSelector { 15 | 16 | /** 17 | * This method is used to perform a get-method invocation of the specified destination object. This invocation tells 18 | * the mapper which property is to be selected for the following configuration. 19 | * 20 | * @param destination The destination object to perform a get-method invocation on. 21 | */ 22 | void selectField(T destination); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/InternalMapper.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * This is an internal abstraction of the essential mapping function that is used internally by 5 | * {@link MappingConfiguration}. This 6 | * interface is used to generalize the mapper specified by {@link MappingConfiguration#useMapper(Mapper)} and the type 7 | * mapping 8 | * functions. 9 | */ 10 | interface InternalMapper { 11 | 12 | /** 13 | * Performs the mapping from the source into a specified destination object. In case of a Java Bean mapper the fields 14 | * in the destination object are overridden if affected by the mapping configuration. In case of a custom type mapper, 15 | * the mapping function defines the behaviour. 16 | * 17 | * @param source The source object. 18 | * @param destination The destination object to map into. 19 | * @return Returns the specified destination object. 20 | */ 21 | public D map(S source, D destination); 22 | 23 | /** 24 | * Performs the mapping from the source into a new destination object. This method is expected to return a new 25 | * instance of the target object. 26 | * 27 | * @param source The source object. 28 | * @return Returns the specified destination object. 29 | */ 30 | public D map(S source); 31 | 32 | /** 33 | * Returns the {@link Projection} this mapper defines. 34 | * 35 | * @return Returns the type projection information. 36 | */ 37 | public Projection getProjection(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/Lang.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * A utility class to provide some language features. 5 | * 6 | * @author schuettec 7 | */ 8 | class Lang { 9 | 10 | /** 11 | * This method throws an {@link IllegalArgumentException} if the specified argument is null. 12 | * 13 | * @param fieldName The parameter name. 14 | * @param argument The actual argument. 15 | * @return Returns the argument 16 | * @throws IllegalArgumentException Thrown with a detailed message if argument is null. Returns 17 | * immediately otherwise. 18 | */ 19 | static T denyNull(String fieldName, T argument) throws IllegalArgumentException { 20 | if (argument == null) { 21 | if (fieldName == null) { 22 | throw new IllegalArgumentException("Argument must not be null."); 23 | } else { 24 | throw new IllegalArgumentException(String.format("Argument %s must not be null.", fieldName)); 25 | } 26 | } 27 | return argument; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/MapTransformation.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import static com.remondis.remap.Properties.asString; 4 | 5 | import java.beans.PropertyDescriptor; 6 | 7 | /** 8 | * The map transformation is the simplest mapping operation. It just reassigns a field from the source object to a 9 | * destination object while the property name AND [ types are equal OR a matching mapper is 10 | * registered on the parent mapper ]. Therefore the mapping transformation is 11 | * a special case of {@link ReassignTransformation}. This mapping transformation is only used 12 | * internally to distinguish from mappings configured by the user and implicit field mappings created by the mapper 13 | * itself. 14 | */ 15 | public class MapTransformation extends ReassignTransformation { 16 | 17 | private static final String MAP_MSG = "Map %s\n to %s"; 18 | 19 | MapTransformation(MappingConfiguration mapping, PropertyDescriptor sourceProperty, 20 | PropertyDescriptor destinationProperty) { 21 | super(mapping, sourceProperty, destinationProperty); 22 | denyReassign(sourceProperty, destinationProperty); 23 | } 24 | 25 | private void denyReassign(PropertyDescriptor sourceProperty, PropertyDescriptor destinationProperty) { 26 | if (!sourceProperty.getName() 27 | .equals(destinationProperty.getName())) { 28 | throw new MappingException("Attempt to perform a reassign with MapTransformation - implementation fault!"); 29 | } 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return String.format(MAP_MSG, asString(sourceProperty), asString(destinationProperty)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/MapperAdapter.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * An implementation to generalize a {@link Mapper} using {@link InternalMapper}. 5 | * 6 | * @param the source type 7 | * @param the destination type. 8 | */ 9 | class MapperAdapter implements InternalMapper { 10 | 11 | private Mapper mapper; 12 | 13 | public MapperAdapter(Mapper mapper) { 14 | super(); 15 | this.mapper = mapper; 16 | } 17 | 18 | @Override 19 | public D map(S source, D destination) { 20 | return mapper.map(source, destination); 21 | } 22 | 23 | @Override 24 | public D map(S source) { 25 | return mapper.map(source); 26 | } 27 | 28 | @Override 29 | public Projection getProjection() { 30 | Class source = mapper.getMapping() 31 | .getSource(); 32 | Class destination = mapper.getMapping() 33 | .getDestination(); 34 | return new Projection<>(source, destination); 35 | } 36 | 37 | Mapper getMapper() { 38 | return mapper; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/Mapping.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * This is the ReMap API entrypoint to create instances of {@link Mapper}. 5 | * 6 | * @author schuettec 7 | * 8 | */ 9 | public class Mapping { 10 | 11 | /** 12 | * Specifies the source data type to map from. 13 | * 14 | * @param source 15 | * the data source type. 16 | * @return Returns a {@link Types} object for further mapping configuration. 17 | */ 18 | public static Types from(Class source) { 19 | return new Types<>(source); 20 | } 21 | 22 | /** 23 | * Specifies the source data type to map from. Use this method to provide information about generic types by providing 24 | * an instance of the object to map. 25 | * 26 | * @param sourceInstance 27 | * The source instance. 28 | * @return Returns a {@link Types} object for further mapping configuration. 29 | */ 30 | @SuppressWarnings("unchecked") 31 | public static Types from(S sourceInstance) { 32 | return new Types<>((Class) sourceInstance.getClass()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/MappingOperation.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * Specifies how the mapping result should be used. 5 | */ 6 | public enum MappingOperation { 7 | /** 8 | * The mapping does not produce a value. Used to distinguish a null-value from "mapping has no result". 9 | */ 10 | SKIP, 11 | /** 12 | * Signals that the value should be used as mapping result. If value ist null, null should 13 | * be used as mapping result value. 14 | */ 15 | VALUE; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/SetSupplierTransformation.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import java.beans.PropertyDescriptor; 4 | import java.util.function.Supplier; 5 | 6 | /** 7 | * A set transformation set a value supplied by a custom function to a destination field. 8 | * 9 | * @param The input type 10 | * @param The output type 11 | * @author schuettec 12 | */ 13 | class SetSupplierTransformation extends SetTransformation { 14 | 15 | SetSupplierTransformation(MappingConfiguration mapping, PropertyDescriptor destProperty, 16 | Supplier supplier) { 17 | super(mapping, destProperty, S -> supplier.get()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/SetValueTransformation.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import java.beans.PropertyDescriptor; 4 | 5 | /** 6 | * A set transformation set a value supplied by a custom function to a destination field. 7 | * 8 | * @param The input type 9 | * @param The output type 10 | * @author schuettec 11 | */ 12 | class SetValueTransformation extends SetTransformation { 13 | 14 | SetValueTransformation(MappingConfiguration mapping, PropertyDescriptor destProperty, RD value) { 15 | super(mapping, destProperty, S -> value); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/SkipWhenNullTransformation.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import java.beans.PropertyDescriptor; 4 | import java.util.function.Function; 5 | 6 | /** 7 | * Interface for transformations that can be skipped on null input. 8 | * 9 | * @param Source field type. 10 | * @param Destination field type. 11 | */ 12 | abstract class SkipWhenNullTransformation extends Transformation { 13 | 14 | SkipWhenNullTransformation(MappingConfiguration mapping, PropertyDescriptor sourceProperty, 15 | PropertyDescriptor destinationProperty) { 16 | super(mapping, sourceProperty, destinationProperty); 17 | } 18 | 19 | /** 20 | * Returns the skip when null configuration. 21 | * 22 | * @return Returns true if this transformation should be skipped when the input value is 23 | * null, otherwise false is returned. 24 | */ 25 | abstract boolean isSkipWhenNull(); 26 | 27 | abstract Function getTransformation(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/Target.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * Target type. 5 | * 6 | * @author chattersley 7 | */ 8 | public enum Target { 9 | 10 | /** Mapping target. */ 11 | SOURCE, 12 | 13 | /** Mapping destination. */ 14 | DESTINATION; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/TypedPropertyDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import java.beans.PropertyDescriptor; 4 | 5 | /** 6 | * A bucket to hold the generic type of a property and the {@link PropertyDescriptor}. 7 | * 8 | * @author schuettec 9 | */ 10 | class TypedPropertyDescriptor { 11 | 12 | R returnValue; 13 | PropertyDescriptor property; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/TypedSelector.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | /** 4 | * This class defines the lambda that receives an object of either a source or destination a mapping type. The lambda is 5 | * implemented with calling the get-method to select the corresponding property. The mapping framework then detects the 6 | * get-method invocation on the destination object and selects the corresponding property for further mapping 7 | * configuration. The mapping configuration is specified with the surrounding configuration method like {@link 8 | * MappingConfiguration#omitInDestination(FieldSelector)},{@link MappingConfiguration#omitInSource(FieldSelector)} . 9 | * 10 | * @param The object type selecting a field on. 11 | * @param The type of the field. 12 | * @author schuettec 13 | */ 14 | @FunctionalInterface 15 | public interface TypedSelector { 16 | 17 | /** 18 | * This method is used to perform a get-method invocation of the specified destination object and returning its value. 19 | * This invocation tells the mapper which property is to be selected for the following configuration and what type it 20 | * has. 21 | * 22 | * @param destination The destination object to perform a get-method invocation on. 23 | * @return Returns the return value of the performed get-method call. 24 | */ 25 | R selectField(T destination); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/utils/propertywalker/BiPropertyVisitor.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.utils.propertywalker; 2 | 3 | import java.util.function.BiConsumer; 4 | import java.util.function.Function; 5 | 6 | /** 7 | * @param The bean type. 8 | * @param

The property type. 9 | * 10 | */ 11 | public class BiPropertyVisitor { 12 | 13 | private Class bean; 14 | private Function propertyExtractor; 15 | private BiConsumer propertyWriter; 16 | 17 | private VisitorFunction visitorFunction; 18 | 19 | public BiPropertyVisitor(Class bean, Function propertyExtractor, BiConsumer propertyWriter, 20 | VisitorFunction visitorFunction) { 21 | this.bean = bean; 22 | this.propertyExtractor = propertyExtractor; 23 | this.propertyWriter = propertyWriter; 24 | this.visitorFunction = visitorFunction; 25 | } 26 | 27 | protected void execute(T source, T target) { 28 | PropertyAccess propertyAccess = new PropertyAccess(source, target, propertyExtractor, propertyWriter); 29 | visitorFunction.consume(propertyAccess); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/utils/propertywalker/GetSet.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.utils.propertywalker; 2 | 3 | import java.util.function.BiConsumer; 4 | import java.util.function.Function; 5 | 6 | public class GetSet { 7 | 8 | private T object; 9 | Function propertyExtractor; 10 | BiConsumer propertyWriter; 11 | 12 | private GetSet(T object, Function propertyExtractor, BiConsumer propertyWriter) { 13 | super(); 14 | this.object = object; 15 | this.propertyExtractor = propertyExtractor; 16 | this.propertyWriter = propertyWriter; 17 | } 18 | 19 | public static GetSet create(T object, Function propertyExtractor, 20 | BiConsumer propertyWriter) { 21 | return new GetSet<>(object, propertyExtractor, propertyWriter); 22 | } 23 | 24 | public void set(P value) { 25 | propertyWriter.accept(object, value); 26 | } 27 | 28 | public P get() { 29 | return propertyExtractor.apply(object); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/utils/propertywalker/PropertyAccess.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.utils.propertywalker; 2 | 3 | import java.util.function.BiConsumer; 4 | import java.util.function.Function; 5 | 6 | public class PropertyAccess { 7 | 8 | private T target; 9 | private T source; 10 | private GetSet sourceGetSet; 11 | private GetSet targetGetSet; 12 | 13 | PropertyAccess(T source, T target, Function propertyExtractor, BiConsumer propertyWriter) { 14 | super(); 15 | this.source = source; 16 | this.target = target; 17 | this.sourceGetSet = GetSet.create(source, propertyExtractor, propertyWriter); 18 | this.targetGetSet = GetSet.create(target, propertyExtractor, propertyWriter); 19 | } 20 | 21 | public T source() { 22 | return source; 23 | } 24 | 25 | public T target() { 26 | return target; 27 | } 28 | 29 | public GetSet sourceProperty() { 30 | return sourceGetSet; 31 | } 32 | 33 | public GetSet targetProperty() { 34 | return targetGetSet; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/remondis/remap/utils/propertywalker/VisitorFunction.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.utils.propertywalker; 2 | 3 | public interface VisitorFunction { 4 | public void consume(PropertyAccess access); 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/extern/usecase/metamodel/NestedDestination.java: -------------------------------------------------------------------------------- 1 | package com.remondis.extern.usecase.metamodel; 2 | 3 | public class NestedDestination { 4 | 5 | private String stringRenamed; 6 | 7 | public NestedDestination(String stringRenamed) { 8 | super(); 9 | this.stringRenamed = stringRenamed; 10 | } 11 | 12 | public NestedDestination() { 13 | super(); 14 | } 15 | 16 | public String getStringRenamed() { 17 | return stringRenamed; 18 | } 19 | 20 | public void setStringRenamed(String stringRenamed) { 21 | this.stringRenamed = stringRenamed; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "NestedDestination [stringRenamed=" + stringRenamed + "]"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/extern/usecase/metamodel/NestedSource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.extern.usecase.metamodel; 2 | 3 | public class NestedSource { 4 | 5 | private String string; 6 | 7 | public NestedSource(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public NestedSource() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "NestedSource [string=" + string + "]"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/extern/usecase/metamodel/Source.java: -------------------------------------------------------------------------------- 1 | package com.remondis.extern.usecase.metamodel; 2 | 3 | public class Source { 4 | 5 | private String string; 6 | private NestedSource nested; 7 | 8 | private Object omitInSource; 9 | 10 | public Source() { 11 | super(); 12 | } 13 | 14 | public String getString() { 15 | return string; 16 | } 17 | 18 | public void setString(String string) { 19 | this.string = string; 20 | } 21 | 22 | public NestedSource getNested() { 23 | return nested; 24 | } 25 | 26 | public void setNested(NestedSource nested) { 27 | this.nested = nested; 28 | } 29 | 30 | public Object getOmitInSource() { 31 | return omitInSource; 32 | } 33 | 34 | public void setOmitInSource(Object omitInSource) { 35 | this.omitInSource = omitInSource; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Source [string=" + string + ", nested=" + nested + "]"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/DummyDto.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | import java.util.Objects; 4 | 5 | public class DummyDto { 6 | 7 | private String string; 8 | 9 | private String anotherString; 10 | 11 | public DummyDto(String string, String anotherString) { 12 | super(); 13 | this.string = string; 14 | this.anotherString = anotherString; 15 | } 16 | 17 | public DummyDto() { 18 | super(); 19 | } 20 | 21 | public String getAnotherString() { 22 | return anotherString; 23 | } 24 | 25 | public void setAnotherString(String anotherString) { 26 | this.anotherString = anotherString; 27 | } 28 | 29 | public String getString() { 30 | return string; 31 | } 32 | 33 | public void setString(String string) { 34 | this.string = string; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(anotherString, string); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (obj == null) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | DummyDto other = (DummyDto) obj; 51 | return Objects.equals(anotherString, other.anotherString) && Objects.equals(string, other.string); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "DummyDto [string=" + string + ", anotherString=" + anotherString + "]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/StringDto.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap; 2 | 3 | public class StringDto { 4 | 5 | private String string; 6 | 7 | public StringDto(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public StringDto() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | StringDto other = (StringDto) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "A [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion; 2 | 3 | public class A { 4 | 5 | private String string; 6 | private B b; 7 | 8 | private String omitted; 9 | 10 | private Integer integer; 11 | 12 | public A() { 13 | super(); 14 | } 15 | 16 | public A(String string, B b, Integer integer) { 17 | super(); 18 | this.string = string; 19 | this.b = b; 20 | this.integer = integer; 21 | } 22 | 23 | public String getOmitted() { 24 | return omitted; 25 | } 26 | 27 | public void setOmitted(String omitted) { 28 | this.omitted = omitted; 29 | } 30 | 31 | public Integer getInteger() { 32 | return integer; 33 | } 34 | 35 | public void setInteger(Integer integer) { 36 | this.integer = integer; 37 | } 38 | 39 | public String getString() { 40 | return string; 41 | } 42 | 43 | public void setString(String string) { 44 | this.string = string; 45 | } 46 | 47 | public B getB() { 48 | return b; 49 | } 50 | 51 | public void setB(B b) { 52 | this.b = b; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "A [string=" + string + ", b=" + b + ", integer=" + integer + "]"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion; 2 | 3 | public class AResource { 4 | 5 | private String anotherString; 6 | private BResource b; 7 | 8 | private Integer omitted; 9 | 10 | private String integerAsString; 11 | 12 | public AResource() { 13 | super(); 14 | } 15 | 16 | public AResource(String anotherString, BResource b, String integerAsString) { 17 | super(); 18 | this.anotherString = anotherString; 19 | this.b = b; 20 | this.integerAsString = integerAsString; 21 | } 22 | 23 | public Integer getOmitted() { 24 | return omitted; 25 | } 26 | 27 | public void setOmitted(Integer omitted) { 28 | this.omitted = omitted; 29 | } 30 | 31 | public String getIntegerAsString() { 32 | return integerAsString; 33 | } 34 | 35 | public void setIntegerAsString(String integerAsString) { 36 | this.integerAsString = integerAsString; 37 | } 38 | 39 | public String getAnotherString() { 40 | return anotherString; 41 | } 42 | 43 | public void setAnotherString(String anotherString) { 44 | this.anotherString = anotherString; 45 | } 46 | 47 | public BResource getB() { 48 | return b; 49 | } 50 | 51 | public void setB(BResource b) { 52 | this.b = b; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "AResource [anotherString=" + anotherString + ", b=" + b + ", integerAsString=" + integerAsString + "]"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B() { 8 | super(); 9 | } 10 | 11 | public B(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | B other = (B) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "B [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/BResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion; 2 | 3 | public class BResource { 4 | 5 | private String string; 6 | 7 | public BResource() { 8 | super(); 9 | } 10 | 11 | public BResource(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | BResource other = (BResource) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "BResource [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/omitOthersAssert/BeanEmpty.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion.omitOthersAssert; 2 | 3 | public class BeanEmpty { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/assertion/omitOthersAssert/BeanWithFields.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.assertion.omitOthersAssert; 2 | 3 | public class BeanWithFields { 4 | private String string; 5 | private int number; 6 | 7 | public BeanWithFields() { 8 | } 9 | 10 | public BeanWithFields(String string, int number) { 11 | this.string = string; 12 | this.number = number; 13 | } 14 | 15 | public String getString() { 16 | return string; 17 | } 18 | 19 | public void setString(String string) { 20 | this.string = string; 21 | } 22 | 23 | public int getNumber() { 24 | return number; 25 | } 26 | 27 | public void setNumber(int number) { 28 | this.number = number; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AReassign.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AReassign { 4 | 5 | private int zahl; 6 | private int firstNumberInA; 7 | private int secondNumberInA; 8 | 9 | public AReassign() { 10 | super(); 11 | } 12 | 13 | public AReassign(int zahl, int firstNumberInA, int secondNumberInA) { 14 | super(); 15 | this.zahl = zahl; 16 | this.firstNumberInA = firstNumberInA; 17 | this.secondNumberInA = secondNumberInA; 18 | } 19 | 20 | public int getZahl() { 21 | return zahl; 22 | } 23 | 24 | public void setZahl(int zahl) { 25 | this.zahl = zahl; 26 | } 27 | 28 | public int getFirstNumberInA() { 29 | return firstNumberInA; 30 | } 31 | 32 | public void setFirstNumberInA(int firstNumberInA) { 33 | this.firstNumberInA = firstNumberInA; 34 | } 35 | 36 | public int getSecondNumberInA() { 37 | return secondNumberInA; 38 | } 39 | 40 | public void setSecondNumberInA(int secondNumberInA) { 41 | this.secondNumberInA = secondNumberInA; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AResourceReassign.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AResourceReassign { 4 | 5 | private int zahl; 6 | private int firstNumberInAResource; 7 | private int secondNumberInAResource; 8 | 9 | public AResourceReassign() { 10 | super(); 11 | } 12 | 13 | public AResourceReassign(int zahl, int firstNumberInAResource, int secondNumberInAResource) { 14 | super(); 15 | this.zahl = zahl; 16 | this.firstNumberInAResource = firstNumberInAResource; 17 | this.secondNumberInAResource = secondNumberInAResource; 18 | } 19 | 20 | public int getZahl() { 21 | return zahl; 22 | } 23 | 24 | public void setZahl(int zahl) { 25 | this.zahl = zahl; 26 | } 27 | 28 | public int getFirstNumberInAResource() { 29 | return firstNumberInAResource; 30 | } 31 | 32 | public void setFirstNumberInAResource(int firstNumberInAResource) { 33 | this.firstNumberInAResource = firstNumberInAResource; 34 | } 35 | 36 | public int getSecondNumberInAResource() { 37 | return secondNumberInAResource; 38 | } 39 | 40 | public void setSecondNumberInAResource(int secondNumberInAResource) { 41 | this.secondNumberInAResource = secondNumberInAResource; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AResourceWithOneMoreDestinationField.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AResourceWithOneMoreDestinationField { 4 | 5 | private int onlyInAResource; 6 | private int zahl; 7 | private String text; 8 | 9 | public AResourceWithOneMoreDestinationField() { 10 | super(); 11 | } 12 | 13 | public AResourceWithOneMoreDestinationField(int onlyInA, int zahl, String text) { 14 | super(); 15 | this.onlyInAResource = onlyInA; 16 | this.zahl = zahl; 17 | this.text = text; 18 | } 19 | 20 | public int getOnlyInAResource() { 21 | return onlyInAResource; 22 | } 23 | 24 | public void setOnlyInAResource(int onlyInAResource) { 25 | this.onlyInAResource = onlyInAResource; 26 | } 27 | 28 | public int getZahl() { 29 | return zahl; 30 | } 31 | 32 | public void setZahl(int zahl) { 33 | this.zahl = zahl; 34 | } 35 | 36 | public String getText() { 37 | return text; 38 | } 39 | 40 | public void setText(String text) { 41 | this.text = text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AResourceWithOneMoreSourceField.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AResourceWithOneMoreSourceField { 4 | 5 | private int zahl; 6 | private String text; 7 | 8 | public AResourceWithOneMoreSourceField() { 9 | super(); 10 | } 11 | 12 | public AResourceWithOneMoreSourceField(int zahl, String text) { 13 | super(); 14 | this.zahl = zahl; 15 | this.text = text; 16 | } 17 | 18 | public int getZahl() { 19 | return zahl; 20 | } 21 | 22 | public void setZahl(int zahl) { 23 | this.zahl = zahl; 24 | } 25 | 26 | public String getText() { 27 | return text; 28 | } 29 | 30 | public void setText(String text) { 31 | this.text = text; 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * 37 | * @see java.lang.Object#toString() 38 | */ 39 | @Override 40 | public String toString() { 41 | return "AResourceWithOneMoreSourceField [zahl=" + zahl + ", text=" + text + "]"; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AWithOneMoreDestinationField.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AWithOneMoreDestinationField { 4 | 5 | private int zahl; 6 | private String text; 7 | 8 | public AWithOneMoreDestinationField() { 9 | super(); 10 | } 11 | 12 | public AWithOneMoreDestinationField(int zahl, String text) { 13 | super(); 14 | this.zahl = zahl; 15 | this.text = text; 16 | } 17 | 18 | public int getZahl() { 19 | return zahl; 20 | } 21 | 22 | public void setZahl(int zahl) { 23 | this.zahl = zahl; 24 | } 25 | 26 | public String getText() { 27 | return text; 28 | } 29 | 30 | public void setText(String text) { 31 | this.text = text; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/AWithOneMoreSourceField.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class AWithOneMoreSourceField { 4 | 5 | private int onlyInA; 6 | private int zahl; 7 | private String text; 8 | 9 | public AWithOneMoreSourceField() { 10 | super(); 11 | } 12 | 13 | public AWithOneMoreSourceField(int onlyInA, int zahl, String text) { 14 | super(); 15 | this.onlyInA = onlyInA; 16 | this.zahl = zahl; 17 | this.text = text; 18 | } 19 | 20 | public int getOnlyInA() { 21 | return onlyInA; 22 | } 23 | 24 | public void setOnlyInA(int onlyInA) { 25 | this.onlyInA = onlyInA; 26 | } 27 | 28 | public int getZahl() { 29 | return zahl; 30 | } 31 | 32 | public void setZahl(int zahl) { 33 | this.zahl = zahl; 34 | } 35 | 36 | public String getText() { 37 | return text; 38 | } 39 | 40 | public void setText(String text) { 41 | this.text = text; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * 47 | * @see java.lang.Object#toString() 48 | */ 49 | @Override 50 | public String toString() { 51 | return "AWithOneMoreSourceField [onlyInA=" + onlyInA + ", zahl=" + zahl + ", text=" + text + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/basic/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.basic; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public B() { 10 | super(); 11 | } 12 | 13 | public B(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "B [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/builder/BuilderTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.builder; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.AssertMapping; 8 | import com.remondis.remap.Mapper; 9 | import com.remondis.remap.Mapping; 10 | import com.remondis.remap.MappingException; 11 | 12 | public class BuilderTest { 13 | 14 | private static final long IDENTIFIER = 4L; 15 | private static final String NAME = "Bob"; 16 | 17 | @Test 18 | public void shouldMapToDestinationFromBuilder() { 19 | 20 | Mapper mapper = Mapping.from(BuilderModel.class) 21 | .to(DestinationModel.class) 22 | .mapper(); 23 | 24 | BuilderModel builderModel = new BuilderModel.BuilderModelBuilder(NAME).field(IDENTIFIER) 25 | .build(); 26 | 27 | DestinationModel destinationModel = mapper.map(builderModel); 28 | 29 | assertEquals(NAME, destinationModel.getName()); 30 | assertEquals(IDENTIFIER, (long) destinationModel.getField()); 31 | 32 | AssertMapping.of(mapper) 33 | .ensure(); 34 | } 35 | 36 | @Test(expected = MappingException.class) 37 | public void failsWhenMapFromBuilder() { 38 | Mapping.from(DestinationModel.class) 39 | .to(BuilderModel.class) 40 | .mapper(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/builder/DestinationModel.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.builder; 2 | 3 | public class DestinationModel { 4 | 5 | private Long field; 6 | private String name; 7 | 8 | public Long getField() { 9 | return field; 10 | } 11 | 12 | public void setField(Long field) { 13 | this.field = field; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((field == null) ? 0 : field.hashCode()); 29 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 30 | return result; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object obj) { 35 | if (this == obj) 36 | return true; 37 | if (obj == null) 38 | return false; 39 | if (getClass() != obj.getClass()) 40 | return false; 41 | DestinationModel other = (DestinationModel) obj; 42 | if (field == null) { 43 | if (other.field != null) 44 | return false; 45 | } else if (!field.equals(other.field)) 46 | return false; 47 | if (name == null) { 48 | if (other.name != null) 49 | return false; 50 | } else if (!name.equals(other.name)) 51 | return false; 52 | return true; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections; 2 | 3 | import java.util.Arrays; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | import com.remondis.remap.basic.B; 8 | 9 | public class A { 10 | 11 | private List bs = new LinkedList<>(); 12 | 13 | public A() { 14 | super(); 15 | } 16 | 17 | public void addBs(B... bs) { 18 | this.bs = Arrays.asList(bs); 19 | } 20 | 21 | public List getBs() { 22 | return bs; 23 | } 24 | 25 | public void setBs(List bs) { 26 | this.bs = bs; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((bs == null) ? 0 : bs.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A other = (A) obj; 46 | if (bs == null) { 47 | if (other.bs != null) 48 | return false; 49 | } else if (!bs.equals(other.bs)) 50 | return false; 51 | return true; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "A [bs=" + bs + "]"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import com.remondis.remap.basic.BResource; 7 | 8 | public class AResource { 9 | 10 | private List bs; 11 | 12 | public AResource() { 13 | super(); 14 | } 15 | 16 | public void addBs(BResource... bs) { 17 | this.bs = Arrays.asList(bs); 18 | } 19 | 20 | public List getBs() { 21 | return bs; 22 | } 23 | 24 | public void setBs(List bs) { 25 | this.bs = bs; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | final int prime = 31; 31 | int result = 1; 32 | result = prime * result + ((bs == null) ? 0 : bs.hashCode()); 33 | return result; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (this == obj) 39 | return true; 40 | if (obj == null) 41 | return false; 42 | if (getClass() != obj.getClass()) 43 | return false; 44 | AResource other = (AResource) obj; 45 | if (bs == null) { 46 | if (other.bs != null) 47 | return false; 48 | } else if (!bs.equals(other.bs)) 49 | return false; 50 | return true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "AResource [bs=" + bs + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/fromSetToList/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.fromSetToList; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class A { 7 | 8 | private Set as = new HashSet<>(); 9 | 10 | public A(Set as) { 11 | super(); 12 | this.as = as; 13 | } 14 | 15 | public A() { 16 | super(); 17 | } 18 | 19 | public void add(A1 a) { 20 | as.add(a); 21 | } 22 | 23 | public Set getAs() { 24 | return as; 25 | } 26 | 27 | public void setAs(Set as) { 28 | this.as = as; 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | final int prime = 31; 34 | int result = 1; 35 | result = prime * result + ((as == null) ? 0 : as.hashCode()); 36 | return result; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (this == obj) 42 | return true; 43 | if (obj == null) 44 | return false; 45 | if (getClass() != obj.getClass()) 46 | return false; 47 | A other = (A) obj; 48 | if (as == null) { 49 | if (other.as != null) 50 | return false; 51 | } else if (!as.equals(other.as)) 52 | return false; 53 | return true; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "A [as=" + as + "]"; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/fromSetToList/A1.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.fromSetToList; 2 | 3 | public class A1 { 4 | 5 | private String string; 6 | 7 | public A1(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A1() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | A1 other = (A1) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "A1 [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/fromSetToList/A2.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.fromSetToList; 2 | 3 | public class A2 { 4 | 5 | private String string; 6 | 7 | public A2(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A2() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | A2 other = (A2) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "A2 [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/fromSetToList/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.fromSetToList; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class AMapped { 7 | 8 | private List as = new LinkedList<>(); 9 | 10 | public AMapped(List as) { 11 | super(); 12 | this.as = as; 13 | } 14 | 15 | public AMapped() { 16 | super(); 17 | } 18 | 19 | public void add(A2 a) { 20 | as.add(a); 21 | } 22 | 23 | public List getAs() { 24 | return as; 25 | } 26 | 27 | public void setAs(List as) { 28 | this.as = as; 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | final int prime = 31; 34 | int result = 1; 35 | result = prime * result + ((as == null) ? 0 : as.hashCode()); 36 | return result; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (this == obj) 42 | return true; 43 | if (obj == null) 44 | return false; 45 | if (getClass() != obj.getClass()) 46 | return false; 47 | AMapped other = (AMapped) obj; 48 | if (as == null) { 49 | if (other.as != null) 50 | return false; 51 | } else if (!as.equals(other.as)) 52 | return false; 53 | return true; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "AMapped [as=" + as + "]"; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/fromSetToList/FromSetToListTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.fromSetToList; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.junit.Test; 8 | 9 | import com.remondis.remap.Mapper; 10 | import com.remondis.remap.Mapping; 11 | 12 | public class FromSetToListTest { 13 | 14 | @Test 15 | public void test() { 16 | A a = new A(); 17 | a.add(new A1("a1")); 18 | a.add(new A1("a2")); 19 | a.add(new A1("a3")); 20 | 21 | Mapper mapper = Mapping.from(A.class) 22 | .to(AMapped.class) 23 | .useMapper(Mapping.from(A1.class) 24 | .to(A2.class) 25 | .mapper()) 26 | .mapper(); 27 | 28 | AMapped aMapped = mapper.map(a); 29 | assertThat(aMapped.getAs()).isInstanceOf(List.class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/listAndMaps/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.listAndMaps; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class A { 8 | 9 | private List> nestedLists; 10 | 11 | public A() { 12 | super(); 13 | } 14 | 15 | public void addNestedLists(@SuppressWarnings("unchecked") Map... lists) { 16 | this.nestedLists = Arrays.asList(lists); 17 | } 18 | 19 | /** 20 | * @return the nestedLists 21 | */ 22 | public List> getNestedLists() { 23 | return nestedLists; 24 | } 25 | 26 | /** 27 | * @param nestedLists 28 | * the nestedLists to set 29 | */ 30 | public void setNestedLists(List> nestedLists) { 31 | this.nestedLists = nestedLists; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "A [nestedLists=" + nestedLists + "]"; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | final int prime = 31; 42 | int result = 1; 43 | result = prime * result + ((nestedLists == null) ? 0 : nestedLists.hashCode()); 44 | return result; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) { 49 | if (this == obj) 50 | return true; 51 | if (obj == null) 52 | return false; 53 | if (getClass() != obj.getClass()) 54 | return false; 55 | A other = (A) obj; 56 | if (nestedLists == null) { 57 | if (other.nestedLists != null) 58 | return false; 59 | } else if (!nestedLists.equals(other.nestedLists)) 60 | return false; 61 | return true; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/listAndMaps/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.listAndMaps; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | public class AResource { 7 | 8 | private Set> nestedLists; 9 | 10 | public AResource() { 11 | super(); 12 | } 13 | 14 | /** 15 | * @return the nestedLists 16 | */ 17 | public Set> getNestedLists() { 18 | return nestedLists; 19 | } 20 | 21 | /** 22 | * @param nestedLists 23 | * the nestedLists to set 24 | */ 25 | public void setNestedLists(Set> nestedLists) { 26 | this.nestedLists = nestedLists; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "AResource [nestedLists=" + nestedLists + "]"; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result + ((nestedLists == null) ? 0 : nestedLists.hashCode()); 39 | return result; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (obj == null) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | AResource other = (AResource) obj; 51 | if (nestedLists == null) { 52 | if (other.nestedLists != null) 53 | return false; 54 | } else if (!nestedLists.equals(other.nestedLists)) 55 | return false; 56 | return true; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/listAndMaps/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.listAndMaps; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public B() { 10 | super(); 11 | } 12 | 13 | public B(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "B [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/listAndMaps/BResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.listAndMaps; 2 | 3 | public class BResource { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public BResource() { 10 | super(); 11 | } 12 | 13 | public BResource(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "BResource [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/nestedCollections/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.nestedCollections; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import com.remondis.remap.basic.B; 8 | 9 | public class A { 10 | 11 | private List> nestedLists; 12 | 13 | public A() { 14 | super(); 15 | } 16 | 17 | public void addNestedLists(@SuppressWarnings("unchecked") Set... lists) { 18 | this.nestedLists = Arrays.asList(lists); 19 | } 20 | 21 | /** 22 | * @return the nestedLists 23 | */ 24 | public List> getNestedLists() { 25 | return nestedLists; 26 | } 27 | 28 | /** 29 | * @param nestedLists 30 | * the nestedLists to set 31 | */ 32 | public void setNestedLists(List> nestedLists) { 33 | this.nestedLists = nestedLists; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "A [nestedLists=" + nestedLists + "]"; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | final int prime = 31; 44 | int result = 1; 45 | result = prime * result + ((nestedLists == null) ? 0 : nestedLists.hashCode()); 46 | return result; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (this == obj) 52 | return true; 53 | if (obj == null) 54 | return false; 55 | if (getClass() != obj.getClass()) 56 | return false; 57 | A other = (A) obj; 58 | if (nestedLists == null) { 59 | if (other.nestedLists != null) 60 | return false; 61 | } else if (!nestedLists.equals(other.nestedLists)) 62 | return false; 63 | return true; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/collections/nestedCollections/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.collections.nestedCollections; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | import com.remondis.remap.basic.BResource; 7 | 8 | public class AResource { 9 | 10 | private Set> nestedLists; 11 | 12 | public AResource() { 13 | super(); 14 | } 15 | 16 | /** 17 | * @return the nestedLists 18 | */ 19 | public Set> getNestedLists() { 20 | return nestedLists; 21 | } 22 | 23 | /** 24 | * @param nestedLists 25 | * the nestedLists to set 26 | */ 27 | public void setNestedLists(Set> nestedLists) { 28 | this.nestedLists = nestedLists; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "AResource [nestedLists=" + nestedLists + "]"; 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = 1; 40 | result = prime * result + ((nestedLists == null) ? 0 : nestedLists.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | AResource other = (AResource) obj; 53 | if (nestedLists == null) { 54 | if (other.nestedLists != null) 55 | return false; 56 | } else if (!nestedLists.equals(other.nestedLists)) 57 | return false; 58 | return true; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/copyObjects/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.copyObjects; 2 | 3 | public class A { 4 | 5 | private B b; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public A(B b) { 12 | super(); 13 | this.b = b; 14 | } 15 | 16 | public B getB() { 17 | return b; 18 | } 19 | 20 | public void setB(B b) { 21 | this.b = b; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((b == null) ? 0 : b.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | A other = (A) obj; 41 | if (b == null) { 42 | if (other.b != null) 43 | return false; 44 | } else if (!b.equals(other.b)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "A [b=" + b + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/copyObjects/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.copyObjects; 2 | 3 | public class AResource { 4 | 5 | private B b; 6 | 7 | public AResource() { 8 | super(); 9 | } 10 | 11 | public AResource(B b) { 12 | super(); 13 | this.b = b; 14 | } 15 | 16 | public B getB() { 17 | return b; 18 | } 19 | 20 | public void setB(B b) { 21 | this.b = b; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((b == null) ? 0 : b.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | AResource other = (AResource) obj; 41 | if (b == null) { 42 | if (other.b != null) 43 | return false; 44 | } else if (!b.equals(other.b)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "A [b=" + b + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/copyObjects/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.copyObjects; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B() { 8 | super(); 9 | } 10 | 11 | public B(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | B other = (B) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "B [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/copyObjects/CopyObjectTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.copyObjects; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | 10 | import com.remondis.remap.Mapper; 11 | import com.remondis.remap.Mapping; 12 | 13 | @Ignore 14 | public class CopyObjectTest { 15 | 16 | private static final String EXPECTED_STRING = "string"; 17 | 18 | @Test 19 | public void shouldCopyObjectsOfSameType() { 20 | B b = new B(EXPECTED_STRING); 21 | A a = new A(b); 22 | 23 | Mapper mapper = Mapping.from(A.class) 24 | .to(AResource.class) 25 | .mapper(); 26 | AResource ar = mapper.map(a); 27 | assertTrue(b == a.getB()); 28 | assertFalse(b == ar.getB()); 29 | assertEquals(b, ar.getB()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/defaultMethods/DefaultMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.defaultMethods; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | 10 | public class DefaultMethodTest { 11 | @Test 12 | public void test_defaults_methods() { 13 | Mapper mapper = Mapping.from(Interface.class) 14 | .to(DestinationBean.class) 15 | .mapper(); 16 | 17 | Interface source = new SourceBeanWithDefaults(); 18 | DestinationBean destinationBean = mapper.map(source); 19 | assertEquals(destinationBean.getString(), source.getString()); 20 | } 21 | 22 | @Test 23 | public void test_withOverridden_defaults_methods() { 24 | Mapper mapper = Mapping.from(Interface.class) 25 | .to(DestinationBean.class) 26 | .mapper(); 27 | 28 | Interface source = new SourceBean("string"); 29 | DestinationBean destinationBean = mapper.map(source); 30 | assertEquals(destinationBean.getString(), source.getString()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/defaultMethods/DestinationBean.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.defaultMethods; 2 | 3 | public class DestinationBean implements Interface { 4 | 5 | private String string; 6 | 7 | public DestinationBean(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public DestinationBean() { 13 | super(); 14 | } 15 | 16 | @Override 17 | public String getString() { 18 | return string; 19 | } 20 | 21 | @Override 22 | public void setString(String string) { 23 | this.string = string; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | final int prime = 31; 29 | int result = 1; 30 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | DestinationBean other = (DestinationBean) obj; 43 | if (string == null) { 44 | if (other.string != null) 45 | return false; 46 | } else if (!string.equals(other.string)) 47 | return false; 48 | return true; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "SourceBean [string=" + string + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/defaultMethods/Interface.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.defaultMethods; 2 | 3 | public interface Interface { 4 | 5 | public static final String DEFAULT_STRING = "defaultString"; 6 | 7 | public default String getString() { 8 | return DEFAULT_STRING; 9 | } 10 | 11 | public default void setString(String string) { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/defaultMethods/SourceBean.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.defaultMethods; 2 | 3 | public class SourceBean implements Interface { 4 | 5 | private String string; 6 | 7 | public SourceBean(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public SourceBean() { 13 | super(); 14 | } 15 | 16 | @Override 17 | public String getString() { 18 | return string; 19 | } 20 | 21 | @Override 22 | public void setString(String string) { 23 | this.string = string; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | final int prime = 31; 29 | int result = 1; 30 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | SourceBean other = (SourceBean) obj; 43 | if (string == null) { 44 | if (other.string != null) 45 | return false; 46 | } else if (!string.equals(other.string)) 47 | return false; 48 | return true; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "SourceBean [string=" + string + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/defaultMethods/SourceBeanWithDefaults.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.defaultMethods; 2 | 3 | public class SourceBeanWithDefaults implements Interface { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/demo/Customer.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.demo; 2 | 3 | public class Customer { 4 | 5 | private String title; 6 | private String forename; 7 | private String name; 8 | private String gender; 9 | private String address; 10 | 11 | public Customer() { 12 | super(); 13 | } 14 | 15 | public Customer(String title, String forename, String name, String gender, String address) { 16 | super(); 17 | this.title = title; 18 | this.forename = forename; 19 | this.name = name; 20 | this.gender = gender; 21 | this.address = address; 22 | } 23 | 24 | public String getTitle() { 25 | return title; 26 | } 27 | 28 | public void setTitle(String title) { 29 | this.title = title; 30 | } 31 | 32 | public String getForename() { 33 | return forename; 34 | } 35 | 36 | public void setForename(String forename) { 37 | this.forename = forename; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | 48 | public String getGender() { 49 | return gender; 50 | } 51 | 52 | public void setGender(String gender) { 53 | this.gender = gender; 54 | } 55 | 56 | public String getAddress() { 57 | return address; 58 | } 59 | 60 | public void setAddress(String address) { 61 | this.address = address; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/demo/Gender.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.demo; 2 | 3 | public enum Gender { 4 | MALE, 5 | FEMALE; 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/demo/v2/Address.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.demo.v2; 2 | 3 | public class Address { 4 | 5 | String street; 6 | 7 | String houseNumber; 8 | 9 | String zipCode; 10 | 11 | String city; 12 | 13 | String email; 14 | 15 | public Address() { 16 | super(); 17 | } 18 | 19 | public Address(String street, String houseNumber, String zipCode, String city, String email) { 20 | super(); 21 | this.street = street; 22 | this.houseNumber = houseNumber; 23 | this.zipCode = zipCode; 24 | this.city = city; 25 | this.email = email; 26 | } 27 | 28 | public String getEmail() { 29 | return email; 30 | } 31 | 32 | public void setEmail(String email) { 33 | this.email = email; 34 | } 35 | 36 | public String getStreet() { 37 | return street; 38 | } 39 | 40 | public void setStreet(String street) { 41 | this.street = street; 42 | } 43 | 44 | public String getHouseNumber() { 45 | return houseNumber; 46 | } 47 | 48 | public void setHouseNumber(String houseNumber) { 49 | this.houseNumber = houseNumber; 50 | } 51 | 52 | public String getZipCode() { 53 | return zipCode; 54 | } 55 | 56 | public void setZipCode(String zipCode) { 57 | this.zipCode = zipCode; 58 | } 59 | 60 | public String getCity() { 61 | return city; 62 | } 63 | 64 | public void setCity(String city) { 65 | this.city = city; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "Address [street=" + street + ", houseNumber=" + houseNumber + ", zipCode=" + zipCode + ", city=" + city 71 | + "]"; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/demo/v2/MapPersonTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.demo.v2; 2 | 3 | import static java.time.Period.between; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.time.LocalDate; 7 | 8 | import org.junit.Test; 9 | 10 | import com.remondis.remap.Mapper; 11 | import com.remondis.remap.Mapping; 12 | 13 | public class MapPersonTest { 14 | 15 | @Test 16 | public void shouldMapToPersonView() { 17 | Person person = new Person("Mustermann", "Max", LocalDate.of(1988, 10, 9), 18 | new Address("Somewhere", "17a", "12346", "Nowhere", "max.mustermann@example.org"), "DE-71545498927"); 19 | 20 | Mapper mapper = Mapping.from(Person.class) 21 | .to(PersonView.class) 22 | // Rename a field 23 | .reassign(Person::getName) 24 | .to(PersonView::getSurname) 25 | // Optional field (may be null) 26 | .replace(Person::getBirthday, PersonView::getAge) 27 | .withSkipWhenNull(birthday -> between(birthday, LocalDate.of(2019, 10, 9)).getYears()) 28 | // Optional field (may be null) 29 | .replace(Person::getAddress, PersonView::getEmail) 30 | .withSkipWhenNull(Address::getEmail) 31 | // Hide tax id 32 | .omitInSource(Person::getTaxId) 33 | .mapper(); 34 | 35 | PersonView personView = mapper.map(person); 36 | assertEquals("Max", personView.getForname()); 37 | assertEquals("Mustermann", personView.getSurname()); 38 | assertEquals(31, personView.getAge()); 39 | assertEquals("max.mustermann@example.org", personView.getEmail()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/demo/v2/PersonView.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.demo.v2; 2 | 3 | public class PersonView { 4 | private String forname; 5 | private String surname; 6 | 7 | private int age; 8 | 9 | private String email; 10 | 11 | public PersonView() { 12 | super(); 13 | } 14 | 15 | public String getForname() { 16 | return forname; 17 | } 18 | 19 | public void setForname(String forname) { 20 | this.forname = forname; 21 | } 22 | 23 | public String getSurname() { 24 | return surname; 25 | } 26 | 27 | public void setSurname(String surname) { 28 | this.surname = surname; 29 | } 30 | 31 | public int getAge() { 32 | return age; 33 | } 34 | 35 | public void setAge(int age) { 36 | this.age = age; 37 | } 38 | 39 | public String getEmail() { 40 | return email; 41 | } 42 | 43 | public void setEmail(String email) { 44 | this.email = email; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "PersonView [forname=" + forname + ", surname=" + surname + ", age=" + age + ", email=" + email + "]"; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/enums/EnumsTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.enums; 2 | 3 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import org.junit.Test; 7 | 8 | import com.remondis.remap.Mapper; 9 | import com.remondis.remap.Mapping; 10 | import com.remondis.remap.MappingException; 11 | 12 | public class EnumsTest { 13 | 14 | @Test 15 | public void shouldMapEnums() { 16 | Mapper mapper = Mapping.from(Person.class) 17 | .to(PersonResource.class) 18 | .mapper(); 19 | 20 | String forename = "Armin"; 21 | String name = "Loaf"; 22 | Gender gender = Gender.MALE; 23 | Person person = new Person(forename, name, gender); 24 | PersonResource pr = mapper.map(person); 25 | 26 | assertEquals(forename, pr.getForename()); 27 | assertEquals(name, pr.getName()); 28 | assertEquals(gender, pr.getGender()); 29 | } 30 | 31 | @Test 32 | public void shouldThrowMappingException() { 33 | assertThatThrownBy(() -> Mapping.from(Person.class) 34 | .to(AnotherResource.class) 35 | .mapper()).isInstanceOf(MappingException.class) 36 | .hasMessageStartingWith("No mapper found for type mapping from "); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/enums/Gender.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.enums; 2 | 3 | public enum Gender { 4 | MALE, 5 | FEMALE; 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/enums/Gender2.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.enums; 2 | 3 | public enum Gender2 { 4 | MALE, 5 | FEMALE; 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/flatCollectionMapping/DemoTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.flatCollectionMapping; 2 | 3 | import java.util.function.Function; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.AssertMapping; 8 | import com.remondis.remap.Mapper; 9 | import com.remondis.remap.Mapping; 10 | 11 | public class DemoTest { 12 | 13 | @Test 14 | public void replaceCollection() { 15 | Mapper mapper = Mapping.from(Source.class) 16 | .to(Destination.class) 17 | .replaceCollection(Source::getIds, Destination::getIds) 18 | .with(newId()) 19 | .mapper(); 20 | 21 | AssertMapping.of(mapper) 22 | .expectReplaceCollection(Source::getIds, Destination::getIds) 23 | .andTest(newId()) 24 | .ensure(); 25 | } 26 | 27 | public Function newId() { 28 | return id -> new Id(id); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/flatCollectionMapping/Destination.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.flatCollectionMapping; 2 | 3 | import java.util.List; 4 | 5 | public class Destination { 6 | 7 | private List ids; 8 | 9 | public Destination(List ids) { 10 | super(); 11 | this.ids = ids; 12 | } 13 | 14 | public Destination() { 15 | super(); 16 | } 17 | 18 | public List getIds() { 19 | return ids; 20 | } 21 | 22 | public void setIds(List ids) { 23 | this.ids = ids; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/flatCollectionMapping/Id.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.flatCollectionMapping; 2 | 3 | public class Id { 4 | private Long id; 5 | 6 | public Id(Long id) { 7 | super(); 8 | this.id = id; 9 | } 10 | 11 | public Id() { 12 | super(); 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | final int prime = 31; 26 | int result = 1; 27 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 28 | return result; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (this == obj) 34 | return true; 35 | if (obj == null) 36 | return false; 37 | if (getClass() != obj.getClass()) 38 | return false; 39 | Id other = (Id) obj; 40 | if (id == null) { 41 | if (other.id != null) 42 | return false; 43 | } else if (!id.equals(other.id)) 44 | return false; 45 | return true; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Id [id=" + id + "]"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/flatCollectionMapping/Source.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.flatCollectionMapping; 2 | 3 | import java.util.List; 4 | 5 | public class Source { 6 | 7 | private List ids; 8 | 9 | public Source() { 10 | super(); 11 | } 12 | 13 | public Source(List ids) { 14 | super(); 15 | this.ids = ids; 16 | } 17 | 18 | public List getIds() { 19 | return ids; 20 | } 21 | 22 | public void setIds(List ids) { 23 | this.ids = ids; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | final int prime = 31; 29 | int result = 1; 30 | result = prime * result + ((ids == null) ? 0 : ids.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | Source other = (Source) obj; 43 | if (ids == null) { 44 | if (other.ids != null) 45 | return false; 46 | } else if (!ids.equals(other.ids)) 47 | return false; 48 | return true; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "Source [ids=" + ids + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/fluent/FluentSetterDto.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.fluent; 2 | 3 | public class FluentSetterDto { 4 | 5 | private Integer integer; 6 | private int i; 7 | private String s; 8 | private boolean b1; 9 | private boolean b2; 10 | 11 | public Integer getInteger() { 12 | return integer; 13 | } 14 | 15 | public FluentSetterDto setInteger(Integer integer) { 16 | this.integer = integer; 17 | return this; 18 | } 19 | 20 | public int getI() { 21 | return integer; 22 | } 23 | 24 | public FluentSetterDto setI(int i) { 25 | this.i = i; 26 | return this; 27 | } 28 | 29 | public String getS() { 30 | return s; 31 | } 32 | 33 | public FluentSetterDto setS(String s) { 34 | this.s = s; 35 | return this; 36 | } 37 | 38 | public boolean getB1() { 39 | return b1; 40 | } 41 | 42 | public FluentSetterDto setB1(boolean b) { 43 | this.b1 = b; 44 | return this; 45 | } 46 | 47 | public boolean isB2() { 48 | return b2; 49 | } 50 | 51 | public FluentSetterDto setB2(boolean b) { 52 | this.b2 = b; 53 | return this; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/generics/Bean.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.generics; 2 | 3 | public class Bean { 4 | 5 | private T object; 6 | 7 | public Bean(T object) { 8 | super(); 9 | this.object = object; 10 | } 11 | 12 | public Bean() { 13 | } 14 | 15 | public T getObject() { 16 | return object; 17 | } 18 | 19 | public void setObject(T object) { 20 | this.object = object; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/generics/Bean2.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.generics; 2 | 3 | public class Bean2 { 4 | 5 | private T reference; 6 | 7 | public Bean2() { 8 | } 9 | 10 | public Bean2(T reference) { 11 | super(); 12 | this.reference = reference; 13 | } 14 | 15 | public T getReference() { 16 | return reference; 17 | } 18 | 19 | public void setReference(T reference) { 20 | this.reference = reference; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/generics/Identifiable.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.generics; 2 | 3 | public interface Identifiable { 4 | 5 | public I getId(); 6 | 7 | public void setId(I id); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/generics/IdentifiableImpl.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.generics; 2 | 3 | public class IdentifiableImpl implements Identifiable { 4 | 5 | private Long id; 6 | 7 | public IdentifiableImpl() { 8 | super(); 9 | } 10 | 11 | public IdentifiableImpl(Long id) { 12 | super(); 13 | this.id = id; 14 | } 15 | 16 | @Override 17 | public Long getId() { 18 | return id; 19 | } 20 | 21 | @Override 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/customTypeConversions/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.customTypeConversions; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private List addresses; 8 | 9 | public A() { 10 | super(); 11 | } 12 | 13 | public A(List addresses) { 14 | super(); 15 | this.addresses = addresses; 16 | } 17 | 18 | public List getAddresses() { 19 | return addresses; 20 | } 21 | 22 | public void setAddresses(List addresses) { 23 | this.addresses = addresses; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/customTypeConversions/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.customTypeConversions; 2 | 3 | import java.util.List; 4 | 5 | public class AResource { 6 | 7 | private List addresses; 8 | 9 | public AResource() { 10 | super(); 11 | } 12 | 13 | public AResource(List addresses) { 14 | super(); 15 | this.addresses = addresses; 16 | } 17 | 18 | public List getAddresses() { 19 | return addresses; 20 | } 21 | 22 | public void setAddresses(List addresses) { 23 | this.addresses = addresses; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/differentFieldNames/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.differentFieldNames; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private B b; 8 | private List bs; 9 | 10 | public A() { 11 | super(); 12 | } 13 | 14 | public A(B b, List bs) { 15 | super(); 16 | this.b = b; 17 | this.bs = bs; 18 | } 19 | 20 | public B getB() { 21 | return b; 22 | } 23 | 24 | public void setB(B b) { 25 | this.b = b; 26 | } 27 | 28 | public List getBs() { 29 | return bs; 30 | } 31 | 32 | public void setBs(List bs) { 33 | this.bs = bs; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/differentFieldNames/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.differentFieldNames; 2 | 3 | import java.util.List; 4 | 5 | public class AResource { 6 | 7 | private BResource bResource; 8 | private List bResources; 9 | 10 | public AResource() { 11 | super(); 12 | } 13 | 14 | public AResource(BResource bResource, List bResources) { 15 | super(); 16 | this.bResource = bResource; 17 | this.bResources = bResources; 18 | } 19 | 20 | public BResource getbResource() { 21 | return bResource; 22 | } 23 | 24 | public void setbResource(BResource bResource) { 25 | this.bResource = bResource; 26 | } 27 | 28 | public List getbResources() { 29 | return bResources; 30 | } 31 | 32 | public void setbResources(List bResources) { 33 | this.bResources = bResources; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/differentFieldNames/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.differentFieldNames; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/differentFieldNames/BResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.differentFieldNames; 2 | 3 | public class BResource { 4 | 5 | private String anotherString; 6 | 7 | public BResource(String string) { 8 | super(); 9 | this.anotherString = string; 10 | } 11 | 12 | public BResource() { 13 | super(); 14 | } 15 | 16 | public String getAnotherString() { 17 | return anotherString; 18 | } 19 | 20 | public void setAnotherString(String anotherString) { 21 | this.anotherString = anotherString; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldAndType/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldAndType; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private B b; 8 | private List bs; 9 | 10 | public A() { 11 | super(); 12 | } 13 | 14 | public A(B b, List bs) { 15 | super(); 16 | this.b = b; 17 | this.bs = bs; 18 | } 19 | 20 | public B getB() { 21 | return b; 22 | } 23 | 24 | public void setB(B b) { 25 | this.b = b; 26 | } 27 | 28 | public List getBs() { 29 | return bs; 30 | } 31 | 32 | public void setBs(List bs) { 33 | this.bs = bs; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldAndType/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldAndType; 2 | 3 | import java.util.List; 4 | 5 | public class AResource { 6 | 7 | private B b; 8 | private List bs; 9 | 10 | public AResource(B b, List bs) { 11 | super(); 12 | this.b = b; 13 | this.bs = bs; 14 | } 15 | 16 | public AResource() { 17 | super(); 18 | } 19 | 20 | public B getB() { 21 | return b; 22 | } 23 | 24 | public void setB(B b) { 25 | this.b = b; 26 | } 27 | 28 | public List getBs() { 29 | return bs; 30 | } 31 | 32 | public void setBs(List bs) { 33 | this.bs = bs; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldAndType/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldAndType; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldAndType/ImplicitMappingTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldAndType; 2 | 3 | import static java.util.Arrays.asList; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import java.util.List; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import com.remondis.remap.Mapper; 13 | import com.remondis.remap.Mapping; 14 | 15 | /** 16 | * A mapping of property B->B' is performed implicitly if the field names are equal and [ the type is equal OR a type 17 | * mapper was registered that maps type(b) -> type(b') ]. 18 | */ 19 | public class ImplicitMappingTest { 20 | private Mapper aMapper; 21 | 22 | @Before 23 | public void setup() { 24 | this.aMapper = Mapping.from(A.class) 25 | .to(AResource.class) 26 | .mapper(); 27 | } 28 | 29 | @Test 30 | public void mappingImplicit() { 31 | AResource aResource = aMapper 32 | .map(new A(new B("string"), asList(new B("string"), new B("string1"), new B("string2")))); 33 | assertNotNull(aResource.getB()); 34 | List bs = aResource.getBs(); 35 | assertNotNull(bs); 36 | assertEquals(3, bs.size()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldNames/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldNames; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private B b; 8 | private List bs; 9 | 10 | public A() { 11 | super(); 12 | } 13 | 14 | public A(B b, List bs) { 15 | super(); 16 | this.b = b; 17 | this.bs = bs; 18 | } 19 | 20 | public B getB() { 21 | return b; 22 | } 23 | 24 | public void setB(B b) { 25 | this.b = b; 26 | } 27 | 28 | public List getBs() { 29 | return bs; 30 | } 31 | 32 | public void setBs(List bs) { 33 | this.bs = bs; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldNames/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldNames; 2 | 3 | import java.util.List; 4 | 5 | public class AResource { 6 | 7 | private BResource b; 8 | private List bs; 9 | 10 | public AResource(BResource b, List bs) { 11 | super(); 12 | this.b = b; 13 | this.bs = bs; 14 | } 15 | 16 | public AResource() { 17 | super(); 18 | } 19 | 20 | public BResource getB() { 21 | return b; 22 | } 23 | 24 | public void setB(BResource b) { 25 | this.b = b; 26 | } 27 | 28 | public List getBs() { 29 | return bs; 30 | } 31 | 32 | public void setBs(List bs) { 33 | this.bs = bs; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldNames/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldNames; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/implicitMappings/sameFieldNames/BResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.implicitMappings.sameFieldNames; 2 | 3 | public class BResource { 4 | 5 | private String anotherString; 6 | 7 | public BResource(String string) { 8 | super(); 9 | this.anotherString = string; 10 | } 11 | 12 | public BResource() { 13 | super(); 14 | } 15 | 16 | public String getAnotherString() { 17 | return anotherString; 18 | } 19 | 20 | public void setAnotherString(String anotherString) { 21 | this.anotherString = anotherString; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/inheritance/Child.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.inheritance; 2 | 3 | import com.remondis.remap.basic.B; 4 | 5 | public class Child extends Parent implements ChildInterface { 6 | 7 | private Object object; 8 | private int zahl; 9 | 10 | public Child() { 11 | super(); 12 | } 13 | 14 | public Child(Object shouldNotMap, String string, B field, Object object, int zahl) { 15 | super(shouldNotMap, string, field); 16 | this.object = object; 17 | this.zahl = zahl; 18 | } 19 | 20 | /** 21 | * @return the object 22 | */ 23 | public Object getObject() { 24 | return object; 25 | } 26 | 27 | /** 28 | * @param object 29 | * the object to set 30 | */ 31 | public void setObject(Object object) { 32 | this.object = object; 33 | } 34 | 35 | /** 36 | * @return the zahl 37 | */ 38 | public int getZahl() { 39 | return zahl; 40 | } 41 | 42 | /** 43 | * @param zahl 44 | * the zahl to set 45 | */ 46 | public void setZahl(int zahl) { 47 | this.zahl = zahl; 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * 53 | * @see java.lang.Object#toString() 54 | */ 55 | @Override 56 | public String toString() { 57 | return "Child [object=" + object + ", zahl=" + zahl + "]"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/inheritance/ChildInterface.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.inheritance; 2 | 3 | public interface ChildInterface extends ParentInterface { 4 | 5 | /** 6 | * @return the object 7 | */ 8 | Object getObject(); 9 | 10 | /** 11 | * @return the zahl 12 | */ 13 | int getZahl(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/inheritance/ChildResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.inheritance; 2 | 3 | import com.remondis.remap.basic.BResource; 4 | 5 | public class ChildResource extends ParentResource { 6 | 7 | private Object object; 8 | private int zahl; 9 | 10 | public ChildResource() { 11 | super(); 12 | } 13 | 14 | public ChildResource(Object shouldNotMap, String string, BResource field, Object object, int zahl) { 15 | super(shouldNotMap, string, field); 16 | this.object = object; 17 | this.zahl = zahl; 18 | } 19 | 20 | /** 21 | * @return the object 22 | */ 23 | public Object getObject() { 24 | return object; 25 | } 26 | 27 | /** 28 | * @param object 29 | * the object to set 30 | */ 31 | public void setObject(Object object) { 32 | this.object = object; 33 | } 34 | 35 | /** 36 | * @return the zahl 37 | */ 38 | public int getZahl() { 39 | return zahl; 40 | } 41 | 42 | /** 43 | * @param zahl 44 | * the zahl to set 45 | */ 46 | public void setZahl(int zahl) { 47 | this.zahl = zahl; 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * 53 | * @see java.lang.Object#toString() 54 | */ 55 | @Override 56 | public String toString() { 57 | return "ChildResource [object=" + object + ", zahl=" + zahl + "]"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/inheritance/ParentInterface.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.inheritance; 2 | 3 | import com.remondis.remap.basic.B; 4 | 5 | public interface ParentInterface { 6 | 7 | /** 8 | * @return the moreInParent 9 | */ 10 | Object getMoreInParent(); 11 | 12 | /** 13 | * @return the shouldNotMap 14 | */ 15 | Object getShouldNotMap(); 16 | 17 | /** 18 | * @return the string 19 | */ 20 | String getString(); 21 | 22 | /** 23 | * @return the b 24 | */ 25 | B getB(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaceMapping/EntityA.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaceMapping; 2 | 3 | public class EntityA implements HasId { 4 | private String name; 5 | 6 | public EntityA() { 7 | } 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | } -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaceMapping/EntityADTO.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaceMapping; 2 | 3 | public class EntityADTO { 4 | private String name; 5 | 6 | public void setName(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | } -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaceMapping/EntityWithIdDTO.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaceMapping; 2 | 3 | public class EntityWithIdDTO { 4 | private Long id; 5 | private String name; 6 | 7 | public void setId(Long id) { 8 | this.id = id; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | } -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaceMapping/HasId.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaceMapping; 2 | 3 | public interface HasId { 4 | default Long getId() { 5 | return 1L; 6 | } 7 | } -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaces/DestImpl.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaces; 2 | 3 | public class DestImpl implements Destination { 4 | 5 | private String string; 6 | 7 | @Override 8 | public String getStringField() { 9 | return string; 10 | } 11 | 12 | @Override 13 | public void setStringField(String string) { 14 | this.string = string; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaces/Destination.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaces; 2 | 3 | public interface Destination { 4 | 5 | public String getStringField(); 6 | 7 | public void setStringField(String string); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaces/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaces; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | 10 | public class MapperTest { 11 | 12 | private static final String STRING = "aString"; 13 | 14 | @Test 15 | public void shouldSupportInterfaces() { 16 | Mapper mapper = Mapping.from(Source.class) 17 | .to(DestImpl.class) 18 | .reassign(Source::getString) 19 | .to(Destination::getStringField) 20 | .mapper(); 21 | SrcImpl src = new SrcImpl(STRING); 22 | Destination dest = mapper.map(src); 23 | assertEquals(STRING, dest.getStringField()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaces/Source.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaces; 2 | 3 | public interface Source { 4 | 5 | public String getString(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/interfaces/SrcImpl.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.interfaces; 2 | 3 | public class SrcImpl implements Source { 4 | 5 | private String aString; 6 | 7 | public SrcImpl(String aString) { 8 | super(); 9 | this.aString = aString; 10 | } 11 | 12 | @Override 13 | public String getString() { 14 | return aString; 15 | } 16 | 17 | public void setString(String string) { 18 | this.aString = string; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/mapInto/Address.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.mapInto; 2 | 3 | public class Address { 4 | 5 | private Integer houseNumber; 6 | private String street; 7 | private String city; 8 | 9 | public Address(Integer houseNumber, String street, String city) { 10 | super(); 11 | this.houseNumber = houseNumber; 12 | this.street = street; 13 | this.city = city; 14 | } 15 | 16 | public Address() { 17 | super(); 18 | } 19 | 20 | public Integer getHouseNumber() { 21 | return houseNumber; 22 | } 23 | 24 | public void setHouseNumber(Integer houseNumber) { 25 | this.houseNumber = houseNumber; 26 | } 27 | 28 | public String getStreet() { 29 | return street; 30 | } 31 | 32 | public void setStreet(String street) { 33 | this.street = street; 34 | } 35 | 36 | public String getCity() { 37 | return city; 38 | } 39 | 40 | public void setCity(String city) { 41 | this.city = city; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/mapInto/AddressLite.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.mapInto; 2 | 3 | public class AddressLite { 4 | 5 | private String street; 6 | private String city; 7 | 8 | public AddressLite(String street, String city) { 9 | super(); 10 | this.street = street; 11 | this.city = city; 12 | } 13 | 14 | public AddressLite() { 15 | super(); 16 | } 17 | 18 | public String getStreet() { 19 | return street; 20 | } 21 | 22 | public void setStreet(String street) { 23 | this.street = street; 24 | } 25 | 26 | public String getCity() { 27 | return city; 28 | } 29 | 30 | public void setCity(String city) { 31 | this.city = city; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Map; 5 | 6 | import com.remondis.remap.basic.B; 7 | 8 | public class A { 9 | 10 | private Map bmap; 11 | 12 | public A() { 13 | super(); 14 | this.bmap = new Hashtable<>(); 15 | 16 | } 17 | 18 | public A addB(Integer key, B b) { 19 | bmap.put(key, b); 20 | return this; 21 | } 22 | 23 | public Map getBmap() { 24 | return bmap; 25 | } 26 | 27 | public void setBmap(Map bmap) { 28 | this.bmap = bmap; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "A [bmap=" + bmap + "]"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps; 2 | 3 | import java.util.Map; 4 | 5 | import com.remondis.remap.basic.BResource; 6 | 7 | public class AResource { 8 | 9 | private Map bmap; 10 | 11 | public AResource() { 12 | super(); 13 | } 14 | 15 | public Map getBmap() { 16 | return bmap; 17 | } 18 | 19 | public void setBmap(Map bmap) { 20 | this.bmap = bmap; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "A [bmap=" + bmap + "]"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | public class A { 7 | 8 | private List>> list; 9 | 10 | public A(List>> list) { 11 | super(); 12 | this.list = list; 13 | } 14 | 15 | public A() { 16 | super(); 17 | } 18 | 19 | public List>> getList() { 20 | return list; 21 | } 22 | 23 | public void setList(List>> list) { 24 | this.list = list; 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | final int prime = 31; 30 | int result = 1; 31 | result = prime * result + ((list == null) ? 0 : list.hashCode()); 32 | return result; 33 | } 34 | 35 | @Override 36 | public boolean equals(Object obj) { 37 | if (this == obj) 38 | return true; 39 | if (obj == null) 40 | return false; 41 | if (getClass() != obj.getClass()) 42 | return false; 43 | A other = (A) obj; 44 | if (list == null) { 45 | if (other.list != null) 46 | return false; 47 | } else if (!list.equals(other.list)) 48 | return false; 49 | return true; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "A [list=" + list + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | public class AMapped { 8 | 9 | private List>> list; 10 | 11 | public AMapped(List>> list) { 12 | super(); 13 | this.list = list; 14 | } 15 | 16 | public AMapped() { 17 | super(); 18 | } 19 | 20 | public List>> getList() { 21 | return list; 22 | } 23 | 24 | public void setList(List>> list) { 25 | this.list = list; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | final int prime = 31; 31 | int result = 1; 32 | result = prime * result + ((list == null) ? 0 : list.hashCode()); 33 | return result; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (this == obj) 39 | return true; 40 | if (obj == null) 41 | return false; 42 | if (getClass() != obj.getClass()) 43 | return false; 44 | AMapped other = (AMapped) obj; 45 | if (list == null) { 46 | if (other.list != null) 47 | return false; 48 | } else if (!list.equals(other.list)) 49 | return false; 50 | return true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "AMapped [list=" + list + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | B other = (B) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "B [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/BMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | public class BMapped { 4 | 5 | private String string; 6 | 7 | public BMapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public BMapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | BMapped other = (BMapped) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "BMapped [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/C.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | public class C { 4 | 5 | private String string; 6 | 7 | public C(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public C() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | C other = (C) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "C [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/CMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | public class CMapped { 4 | 5 | private String string; 6 | 7 | public CMapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public CMapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | CMapped other = (CMapped) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "CMapped [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/incompatibleListMapTypeValidation/TypeValidationTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.incompatibleListMapTypeValidation; 2 | 3 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapping; 8 | import com.remondis.remap.MappingException; 9 | 10 | public class TypeValidationTest { 11 | 12 | @Test 13 | public void shouldDetectIncompatibleCollections() { 14 | assertThatThrownBy(() -> { 15 | Mapping.from(A.class) 16 | .to(AMapped.class) 17 | .mapper(); 18 | }).isInstanceOf(MappingException.class) 19 | .hasMessageContaining("java.util.Set\n\tto" 20 | + "\n\tjava.util.Map"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | public class A { 8 | 9 | private List>> list; 10 | 11 | public A(List>> list) { 12 | super(); 13 | this.list = list; 14 | } 15 | 16 | public A() { 17 | super(); 18 | } 19 | 20 | public List>> getList() { 21 | return list; 22 | } 23 | 24 | public void setList(List>> list) { 25 | this.list = list; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | final int prime = 31; 31 | int result = 1; 32 | result = prime * result + ((list == null) ? 0 : list.hashCode()); 33 | return result; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (this == obj) 39 | return true; 40 | if (obj == null) 41 | return false; 42 | if (getClass() != obj.getClass()) 43 | return false; 44 | A other = (A) obj; 45 | if (list == null) { 46 | if (other.list != null) 47 | return false; 48 | } else if (!list.equals(other.list)) 49 | return false; 50 | return true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "A [list=" + list + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | public class AMapped { 8 | 9 | private List>> list; 10 | 11 | public AMapped(List>> list) { 12 | super(); 13 | this.list = list; 14 | } 15 | 16 | public AMapped() { 17 | super(); 18 | } 19 | 20 | public List>> getList() { 21 | return list; 22 | } 23 | 24 | public void setList(List>> list) { 25 | this.list = list; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | final int prime = 31; 31 | int result = 1; 32 | result = prime * result + ((list == null) ? 0 : list.hashCode()); 33 | return result; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (this == obj) 39 | return true; 40 | if (obj == null) 41 | return false; 42 | if (getClass() != obj.getClass()) 43 | return false; 44 | AMapped other = (AMapped) obj; 45 | if (list == null) { 46 | if (other.list != null) 47 | return false; 48 | } else if (!list.equals(other.list)) 49 | return false; 50 | return true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "AMapped [list=" + list + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | B other = (B) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "B [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/BMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | public class BMapped { 4 | 5 | private String string; 6 | 7 | public BMapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public BMapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | BMapped other = (BMapped) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "BMapped [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/C.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | public class C { 4 | 5 | private String string; 6 | 7 | public C(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public C() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | C other = (C) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "C [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/CMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | public class CMapped { 4 | 5 | private String string; 6 | 7 | public CMapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public CMapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | final int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | CMapped other = (CMapped) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "CMapped [string=" + string + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/listMapTypeValidation/TypeValidationTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.listMapTypeValidation; 2 | 3 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | import com.remondis.remap.MappingException; 10 | 11 | public class TypeValidationTest { 12 | 13 | @Test 14 | public void shouldDetectBothNestedGenericTypes() { 15 | Mapper bMapper = Mapping.from(B.class) 16 | .to(BMapped.class) 17 | .mapper(); 18 | 19 | Mapper cMapper = Mapping.from(C.class) 20 | .to(CMapped.class) 21 | .mapper(); 22 | 23 | assertThatThrownBy(() -> { 24 | Mapping.from(A.class) 25 | .to(AMapped.class) 26 | .useMapper(cMapper) 27 | .mapper(); 28 | }).isInstanceOf(MappingException.class) 29 | .hasMessageContaining( 30 | "No mapper found for type mapping from com.remondis.remap.maps.listMapTypeValidation.B to com.remondis.remap.maps.listMapTypeValidation.BMapped."); 31 | 32 | assertThatThrownBy(() -> { 33 | Mapping.from(A.class) 34 | .to(AMapped.class) 35 | .useMapper(bMapper) 36 | .mapper(); 37 | }).isInstanceOf(MappingException.class) 38 | .hasMessageContaining( 39 | "No mapper found for type mapping from com.remondis.remap.maps.listMapTypeValidation.C to com.remondis.remap.maps.listMapTypeValidation.CMapped."); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | import java.util.Hashtable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class A { 8 | 9 | private Map, Map> map; 10 | 11 | public A() { 12 | super(); 13 | this.map = new Hashtable<>(); 14 | } 15 | 16 | public void add(List key, Map value) { 17 | this.map.put(key, value); 18 | } 19 | 20 | public Map, Map> getMap() { 21 | return map; 22 | } 23 | 24 | public void setMap(Map, Map> map) { 25 | this.map = map; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "A [bmap=" + map + "]"; 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | final int prime = 31; 36 | int result = 1; 37 | result = prime * result + ((map == null) ? 0 : map.hashCode()); 38 | return result; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) 44 | return true; 45 | if (obj == null) 46 | return false; 47 | if (getClass() != obj.getClass()) 48 | return false; 49 | A other = (A) obj; 50 | if (map == null) { 51 | if (other.map != null) 52 | return false; 53 | } else if (!map.equals(other.map)) 54 | return false; 55 | return true; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A1.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A1 { 4 | 5 | private String string; 6 | 7 | public A1(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A1() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A1 [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A1 other = (A1) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A1Mapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A1Mapped { 4 | 5 | private String string; 6 | 7 | public A1Mapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A1Mapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A1Mapped [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A1Mapped other = (A1Mapped) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A2.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A2 { 4 | 5 | private String string; 6 | 7 | public A2(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A2() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A2 [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A2 other = (A2) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A2Mapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A2Mapped { 4 | 5 | private String string; 6 | 7 | public A2Mapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A2Mapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A2Mapped [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A2Mapped other = (A2Mapped) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A3.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A3 { 4 | 5 | private String string; 6 | 7 | public A3(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A3() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A3 [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A3 other = (A3) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/A3Mapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | public class A3Mapped { 4 | 5 | private String string; 6 | 7 | public A3Mapped(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public A3Mapped() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "A3Mapped [string=" + string + "]"; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | A3Mapped other = (A3Mapped) obj; 46 | if (string == null) { 47 | if (other.string != null) 48 | return false; 49 | } else if (!string.equals(other.string)) 50 | return false; 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/nested/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.nested; 2 | 3 | import java.util.Hashtable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class AMapped { 8 | 9 | private Map, Map> map; 10 | 11 | public AMapped() { 12 | super(); 13 | this.map = new Hashtable<>(); 14 | } 15 | 16 | public void add(List key, Map value) { 17 | this.map.put(key, value); 18 | } 19 | 20 | public Map, Map> getMap() { 21 | return map; 22 | } 23 | 24 | public void setMap(Map, Map> map) { 25 | this.map = map; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "AMapped [map=" + map + "]"; 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | final int prime = 31; 36 | int result = 1; 37 | result = prime * result + ((map == null) ? 0 : map.hashCode()); 38 | return result; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) 44 | return true; 45 | if (obj == null) 46 | return false; 47 | if (getClass() != obj.getClass()) 48 | return false; 49 | AMapped other = (AMapped) obj; 50 | if (map == null) { 51 | if (other.map != null) 52 | return false; 53 | } else if (!map.equals(other.map)) 54 | return false; 55 | return true; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/reassign/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.reassign; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Map; 5 | 6 | public class A { 7 | 8 | private Map bmap; 9 | 10 | public A() { 11 | super(); 12 | this.bmap = new Hashtable<>(); 13 | 14 | } 15 | 16 | public A addB(Integer key, B b) { 17 | bmap.put(key, b); 18 | return this; 19 | } 20 | 21 | public Map getBmap() { 22 | return bmap; 23 | } 24 | 25 | public void setBmap(Map bmap) { 26 | this.bmap = bmap; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "A [bmap=" + bmap + "]"; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/reassign/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.reassign; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Map; 5 | 6 | public class AMapped { 7 | 8 | private Map anotherName; 9 | 10 | public AMapped() { 11 | super(); 12 | this.anotherName = new Hashtable<>(); 13 | } 14 | 15 | public Map getAnotherName() { 16 | return anotherName; 17 | } 18 | 19 | public void setAnotherName(Map anotherName) { 20 | this.anotherName = anotherName; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | final int prime = 31; 26 | int result = 1; 27 | result = prime * result + ((anotherName == null) ? 0 : anotherName.hashCode()); 28 | return result; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (this == obj) 34 | return true; 35 | if (obj == null) 36 | return false; 37 | if (getClass() != obj.getClass()) 38 | return false; 39 | AMapped other = (AMapped) obj; 40 | if (anotherName == null) { 41 | if (other.anotherName != null) 42 | return false; 43 | } else if (!anotherName.equals(other.anotherName)) 44 | return false; 45 | return true; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "AMapped [anotherName=" + anotherName + "]"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/reassign/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.reassign; 2 | 3 | public class B { 4 | 5 | private String string; 6 | 7 | public B(String string) { 8 | super(); 9 | this.string = string; 10 | } 11 | 12 | public B() { 13 | super(); 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/maps/reassign/ReassignTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.maps.reassign; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Map; 6 | 7 | import org.junit.Test; 8 | 9 | import com.remondis.remap.Mapper; 10 | import com.remondis.remap.Mapping; 11 | 12 | public class ReassignTest { 13 | 14 | @Test 15 | public void shouldReassignMaps() { 16 | Mapper mapper = Mapping.from(A.class) 17 | .to(AMapped.class) 18 | .reassign(A::getBmap) 19 | .to(AMapped::getAnotherName) 20 | .mapper(); 21 | 22 | A a = new A(); 23 | B b1 = new B("1"); 24 | B b2 = new B("2"); 25 | a.addB(1, b1); 26 | a.addB(2, b2); 27 | AMapped aMapped = mapper.map(a); 28 | Map map = aMapped.getAnotherName(); 29 | assertEquals(map.get(1), b1); 30 | assertEquals(map.get(2), b2); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/reassign/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.reassign; 2 | 3 | public class A { 4 | 5 | private String string; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public A(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/reassign/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.reassign; 2 | 3 | public class AResource { 4 | 5 | private String string1; 6 | private String string2; 7 | private String string3; 8 | 9 | public AResource() { 10 | super(); 11 | } 12 | 13 | public String getString1() { 14 | return string1; 15 | } 16 | 17 | public void setString1(String string1) { 18 | this.string1 = string1; 19 | } 20 | 21 | public String getString2() { 22 | return string2; 23 | } 24 | 25 | public void setString2(String string2) { 26 | this.string2 = string2; 27 | } 28 | 29 | public String getString3() { 30 | return string3; 31 | } 32 | 33 | public void setString3(String string3) { 34 | this.string3 = string3; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/reassign/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.reassign; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.AssertMapping; 8 | import com.remondis.remap.Mapper; 9 | import com.remondis.remap.Mapping; 10 | 11 | public class MapperTest { 12 | 13 | @Test 14 | public void shouldAllowMultipleReassigns() { 15 | 16 | Mapper mapper = Mapping.from(A.class) 17 | .to(AResource.class) 18 | .reassign(A::getString) 19 | .to(AResource::getString1) 20 | .reassign(A::getString) 21 | .to(AResource::getString2) 22 | .reassign(A::getString) 23 | .to(AResource::getString3) 24 | .mapper(); 25 | AssertMapping.of(mapper) 26 | .expectReassign(A::getString) 27 | .to(AResource::getString1) 28 | .expectReassign(A::getString) 29 | .to(AResource::getString2) 30 | .expectReassign(A::getString) 31 | .to(AResource::getString3) 32 | .ensure(); 33 | 34 | String string = "somestring"; 35 | AResource ar = mapper.map(new A(string)); 36 | assertEquals(string, ar.getString1()); 37 | assertEquals(string, ar.getString2()); 38 | assertEquals(string, ar.getString3()); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/replace/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.replace; 2 | 3 | public class A { 4 | 5 | private String aString; 6 | private B b; 7 | 8 | public A() { 9 | super(); 10 | } 11 | 12 | public A(String aString, B b) { 13 | super(); 14 | this.aString = aString; 15 | this.b = b; 16 | } 17 | 18 | public String getAString() { 19 | return aString; 20 | } 21 | 22 | public void setAString(String aString) { 23 | this.aString = aString; 24 | } 25 | 26 | public B getB() { 27 | return b; 28 | } 29 | 30 | public void setB(B b) { 31 | this.b = b; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "A [aString=" + aString + ", b=" + b + "]"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/replace/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.replace; 2 | 3 | public class AResource { 4 | 5 | private String aString; 6 | private String string; 7 | private int number; 8 | private Integer integer; 9 | 10 | public AResource() { 11 | super(); 12 | } 13 | 14 | public AResource(String aString, String string, int number, Integer integer) { 15 | super(); 16 | this.aString = aString; 17 | this.string = string; 18 | this.number = number; 19 | this.integer = integer; 20 | } 21 | 22 | public String getAString() { 23 | return aString; 24 | } 25 | 26 | public void setAString(String aString) { 27 | this.aString = aString; 28 | } 29 | 30 | public String getString() { 31 | return string; 32 | } 33 | 34 | public void setString(String string) { 35 | this.string = string; 36 | } 37 | 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | public void setNumber(int number) { 43 | this.number = number; 44 | } 45 | 46 | public Integer getInteger() { 47 | return integer; 48 | } 49 | 50 | public void setInteger(Integer integer) { 51 | this.integer = integer; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "AResource [aString=" + aString + ", string=" + string + ", number=" + number + ", integer=" + integer + "]"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/multimapping/replace/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.multimapping.replace; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public B() { 10 | super(); 11 | } 12 | 13 | public B(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "B [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/noImplicitMappings/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.noImplicitMappings; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private Integer integer; 7 | 8 | public B(String string, Integer integer) { 9 | super(); 10 | this.string = string; 11 | this.integer = integer; 12 | } 13 | 14 | public B() { 15 | super(); 16 | } 17 | 18 | public String getString() { 19 | return string; 20 | } 21 | 22 | public void setString(String string) { 23 | this.string = string; 24 | } 25 | 26 | public Integer getInteger() { 27 | return integer; 28 | } 29 | 30 | public void setInteger(Integer integer) { 31 | this.integer = integer; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result + ((integer == null) ? 0 : integer.hashCode()); 39 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 40 | return result; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | if (this == obj) 46 | return true; 47 | if (obj == null) 48 | return false; 49 | if (getClass() != obj.getClass()) 50 | return false; 51 | B other = (B) obj; 52 | if (integer == null) { 53 | if (other.integer != null) 54 | return false; 55 | } else if (!integer.equals(other.integer)) 56 | return false; 57 | if (string == null) { 58 | if (other.string != null) 59 | return false; 60 | } else if (!string.equals(other.string)) 61 | return false; 62 | return true; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/nullvalues/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.nullvalues; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public B() { 10 | super(); 11 | } 12 | 13 | public B(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "B [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/nullvalues/BResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.nullvalues; 2 | 3 | public class BResource { 4 | 5 | private String string; 6 | private int number; 7 | private Integer integer; 8 | 9 | public BResource() { 10 | super(); 11 | } 12 | 13 | public BResource(String string, int number, Integer integer) { 14 | super(); 15 | this.string = string; 16 | this.number = number; 17 | this.integer = integer; 18 | } 19 | 20 | /** 21 | * @return the string 22 | */ 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | /** 28 | * @param string 29 | * the string to set 30 | */ 31 | public void setString(String string) { 32 | this.string = string; 33 | } 34 | 35 | /** 36 | * @return the number 37 | */ 38 | public int getNumber() { 39 | return number; 40 | } 41 | 42 | /** 43 | * @param number 44 | * the number to set 45 | */ 46 | public void setNumber(int number) { 47 | this.number = number; 48 | } 49 | 50 | /** 51 | * @return the integer 52 | */ 53 | public Integer getInteger() { 54 | return integer; 55 | } 56 | 57 | /** 58 | * @param integer 59 | * the integer to set 60 | */ 61 | public void setInteger(Integer integer) { 62 | this.integer = integer; 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return "BResource [string=" + string + ", number=" + number + ", integer=" + integer + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/omitOthers/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.omitOthers; 2 | 3 | public class A { 4 | private Long id; 5 | private String description; 6 | private String a; 7 | private String b; 8 | 9 | public A() { 10 | super(); 11 | } 12 | 13 | public A(Long id, String description, String a, String b) { 14 | super(); 15 | this.id = id; 16 | this.description = description; 17 | this.a = a; 18 | this.b = b; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getDescription() { 30 | return description; 31 | } 32 | 33 | public void setDescription(String description) { 34 | this.description = description; 35 | } 36 | 37 | public String getA() { 38 | return a; 39 | } 40 | 41 | public void setA(String a) { 42 | this.a = a; 43 | } 44 | 45 | public String getB() { 46 | return b; 47 | } 48 | 49 | public void setB(String b) { 50 | this.b = b; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/omitOthers/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.omitOthers; 2 | 3 | public class AResource { 4 | private String id; 5 | private String name; 6 | private String c; 7 | private String d; 8 | private String e; 9 | 10 | public AResource() { 11 | super(); 12 | } 13 | 14 | public AResource(String id, String name, String c, String d, String e) { 15 | super(); 16 | this.id = id; 17 | this.name = name; 18 | this.c = c; 19 | this.d = d; 20 | this.e = e; 21 | } 22 | 23 | public String getId() { 24 | return id; 25 | } 26 | 27 | public void setId(String id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getC() { 40 | return c; 41 | } 42 | 43 | public void setC(String c) { 44 | this.c = c; 45 | } 46 | 47 | public String getD() { 48 | return d; 49 | } 50 | 51 | public void setD(String d) { 52 | this.d = d; 53 | } 54 | 55 | public String getE() { 56 | return e; 57 | } 58 | 59 | public void setE(String e) { 60 | this.e = e; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/Address.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping; 2 | 3 | public class Address { 4 | 5 | String street; 6 | 7 | String houseNumber; 8 | 9 | String zipCode; 10 | 11 | String city; 12 | 13 | public Address() { 14 | super(); 15 | } 16 | 17 | public Address(String street, String houseNumber, String zipCode, String city) { 18 | super(); 19 | this.street = street; 20 | this.houseNumber = houseNumber; 21 | this.zipCode = zipCode; 22 | this.city = city; 23 | } 24 | 25 | public String getStreet() { 26 | return street; 27 | } 28 | 29 | public void setStreet(String street) { 30 | this.street = street; 31 | } 32 | 33 | public String getHouseNumber() { 34 | return houseNumber; 35 | } 36 | 37 | public void setHouseNumber(String houseNumber) { 38 | this.houseNumber = houseNumber; 39 | } 40 | 41 | public String getZipCode() { 42 | return zipCode; 43 | } 44 | 45 | public void setZipCode(String zipCode) { 46 | this.zipCode = zipCode; 47 | } 48 | 49 | public String getCity() { 50 | return city; 51 | } 52 | 53 | public void setCity(String city) { 54 | this.city = city; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Address [street=" + street + ", houseNumber=" + houseNumber + ", zipCode=" + zipCode + ", city=" + city 60 | + "]"; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/Person.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping; 2 | 3 | public class Person { 4 | String forename; 5 | 6 | String name; 7 | 8 | Address address; 9 | 10 | public Person() { 11 | super(); 12 | } 13 | 14 | public Person(String forename, String name, Address address) { 15 | super(); 16 | this.forename = forename; 17 | this.name = name; 18 | this.address = address; 19 | } 20 | 21 | public String getForename() { 22 | return forename; 23 | } 24 | 25 | public void setForename(String forename) { 26 | this.forename = forename; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public Address getAddress() { 38 | return address; 39 | } 40 | 41 | public void setAddress(Address address) { 42 | this.address = address; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/collections/CollectionDestination.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping.collections; 2 | 3 | import java.util.Set; 4 | 5 | public class CollectionDestination { 6 | 7 | private Set cities; 8 | 9 | public CollectionDestination(Set cities) { 10 | super(); 11 | this.cities = cities; 12 | } 13 | 14 | public CollectionDestination() { 15 | super(); 16 | } 17 | 18 | public Set getCities() { 19 | return cities; 20 | } 21 | 22 | public void setCities(Set cities) { 23 | this.cities = cities; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/collections/CollectionSource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping.collections; 2 | 3 | import java.util.List; 4 | 5 | import com.remondis.remap.propertypathmapping.Person; 6 | 7 | public class CollectionSource { 8 | 9 | private List persons; 10 | 11 | public CollectionSource(List persons) { 12 | super(); 13 | this.persons = persons; 14 | } 15 | 16 | public CollectionSource() { 17 | super(); 18 | } 19 | 20 | public List getPersons() { 21 | return persons; 22 | } 23 | 24 | public void setPersons(List persons) { 25 | this.persons = persons; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/withtransformation/PersonView.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping.withtransformation; 2 | 3 | /** 4 | * 5 | */ 6 | public class PersonView { 7 | 8 | private int streetLength; 9 | private Integer streetLengthWrap; 10 | 11 | public PersonView(int streetLength) { 12 | super(); 13 | this.streetLength = streetLength; 14 | } 15 | 16 | public PersonView() { 17 | super(); 18 | } 19 | 20 | public int getStreetLength() { 21 | return streetLength; 22 | } 23 | 24 | public void setStreetLength(int streetLength) { 25 | this.streetLength = streetLength; 26 | } 27 | 28 | public Integer getStreetLengthWrap() { 29 | return streetLengthWrap; 30 | } 31 | 32 | public void setStreetLengthWrap(Integer streetLengthWrap) { 33 | this.streetLengthWrap = streetLengthWrap; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/withtransformation/collections/Person.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping.withtransformation.collections; 2 | 3 | import java.util.List; 4 | 5 | import com.remondis.remap.propertypathmapping.Address; 6 | 7 | public class Person { 8 | 9 | List

addresses; 10 | 11 | public Person() { 12 | super(); 13 | } 14 | 15 | public Person(List
addresses) { 16 | super(); 17 | this.addresses = addresses; 18 | } 19 | 20 | public List
getAddresses() { 21 | return addresses; 22 | } 23 | 24 | public void setAddresses(List
addresses) { 25 | this.addresses = addresses; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/propertypathmapping/withtransformation/collections/PersonView.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.propertypathmapping.withtransformation.collections; 2 | 3 | import java.util.List; 4 | 5 | public class PersonView { 6 | 7 | private List streetLength; 8 | 9 | public PersonView() { 10 | super(); 11 | } 12 | 13 | public List getStreetLength() { 14 | return streetLength; 15 | } 16 | 17 | public void setStreetLength(List streetLength) { 18 | this.streetLength = streetLength; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/booleanObjectBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.booleanObjectBug; 2 | 3 | public class A { 4 | private Boolean newsletterSubscribed; 5 | private String mail; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public String getMail() { 12 | return mail; 13 | } 14 | 15 | public void setMail(String mail) { 16 | this.mail = mail; 17 | } 18 | 19 | public Boolean getNewsletterSubscribed() { 20 | return newsletterSubscribed; 21 | } 22 | 23 | public void setNewsletterSubscribed(Boolean newsletterSubscribed) { 24 | this.newsletterSubscribed = newsletterSubscribed; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/booleanObjectBug/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.booleanObjectBug; 2 | 3 | public class B { 4 | private String email; 5 | 6 | public B() { 7 | super(); 8 | } 9 | 10 | public String getEmail() { 11 | return email; 12 | } 13 | 14 | public void setEmail(String email) { 15 | this.email = email; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/booleanObjectBug/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.booleanObjectBug; 2 | 3 | import org.junit.Test; 4 | 5 | import com.remondis.remap.Mapping; 6 | 7 | public class MapperTest { 8 | 9 | @Test 10 | public void shouldMap() { 11 | Mapping.from(A.class) 12 | .to(B.class) 13 | .reassign(A::getMail) 14 | .to(B::getEmail) 15 | .omitInSource(A::getNewsletterSubscribed) 16 | .mapper(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/capitalLetterBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.capitalLetterBug; 2 | 3 | public class A { 4 | 5 | public String aString; 6 | 7 | public A(String aString) { 8 | super(); 9 | this.aString = aString; 10 | } 11 | 12 | public A() { 13 | super(); 14 | } 15 | 16 | public String getAString() { 17 | return aString; 18 | } 19 | 20 | public void setAString(String aString) { 21 | this.aString = aString; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/capitalLetterBug/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.capitalLetterBug; 2 | 3 | public class AResource { 4 | 5 | public String bString; 6 | 7 | public AResource(String bString) { 8 | super(); 9 | this.bString = bString; 10 | } 11 | 12 | public AResource() { 13 | super(); 14 | } 15 | 16 | public String getAString() { 17 | return bString; 18 | } 19 | 20 | public void setAString(String bString) { 21 | this.bString = bString; 22 | } 23 | 24 | public String getBString() { 25 | return bString; 26 | } 27 | 28 | public void setBString(String bString) { 29 | this.bString = bString; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/capitalLetterBug/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.capitalLetterBug; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | 10 | public class MapperTest { 11 | 12 | private static final String STRING = "aString"; 13 | 14 | @Test 15 | public void shouldMapProperties() { 16 | Mapper mapper = Mapping.from(A.class) 17 | .to(AResource.class) 18 | .reassign(A::getAString) 19 | .to(AResource::getAString) 20 | .reassign(A::getAString) 21 | .to(AResource::getBString) 22 | .mapper(); 23 | 24 | A a = new A(STRING); 25 | AResource ar = mapper.map(a); 26 | 27 | assertEquals(STRING, ar.getAString()); 28 | assertEquals(STRING, ar.getBString()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/implicitPrimitiveToWrapperMappingBug/BoolPrimitive.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.implicitPrimitiveToWrapperMappingBug; 2 | 3 | public class BoolPrimitive { 4 | 5 | private boolean bool; 6 | 7 | public BoolPrimitive() { 8 | super(); 9 | } 10 | 11 | public BoolPrimitive(boolean bool) { 12 | super(); 13 | this.bool = bool; 14 | } 15 | 16 | public boolean isBool() { 17 | return bool; 18 | } 19 | 20 | public void setBool(boolean bool) { 21 | this.bool = bool; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/implicitPrimitiveToWrapperMappingBug/BoolWrapper.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.implicitPrimitiveToWrapperMappingBug; 2 | 3 | public class BoolWrapper { 4 | 5 | private Boolean bool; 6 | 7 | public BoolWrapper() { 8 | super(); 9 | } 10 | 11 | public BoolWrapper(Boolean bool) { 12 | super(); 13 | this.bool = bool; 14 | } 15 | 16 | public Boolean getBool() { 17 | return bool; 18 | } 19 | 20 | public void setBool(Boolean bool) { 21 | this.bool = bool; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/implicitPrimitiveToWrapperMappingBug/IntPrimitive.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.implicitPrimitiveToWrapperMappingBug; 2 | 3 | public class IntPrimitive { 4 | 5 | private int integer; 6 | 7 | public IntPrimitive() { 8 | super(); 9 | } 10 | 11 | public IntPrimitive(int integer) { 12 | super(); 13 | this.integer = integer; 14 | } 15 | 16 | public int getInteger() { 17 | return integer; 18 | } 19 | 20 | public void setInteger(int integer) { 21 | this.integer = integer; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/implicitPrimitiveToWrapperMappingBug/IntWrapper.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.implicitPrimitiveToWrapperMappingBug; 2 | 3 | public class IntWrapper { 4 | 5 | private Integer integer; 6 | 7 | public IntWrapper() { 8 | super(); 9 | } 10 | 11 | public IntWrapper(Integer integer) { 12 | super(); 13 | this.integer = integer; 14 | } 15 | 16 | public Integer getInteger() { 17 | return integer; 18 | } 19 | 20 | public void setInteger(Integer integer) { 21 | this.integer = integer; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/methodCallsInConstructor/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.methodCallsInConstructor; 2 | 3 | public class A { 4 | 5 | private String aString; 6 | 7 | public A() { 8 | this.notAValidMethod("toCall"); 9 | } 10 | 11 | public A(String aString) { 12 | super(); 13 | this.aString = aString; 14 | } 15 | 16 | public String notAValidMethod(String toCall) { 17 | return null; 18 | } 19 | 20 | public String getaString() { 21 | return aString; 22 | } 23 | 24 | public void setaString(String aString) { 25 | this.aString = aString; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/methodCallsInConstructor/MethodCallsInConstructorTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.methodCallsInConstructor; 2 | 3 | import java.util.function.Function; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | 10 | public class MethodCallsInConstructorTest { 11 | 12 | @Test 13 | public void shouldNotComplainAboutInternalMethodsInConstructor() { 14 | Mapper mapper = Mapping.from(A.class) 15 | .to(A.class) 16 | .replace(A::getaString, A::getaString) 17 | .with(Function.identity()) 18 | .mapper(); 19 | 20 | mapper.map(new A("AString")); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/noBeanCopyBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.noBeanCopyBug; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class A { 6 | 7 | private BigDecimal bigDecimal; 8 | 9 | public A() { 10 | super(); 11 | } 12 | 13 | public A(BigDecimal bigDecimal) { 14 | super(); 15 | this.bigDecimal = bigDecimal; 16 | } 17 | 18 | public BigDecimal getBigDecimal() { 19 | return bigDecimal; 20 | } 21 | 22 | public void setBigDecimal(BigDecimal bigDecimal) { 23 | this.bigDecimal = bigDecimal; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | final int prime = 31; 29 | int result = 1; 30 | result = prime * result + ((bigDecimal == null) ? 0 : bigDecimal.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | A other = (A) obj; 43 | if (bigDecimal == null) { 44 | if (other.bigDecimal != null) 45 | return false; 46 | } else if (!bigDecimal.equals(other.bigDecimal)) 47 | return false; 48 | return true; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/noBeanCopyBug/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.noBeanCopyBug; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class AResource { 6 | 7 | private BigDecimal bigDecimal; 8 | 9 | public AResource() { 10 | super(); 11 | } 12 | 13 | public AResource(BigDecimal bigDecimal) { 14 | super(); 15 | this.bigDecimal = bigDecimal; 16 | } 17 | 18 | public BigDecimal getBigDecimal() { 19 | return bigDecimal; 20 | } 21 | 22 | public void setBigDecimal(BigDecimal bigDecimal) { 23 | this.bigDecimal = bigDecimal; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | final int prime = 31; 29 | int result = 1; 30 | result = prime * result + ((bigDecimal == null) ? 0 : bigDecimal.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | AResource other = (AResource) obj; 43 | if (bigDecimal == null) { 44 | if (other.bigDecimal != null) 45 | return false; 46 | } else if (!bigDecimal.equals(other.bigDecimal)) 47 | return false; 48 | return true; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/noBeanCopyBug/NoBeanCopyBug.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.noBeanCopyBug; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.math.BigDecimal; 6 | 7 | import org.junit.Test; 8 | 9 | import com.remondis.remap.Mapper; 10 | import com.remondis.remap.Mapping; 11 | 12 | public class NoBeanCopyBug { 13 | 14 | /** 15 | * There was a bug in mapping an object holding a {@link BigDecimal}, a Java object not complying to Java bean 16 | * convention. The attempt was made to copy this instance by calling a default constructor, but there is none. 17 | */ 18 | @Test 19 | public void noBeanCopyBug() { 20 | Mapper mapper = Mapping.from(A.class) 21 | .to(AResource.class) 22 | .mapper(); 23 | 24 | BigDecimal bigDecimal = new BigDecimal(1L); 25 | A a = new A(bigDecimal); 26 | AResource ar = mapper.map(a); 27 | 28 | assertEquals(bigDecimal, a.getBigDecimal()); 29 | assertEquals(bigDecimal, ar.getBigDecimal()); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeDenyAlreadyOmitted/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeDenyAlreadyOmitted; 2 | 3 | public class A { 4 | 5 | public String multiMapped; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public A(String multiMapped) { 12 | super(); 13 | this.multiMapped = multiMapped; 14 | } 15 | 16 | public String getMultiMapped() { 17 | return multiMapped; 18 | } 19 | 20 | public void setMultiMapped(String multiMapped) { 21 | this.multiMapped = multiMapped; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeDenyAlreadyOmitted/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeDenyAlreadyOmitted; 2 | 3 | public class AResource { 4 | 5 | public String multiMapped1; 6 | public String multiMapped2; 7 | public String multiMapped3; 8 | public String omitted; 9 | 10 | public AResource() { 11 | super(); 12 | } 13 | 14 | public AResource(String multiMapped1, String multiMapped2, String multiMapped3) { 15 | super(); 16 | this.multiMapped1 = multiMapped1; 17 | this.multiMapped2 = multiMapped2; 18 | this.multiMapped3 = multiMapped3; 19 | } 20 | 21 | public String getOmitted() { 22 | return omitted; 23 | } 24 | 25 | public void setOmitted(String omitted) { 26 | this.omitted = omitted; 27 | } 28 | 29 | public String getMultiMapped1() { 30 | return multiMapped1; 31 | } 32 | 33 | public void setMultiMapped1(String multiMapped1) { 34 | this.multiMapped1 = multiMapped1; 35 | } 36 | 37 | public String getMultiMapped2() { 38 | return multiMapped2; 39 | } 40 | 41 | public void setMultiMapped2(String multiMapped2) { 42 | this.multiMapped2 = multiMapped2; 43 | } 44 | 45 | public String getMultiMapped3() { 46 | return multiMapped3; 47 | } 48 | 49 | public void setMultiMapped3(String multiMapped3) { 50 | this.multiMapped3 = multiMapped3; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeDenyAlreadyOmitted/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeDenyAlreadyOmitted; 2 | 3 | import java.util.function.Function; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapping; 8 | 9 | public class MapperTest { 10 | 11 | @Test 12 | public void shouldMap() { 13 | Mapping.from(A.class) 14 | .to(AResource.class) 15 | .omitInDestination(AResource::getOmitted) 16 | .replace(A::getMultiMapped, AResource::getMultiMapped1) 17 | .withSkipWhenNull(Function.identity()) 18 | .replace(A::getMultiMapped, AResource::getMultiMapped2) 19 | .withSkipWhenNull(Function.identity()) 20 | .replace(A::getMultiMapped, AResource::getMultiMapped3) 21 | .withSkipWhenNull(Function.identity()) 22 | .mapper(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeOnUnmappedReadOnlyProperty/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeOnUnmappedReadOnlyProperty; 2 | 3 | public class A { 4 | private String string; 5 | private Integer readOnly; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public A(String string, Integer readOnly) { 12 | super(); 13 | this.string = string; 14 | this.readOnly = readOnly; 15 | } 16 | 17 | public String getString() { 18 | return string; 19 | } 20 | 21 | public void setString(String string) { 22 | this.string = string; 23 | } 24 | 25 | public Integer getReadOnly() { 26 | return readOnly; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeOnUnmappedReadOnlyProperty/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeOnUnmappedReadOnlyProperty; 2 | 3 | public class B { 4 | private String string; 5 | 6 | public B() { 7 | super(); 8 | } 9 | 10 | public B(String string) { 11 | super(); 12 | this.string = string; 13 | } 14 | 15 | public String getString() { 16 | return string; 17 | } 18 | 19 | public void setString(String string) { 20 | this.string = string; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/npeOnUnmappedReadOnlyProperty/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.npeOnUnmappedReadOnlyProperty; 2 | 3 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapping; 8 | 9 | public class MapperTest { 10 | @Test 11 | public void test() { 12 | assertThatThrownBy(() -> { 13 | Mapping.from(A.class) 14 | .to(B.class) 15 | .mapper(); 16 | }).hasMessageStartingWith("The following properties are unmapped:"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitCustomGet/Bar.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitCustomGet; 2 | 3 | public class Bar { 4 | private String string; 5 | 6 | public Bar() { 7 | super(); 8 | } 9 | 10 | public Bar(String string) { 11 | super(); 12 | this.string = string; 13 | } 14 | 15 | public String getString() { 16 | return string; 17 | } 18 | 19 | public void setString(String string) { 20 | this.string = string; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitCustomGet/Foo.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitCustomGet; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | public class Foo { 7 | 8 | private List bars; 9 | 10 | public Foo() { 11 | super(); 12 | } 13 | 14 | public Foo(List bars) { 15 | super(); 16 | this.bars = bars; 17 | } 18 | 19 | public List getBars() { 20 | return bars; 21 | } 22 | 23 | public void setBars(List bars) { 24 | this.bars = bars; 25 | } 26 | 27 | public List getFilteredBars() { 28 | return this.bars.stream() 29 | .filter(b -> b.getString() 30 | .equals("hello")) 31 | .collect(Collectors.toList()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitCustomGet/FooMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitCustomGet; 2 | 3 | import java.util.List; 4 | 5 | public class FooMapped { 6 | 7 | private List bars; 8 | 9 | public FooMapped() { 10 | super(); 11 | } 12 | 13 | public FooMapped(List bars) { 14 | super(); 15 | this.bars = bars; 16 | } 17 | 18 | public List getBars() { 19 | return bars; 20 | } 21 | 22 | public void setBars(List bars) { 23 | this.bars = bars; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitCustomGet/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitCustomGet; 2 | 3 | import org.junit.Test; 4 | 5 | import com.remondis.remap.AssertMapping; 6 | import com.remondis.remap.Mapper; 7 | import com.remondis.remap.Mapping; 8 | 9 | public class MapperTest { 10 | 11 | @Test 12 | public void map() { 13 | Mapper mapper = Mapping.from(Foo.class) 14 | .to(FooMapped.class) 15 | .omitInSource(Foo::getFilteredBars) 16 | .mapper(); 17 | 18 | AssertMapping.of(mapper) 19 | .expectOmitInSource(Foo::getFilteredBars) 20 | .ensure(); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitOthersOmitsImplicitMappings/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitOthersOmitsImplicitMappings; 2 | 3 | public class A { 4 | 5 | private String string1; 6 | private String string2; 7 | private String anotherString; 8 | 9 | public A(String string1, String string2, String anotherString) { 10 | super(); 11 | this.string1 = string1; 12 | this.string2 = string2; 13 | this.anotherString = anotherString; 14 | } 15 | 16 | public A() { 17 | super(); 18 | } 19 | 20 | public String getString1() { 21 | return string1; 22 | } 23 | 24 | public void setString1(String string1) { 25 | this.string1 = string1; 26 | } 27 | 28 | public String getString2() { 29 | return string2; 30 | } 31 | 32 | public void setString2(String string2) { 33 | this.string2 = string2; 34 | } 35 | 36 | public String getAnotherString() { 37 | return anotherString; 38 | } 39 | 40 | public void setAnotherString(String anotherString) { 41 | this.anotherString = anotherString; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitOthersOmitsImplicitMappings/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitOthersOmitsImplicitMappings; 2 | 3 | public class B { 4 | 5 | private String string1; 6 | private int string2Length; 7 | private String someOtherString; 8 | 9 | public B(String string1, int string2Length, String someOtherString) { 10 | super(); 11 | this.string1 = string1; 12 | this.string2Length = string2Length; 13 | this.someOtherString = someOtherString; 14 | } 15 | 16 | public B() { 17 | super(); 18 | } 19 | 20 | public String getString1() { 21 | return string1; 22 | } 23 | 24 | public void setString1(String string1) { 25 | this.string1 = string1; 26 | } 27 | 28 | public int getString2Length() { 29 | return string2Length; 30 | } 31 | 32 | public void setString2Length(int string2Length) { 33 | this.string2Length = string2Length; 34 | } 35 | 36 | public String getSomeOtherString() { 37 | return someOtherString; 38 | } 39 | 40 | public void setSomeOtherString(String someOtherString) { 41 | this.someOtherString = someOtherString; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitOthersOmitsImplicitMappings/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitOthersOmitsImplicitMappings; 2 | 3 | import org.junit.Test; 4 | 5 | import com.remondis.remap.AssertMapping; 6 | import com.remondis.remap.Mapper; 7 | import com.remondis.remap.Mapping; 8 | 9 | public class MapperTest { 10 | 11 | /** 12 | * The bug was, that omitOtherSourceProperties() removed all implicit mappings. In this case the Mapper complained 13 | * about field "string1" is not being mapped. 14 | */ 15 | @Test 16 | public void shouldNotBreakImplicitMappings() { 17 | Mapper mapper = Mapping.from(A.class) 18 | .to(B.class) 19 | .replace(A::getString2, B::getString2Length) 20 | .withSkipWhenNull(String::length) 21 | .omitOtherSourceProperties() 22 | .omitInDestination(B::getSomeOtherString) 23 | .mapper(); 24 | 25 | AssertMapping.of(mapper) 26 | .expectReplace(A::getString2, B::getString2Length) 27 | .andSkipWhenNull() 28 | .expectOtherSourceFieldsToBeOmitted() 29 | .expectOmitInDestination(B::getSomeOtherString) 30 | .ensure(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitReadOnlyGetterBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitReadOnlyGetterBug; 2 | 3 | public class A { 4 | private String string; 5 | private Integer readOnly; 6 | 7 | public A() { 8 | super(); 9 | } 10 | 11 | public A(String string, Integer readOnly) { 12 | super(); 13 | this.string = string; 14 | this.readOnly = readOnly; 15 | } 16 | 17 | public String getString() { 18 | return string; 19 | } 20 | 21 | public void setString(String string) { 22 | this.string = string; 23 | } 24 | 25 | public Integer getReadOnly() { 26 | return readOnly; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitReadOnlyGetterBug/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitReadOnlyGetterBug; 2 | 3 | public class B { 4 | private String string; 5 | 6 | public B() { 7 | super(); 8 | } 9 | 10 | public B(String string) { 11 | super(); 12 | this.string = string; 13 | } 14 | 15 | public String getString() { 16 | return string; 17 | } 18 | 19 | public void setString(String string) { 20 | this.string = string; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/omitReadOnlyGetterBug/MapperTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.omitReadOnlyGetterBug; 2 | 3 | import org.junit.Test; 4 | 5 | import com.remondis.remap.Mapping; 6 | 7 | public class MapperTest { 8 | @Test 9 | public void test() { 10 | 11 | Mapping.from(A.class) 12 | .to(B.class) 13 | .omitInSource(A::getReadOnly) 14 | .mapper(); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/replaceOnCollectionBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.replaceOnCollectionBug; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private List strings; 8 | 9 | public A(List strings) { 10 | super(); 11 | this.strings = strings; 12 | } 13 | 14 | public A() { 15 | super(); 16 | } 17 | 18 | public List getStrings() { 19 | return strings; 20 | } 21 | 22 | public void setStrings(List strings) { 23 | this.strings = strings; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/replaceOnCollectionBug/AFlat.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.replaceOnCollectionBug; 2 | 3 | public class AFlat { 4 | private String string; 5 | 6 | public AFlat(String string) { 7 | super(); 8 | this.string = string; 9 | } 10 | 11 | public AFlat() { 12 | super(); 13 | } 14 | 15 | public String getString() { 16 | return string; 17 | } 18 | 19 | public void setString(String string) { 20 | this.string = string; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/replaceOnCollectionBug/AResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.replaceOnCollectionBug; 2 | 3 | import java.util.List; 4 | 5 | public class AResource { 6 | private List strings; 7 | 8 | public AResource(List strings) { 9 | super(); 10 | this.strings = strings; 11 | } 12 | 13 | public AResource() { 14 | super(); 15 | } 16 | 17 | public List getStrings() { 18 | return strings; 19 | } 20 | 21 | public void setStrings(List strings) { 22 | this.strings = strings; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/typeMappingForCollectionsBug/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.typeMappingForCollectionsBug; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | private List strings; 7 | 8 | public A() { 9 | super(); 10 | } 11 | 12 | public A(List strings) { 13 | super(); 14 | this.strings = strings; 15 | } 16 | 17 | public List getStrings() { 18 | return strings; 19 | } 20 | 21 | public void setStrings(List strings) { 22 | this.strings = strings; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/typeMappingForCollectionsBug/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.typeMappingForCollectionsBug; 2 | 3 | import java.util.Set; 4 | 5 | public class B { 6 | private Set strings; 7 | 8 | public B() { 9 | super(); 10 | } 11 | 12 | public B(Set strings) { 13 | super(); 14 | this.strings = strings; 15 | } 16 | 17 | public Set getStrings() { 18 | return strings; 19 | } 20 | 21 | public void setStrings(Set strings) { 22 | this.strings = strings; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/useMapperTwice/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.useMapperTwice; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | private List bs; 8 | 9 | public A() { 10 | super(); 11 | } 12 | 13 | public A(List bs) { 14 | super(); 15 | this.bs = bs; 16 | } 17 | 18 | public List getBs() { 19 | return bs; 20 | } 21 | 22 | public void setBs(List bs) { 23 | this.bs = bs; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/useMapperTwice/AMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.useMapperTwice; 2 | 3 | import java.util.List; 4 | 5 | public class AMapped { 6 | 7 | private List bs; 8 | 9 | public AMapped() { 10 | super(); 11 | } 12 | 13 | public AMapped(List bs) { 14 | super(); 15 | this.bs = bs; 16 | } 17 | 18 | public List getBs() { 19 | return bs; 20 | } 21 | 22 | public void setBs(List bs) { 23 | this.bs = bs; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/useMapperTwice/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.useMapperTwice; 2 | 3 | /** 4 | * 5 | */ 6 | public class B { 7 | 8 | private String string; 9 | 10 | public B(String string) { 11 | super(); 12 | this.string = string; 13 | } 14 | 15 | public B() { 16 | super(); 17 | } 18 | 19 | public String getString() { 20 | return string; 21 | } 22 | 23 | public void setString(String string) { 24 | this.string = string; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/useMapperTwice/BMapped.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.useMapperTwice; 2 | 3 | /** 4 | * 5 | */ 6 | public class BMapped { 7 | 8 | private int stringLength; 9 | 10 | public BMapped(int stringLength) { 11 | super(); 12 | this.stringLength = stringLength; 13 | } 14 | 15 | public BMapped() { 16 | super(); 17 | } 18 | 19 | public int getStringLength() { 20 | return stringLength; 21 | } 22 | 23 | public void setStringLength(int stringLength) { 24 | this.stringLength = stringLength; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/regression/useMapperTwice/UseMapperTwiceTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.regression.useMapperTwice; 2 | 3 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | import com.remondis.remap.MappingException; 10 | 11 | public class UseMapperTwiceTest { 12 | 13 | @Test 14 | public void should_complain_with_types_of_mapper_when_useMapperTwice() { 15 | Mapper bMapper = Mapping.from(B.class) 16 | .to(BMapped.class) 17 | .replace(B::getString, BMapped::getStringLength) 18 | .withSkipWhenNull(String::length) 19 | .mapper(); 20 | 21 | assertThatThrownBy(() -> { 22 | Mapping.from(A.class) 23 | .to(AMapped.class) 24 | .useMapper(bMapper) 25 | .useMapper(bMapper); 26 | }).isInstanceOf(MappingException.class) 27 | .hasMessage( 28 | "A mapper mapping the type com.remondis.remap.regression.useMapperTwice.B to type com.remondis.remap.regression.useMapperTwice.BMapped was already registered."); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/Address.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure; 2 | 3 | public class Address { 4 | private String street; 5 | private int houseNumber; 6 | private String city; 7 | 8 | public Address() { 9 | } 10 | 11 | public Address(String street, int houseNumber, String city) { 12 | this.street = street; 13 | this.houseNumber = houseNumber; 14 | this.city = city; 15 | } 16 | 17 | public String getStreet() { 18 | return street; 19 | } 20 | 21 | public void setStreet(String street) { 22 | this.street = street; 23 | } 24 | 25 | public int getHouseNumber() { 26 | return houseNumber; 27 | } 28 | 29 | public void setHouseNumber(int houseNumber) { 30 | this.houseNumber = houseNumber; 31 | } 32 | 33 | public String getCity() { 34 | return city; 35 | } 36 | 37 | public void setCity(String city) { 38 | this.city = city; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Address{" + "street='" + street + '\'' + ", houseNumber=" + houseNumber + ", city='" + city + '\'' + '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/Bean.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure; 2 | 3 | public class Bean { 4 | 5 | private String forename; 6 | private String name; 7 | 8 | private String street; 9 | private int houseNumber; 10 | private String city; 11 | 12 | public Bean() { 13 | } 14 | 15 | public Bean(String forename, String name, String street, int houseNumber, String city) { 16 | this.forename = forename; 17 | this.name = name; 18 | this.street = street; 19 | this.houseNumber = houseNumber; 20 | this.city = city; 21 | } 22 | 23 | public String getForename() { 24 | return forename; 25 | } 26 | 27 | public void setForename(String forename) { 28 | this.forename = forename; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getStreet() { 40 | return street; 41 | } 42 | 43 | public void setStreet(String street) { 44 | this.street = street; 45 | } 46 | 47 | public int getHouseNumber() { 48 | return houseNumber; 49 | } 50 | 51 | public void setHouseNumber(int houseNumber) { 52 | this.houseNumber = houseNumber; 53 | } 54 | 55 | public String getCity() { 56 | return city; 57 | } 58 | 59 | public void setCity(String city) { 60 | this.city = city; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Bean{" + "forename='" + forename + '\'' + ", name='" + name + '\'' + ", street='" + street + '\'' 66 | + ", houseNumber=" + houseNumber + ", city='" + city + '\'' + '}'; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/RestructuredBean.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure; 2 | 3 | public class RestructuredBean { 4 | 5 | private String forename; 6 | private String name; 7 | 8 | private Address address; 9 | 10 | public RestructuredBean() { 11 | } 12 | 13 | public RestructuredBean(String forename, String name, Address address) { 14 | this.forename = forename; 15 | this.name = name; 16 | this.address = address; 17 | } 18 | 19 | public String getForename() { 20 | return forename; 21 | } 22 | 23 | public void setForename(String forename) { 24 | this.forename = forename; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Address getAddress() { 36 | return address; 37 | } 38 | 39 | public void setAddress(Address address) { 40 | this.address = address; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "RestructuredBean{" + "forename='" + forename + '\'' + ", name='" + name + '\'' + ", address=" + address 46 | + '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/demo/Address.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.demo; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String houseNumber; 7 | 8 | public Address() { 9 | } 10 | 11 | public Address(String street, String houseNumber) { 12 | this.street = street; 13 | this.houseNumber = houseNumber; 14 | } 15 | 16 | public String getStreet() { 17 | return street; 18 | } 19 | 20 | public void setStreet(String street) { 21 | this.street = street; 22 | } 23 | 24 | public String getHouseNumber() { 25 | return houseNumber; 26 | } 27 | 28 | public void setHouseNumber(String houseNumber) { 29 | this.houseNumber = houseNumber; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Address{" + "street='" + street + '\'' + ", houseNumber='" + houseNumber + '\'' + '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/demo/Family.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.demo; 2 | 3 | public class Family { 4 | 5 | private Person dad; 6 | 7 | public Family() { 8 | } 9 | 10 | public Family(Person dad) { 11 | this.dad = dad; 12 | } 13 | 14 | public Person getDad() { 15 | return dad; 16 | } 17 | 18 | public void setDad(Person dad) { 19 | this.dad = dad; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Family{" + "dad=" + dad + '}'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/demo/Person.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.demo; 2 | 3 | public class Person { 4 | 5 | private String forename; 6 | private String name; 7 | 8 | private Address address; 9 | 10 | public Person() { 11 | } 12 | 13 | public Person(String forename, String name, Address address) { 14 | this.forename = forename; 15 | this.name = name; 16 | this.address = address; 17 | } 18 | 19 | public String getForename() { 20 | return forename; 21 | } 22 | 23 | public void setForename(String forename) { 24 | this.forename = forename; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Address getAddress() { 36 | return address; 37 | } 38 | 39 | public void setAddress(Address address) { 40 | this.address = address; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Person{" + "forename='" + forename + '\'' + ", name='" + name + '\'' + ", address=" + address + '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/demo/PersonFlat.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.demo; 2 | 3 | public class PersonFlat { 4 | private String forename; 5 | private String name; 6 | 7 | private String street; 8 | private String houseNumber; 9 | 10 | public PersonFlat() { 11 | } 12 | 13 | public PersonFlat(String forename, String name, String street, String houseNumber) { 14 | this.forename = forename; 15 | this.name = name; 16 | this.street = street; 17 | this.houseNumber = houseNumber; 18 | } 19 | 20 | public String getForename() { 21 | return forename; 22 | } 23 | 24 | public void setForename(String forename) { 25 | this.forename = forename; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public String getStreet() { 37 | return street; 38 | } 39 | 40 | public void setStreet(String street) { 41 | this.street = street; 42 | } 43 | 44 | public String getHouseNumber() { 45 | return houseNumber; 46 | } 47 | 48 | public void setHouseNumber(String houseNumber) { 49 | this.houseNumber = houseNumber; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/demo/RestructuringDemoTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.demo; 2 | 3 | import com.remondis.remap.AssertMapping; 4 | import com.remondis.remap.Mapper; 5 | import com.remondis.remap.Mapping; 6 | import com.remondis.resample.Samples; 7 | import org.junit.Test; 8 | 9 | public class RestructuringDemoTest { 10 | 11 | @Test 12 | public void shouldRestructurePerson() { 13 | Mapper mapper = Mapping.from(PersonFlat.class) 14 | .to(Family.class) 15 | .omitOtherSourceProperties() 16 | .restructure(Family::getDad) 17 | .applying(flat2PersonMapping -> flat2PersonMapping.restructure(Person::getAddress) 18 | .implicitly()) 19 | .mapper(); 20 | 21 | PersonFlat personFlat = Samples.Default.of(PersonFlat.class) 22 | .get(); 23 | Family family = mapper.map(personFlat); 24 | System.out.println(family); 25 | 26 | AssertMapping.of(mapper) 27 | .expectOtherSourceFieldsToBeOmitted() 28 | .expectRestructure(Family::getDad) 29 | .applying(flat2PersonMapping -> flat2PersonMapping.expectRestructure(Person::getAddress) 30 | .implicitly()) 31 | .ensure(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/ndepth/Bean2.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.ndepth; 2 | 3 | public class Bean2 { 4 | 5 | private Person person; 6 | 7 | public Bean2() { 8 | } 9 | 10 | public Bean2(Person person) { 11 | this.person = person; 12 | } 13 | 14 | public Person getPerson() { 15 | return person; 16 | } 17 | 18 | public void setPerson(Person person) { 19 | this.person = person; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/restructure/ndepth/Person.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.restructure.ndepth; 2 | 3 | import com.remondis.remap.restructure.Address; 4 | 5 | public class Person { 6 | private String forename; 7 | private String name; 8 | 9 | private Address address; 10 | 11 | public Person() { 12 | } 13 | 14 | public Person(Address address) { 15 | this.address = address; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public String getForename() { 27 | return forename; 28 | } 29 | 30 | public void setForename(String forename) { 31 | this.forename = forename; 32 | } 33 | 34 | public Address getAddress() { 35 | return address; 36 | } 37 | 38 | public void setAddress(Address address) { 39 | this.address = address; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/setOperation/A.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.setOperation; 2 | 3 | public class A { 4 | 5 | private String string; 6 | private String anotherString; 7 | 8 | public A() { 9 | super(); 10 | } 11 | 12 | public A(String string, String anotherString) { 13 | super(); 14 | this.string = string; 15 | this.anotherString = anotherString; 16 | } 17 | 18 | public String getString() { 19 | return string; 20 | } 21 | 22 | public void setString(String string) { 23 | this.string = string; 24 | } 25 | 26 | public String getAnotherString() { 27 | return anotherString; 28 | } 29 | 30 | public void setAnotherString(String anotherString) { 31 | this.anotherString = anotherString; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/setOperation/B.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.setOperation; 2 | 3 | public class B { 4 | 5 | private String string; 6 | private Integer integerRef; 7 | private int integer; 8 | 9 | private String valueSet; 10 | 11 | public B(String string, Integer integerRef, int integer, String valueSet) { 12 | super(); 13 | this.string = string; 14 | this.integerRef = integerRef; 15 | this.integer = integer; 16 | this.valueSet = valueSet; 17 | } 18 | 19 | public B() { 20 | super(); 21 | } 22 | 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | public void setString(String string) { 28 | this.string = string; 29 | } 30 | 31 | public Integer getIntegerRef() { 32 | return integerRef; 33 | } 34 | 35 | public void setIntegerRef(Integer integerRef) { 36 | this.integerRef = integerRef; 37 | } 38 | 39 | public int getInteger() { 40 | return integer; 41 | } 42 | 43 | public void setInteger(int integer) { 44 | this.integer = integer; 45 | } 46 | 47 | public String getValueSet() { 48 | return valueSet; 49 | } 50 | 51 | public void setValueSet(String valueSet) { 52 | this.valueSet = valueSet; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/utils/mapOver/MapOverTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.utils.mapOver; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotEquals; 5 | 6 | import org.junit.Test; 7 | 8 | import com.remondis.remap.basic.A; 9 | import com.remondis.remap.basic.B; 10 | 11 | public class MapOverTest { 12 | @Test 13 | public void shouldMapFromSourceToTarget() { 14 | A a1 = new A("moreInA1", "stringA1", 1, 2, 1L, new B("stringB1", 1, 1)); 15 | A a2 = new A("moreInA2", "stringA2", 1, 2, 1L, new B("stringB2", 1, 1)); 16 | 17 | assertNotEquals(a1.getString(), a2.getString()); 18 | assertNotEquals(a1.getB() 19 | .getString(), 20 | a2.getB() 21 | .getString()); 22 | 23 | MapOver mapOver = MapOver.create(A.class) 24 | .mapProperty(A::getString, A::setString) 25 | .goInto(A::getB, A::setB, B.class) 26 | .mapProperty(B::getString, B::setString) 27 | .build(); 28 | 29 | mapOver.mapOver(a1, a2); 30 | 31 | assertEquals(a1.getString(), a2.getString()); 32 | assertEquals(a1.getB() 33 | .getString(), 34 | a2.getB() 35 | .getString()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/visibility/C.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.visibility; 2 | 3 | class C { 4 | 5 | private String string; 6 | 7 | public C() { 8 | super(); 9 | } 10 | 11 | public C(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/visibility/CResource.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.visibility; 2 | 3 | class CResource { 4 | 5 | private String string; 6 | 7 | public CResource() { 8 | super(); 9 | } 10 | 11 | public CResource(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/visibility/VisibilityTest.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.visibility; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.remondis.remap.Mapper; 8 | import com.remondis.remap.Mapping; 9 | 10 | public class VisibilityTest { 11 | @Test 12 | public void testVisibility() { 13 | Mapper mapper = Mapping.from(C.class) 14 | .to(CResource.class) 15 | .mapper(); 16 | 17 | String string = "A string"; 18 | CResource cr = mapper.map(new C(string)); 19 | assertEquals(string, cr.getString()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/writeNull/Destination.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.writeNull; 2 | 3 | public class Destination { 4 | 5 | private String string; 6 | 7 | public Destination() { 8 | super(); 9 | } 10 | 11 | public Destination(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Destination [string=" + string + "]"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/remondis/remap/writeNull/Source.java: -------------------------------------------------------------------------------- 1 | package com.remondis.remap.writeNull; 2 | 3 | public class Source { 4 | 5 | private String string; 6 | 7 | public Source() { 8 | super(); 9 | } 10 | 11 | public Source(String string) { 12 | super(); 13 | this.string = string; 14 | } 15 | 16 | public String getString() { 17 | return string; 18 | } 19 | 20 | public void setString(String string) { 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Source [string=" + string + "]"; 27 | } 28 | 29 | } 30 | --------------------------------------------------------------------------------