Skip to content

Commit

Permalink
Add failed test case for issue45
Browse files Browse the repository at this point in the history
  • Loading branch information
Spikhalskiy committed Jan 3, 2013
1 parent 344d8b5 commit 2e6bc71
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
Expand Up @@ -89,6 +89,7 @@ public void setMapper(Mapper mapper) {
this.mapper = mapper;
}

@Override
public BidirectionalOneConvert convertFrom(BidirectionalOne arg0, BidirectionalOneConvert arg1) {
return mapper.map(arg0, BidirectionalOneConvert.class);
}
Expand Down
@@ -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.

Copy link
@buzdin

buzdin Jan 3, 2013

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)

This comment has been minimized.

Copy link
@Spikhalskiy

Spikhalskiy Jan 3, 2013

Author Owner

Ok, no problem.

This comment has been minimized.

Copy link
@Spikhalskiy

Spikhalskiy Jan 3, 2013

Author Owner

Done :)

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;
}
}
}
@@ -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;
}
}
@@ -0,0 +1,8 @@
package org.dozer.vo.mapperaware;

/**
* @author Dmitry Spikhalskiy
* @since 03.01.13
*/
public class MapperAwareSimpleInternal {
}
@@ -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;
}
}
9 changes: 9 additions & 0 deletions core/src/test/resources/mapper-aware.xml
Expand Up @@ -21,4 +21,13 @@
</field>
</mapping>

<mapping>
<class-a>org.dozer.vo.mapperaware.MapperAwareSimpleSrc</class-a>
<class-b>org.dozer.vo.mapperaware.MapperAwareSimpleDest</class-b>
<field custom-converter-id="issue45Converter">
<a>one</a>
<b>one</b>
</field>
</mapping>

</mappings>
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -64,8 +64,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>

This comment has been minimized.

Copy link
@buzdin

buzdin Jan 3, 2013

This would be great as a separate change list as not directly related, but no problems.

This comment has been minimized.

Copy link
@Spikhalskiy

Spikhalskiy Jan 3, 2013

Author Owner

I agree. You can fix it in master and I merge your changes to my branch if you wish.

This comment has been minimized.

Copy link
@buzdin

buzdin Jan 3, 2013

No need for that. Just have to remember to write it in release notes and close according issue.

<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 2e6bc71

Please sign in to comment.