forked from DozerMapper/dozer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
344d8b5
commit 2e6bc71
Showing
7 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
core/src/test/java/org/dozer/functional_tests/mapperaware/SecondUsingMapInternalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.dozer.functional_tests.mapperaware; | ||
|
||
import org.dozer.CustomConverter; | ||
import org.dozer.DozerBeanMapper; | ||
import org.dozer.Mapper; | ||
import org.dozer.MapperAware; | ||
import org.dozer.vo.mapperaware.MapperAwareSimpleDest; | ||
import org.dozer.vo.mapperaware.MapperAwareSimpleInternal; | ||
import org.dozer.vo.mapperaware.MapperAwareSimpleSrc; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
|
||
/** | ||
* @author Dmitry Spikhalskiy | ||
* @see <a href="https://github.com/DozerMapper/dozer/issues/45">issue</a> | ||
*/ | ||
public class SecondUsingMapInternalTest { | ||
DozerBeanMapper mapper; | ||
|
||
@Before | ||
public void setup() { | ||
mapper = new DozerBeanMapper(); | ||
List<String> mappingFileUrls = new ArrayList<String>(); | ||
mappingFileUrls.add("mapper-aware.xml"); | ||
|
||
Map<String, CustomConverter> customConvertersWithId = new HashMap<String, CustomConverter>(); | ||
customConvertersWithId.put("issue45Converter", new Issue45Converter()); | ||
|
||
mapper.setCustomConvertersWithId(customConvertersWithId); | ||
mapper.setMappingFiles(mappingFileUrls); | ||
} | ||
|
||
@Test | ||
public void issue45Test() { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
MapperAwareSimpleSrc src = new MapperAwareSimpleSrc(); | ||
src.setOne(new MapperAwareSimpleInternal()); | ||
MapperAwareSimpleDest dst = new MapperAwareSimpleDest(); | ||
mapper.map(src, dst); | ||
assertNotNull(dst.getOne()); | ||
} | ||
|
||
private static class Issue45Converter implements CustomConverter, MapperAware { | ||
|
||
private Mapper mapper; | ||
|
||
@Override | ||
public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) { | ||
MapperAwareSimpleInternal a = (MapperAwareSimpleInternal)sourceFieldValue; | ||
|
||
MapperAwareSimpleInternal b = new MapperAwareSimpleInternal(); | ||
mapper.map(a, b); | ||
MapperAwareSimpleInternal b2 = new MapperAwareSimpleInternal(); | ||
mapper.map(a, b2); //throws NPE | ||
return b2; | ||
} | ||
|
||
@Override | ||
public void setMapper(Mapper mapper) { | ||
this.mapper = mapper; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/test/java/org/dozer/vo/mapperaware/MapperAwareSimpleDest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.dozer.vo.mapperaware; | ||
|
||
/** | ||
* @author Dmitry Spikhalskiy | ||
* @since 03.01.13 | ||
*/ | ||
public class MapperAwareSimpleDest { | ||
private MapperAwareSimpleInternal one; | ||
|
||
public MapperAwareSimpleInternal getOne() { | ||
return one; | ||
} | ||
|
||
public void setOne(MapperAwareSimpleInternal one) { | ||
this.one = one; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
core/src/test/java/org/dozer/vo/mapperaware/MapperAwareSimpleInternal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.dozer.vo.mapperaware; | ||
|
||
/** | ||
* @author Dmitry Spikhalskiy | ||
* @since 03.01.13 | ||
*/ | ||
public class MapperAwareSimpleInternal { | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/test/java/org/dozer/vo/mapperaware/MapperAwareSimpleSrc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.dozer.vo.mapperaware; | ||
|
||
/** | ||
* @author Dmitry Spikhalskiy | ||
* @since 03.01.13 | ||
*/ | ||
public class MapperAwareSimpleSrc { | ||
private MapperAwareSimpleInternal one; | ||
|
||
public MapperAwareSimpleInternal getOne() { | ||
return one; | ||
} | ||
|
||
public void setOne(MapperAwareSimpleInternal one) { | ||
this.one = one; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,8 @@ | |
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
This comment has been minimized.
Sorry, something went wrong.
buzdin
|
||
<configuration> | ||
<source>1.5</source> | ||
<target>1.5</target> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
|
I would not use issue numbers in the code since issue trackers come and go, but Dozer remains :)
Would be great to change to meaningful names instead (even if they are long)