@Test
public void testCustomConverterMapping() throws Exception {
mapper = getMapper(new String[] { "dozerBeanMapping.xml" });
TestCustomConverterObject obj = newInstance(TestCustomConverterObject.class);
CustomDoubleObjectIF doub = newInstance(CustomDoubleObject.class);
doub.setTheDouble(15);
CustomDoubleObjectIF doub2 = newInstance(CustomDoubleObject.class);
doub2.setTheDouble(15);
obj.setAttribute(doub);
Collection<CustomDoubleObjectIF> list = newInstance(ArrayList.class);
list.add(doub2);
obj.setNames(list);
TestCustomConverterObjectPrime dest = mapper.map(obj, TestCustomConverterObjectPrime.class);
assertEquals("Custom Converter failed", dest.getDoubleAttribute().doubleValue() + "", "15.0");
assertEquals("Custom Converter failed", ((Double) dest.getNames().iterator().next()).doubleValue() + "", "15.0");
TestCustomConverterObjectPrime objp = newInstance(TestCustomConverterObjectPrime.class);
objp.setDoubleAttribute(new Double(15));
Collection<Double> list2 = newInstance(ArrayList.class);
list2.add(new Double(10));
objp.setNames(list2);
TestCustomConverterObject destp = mapper.map(objp, TestCustomConverterObject.class);
assertEquals("Custom Converter failed", destp.getAttribute().getTheDouble() + "", "15.0");
assertEquals("Custom Converter failed", ((CustomDoubleObjectIF) destp.getNames().iterator().next()).getTheDouble() + "", "10.0");
destp.getAttribute().setName("testName");
// pass by reference
mapper.map(objp, destp);
assertEquals("Custom Converter failed", destp.getAttribute().getTheDouble() + "", "15.0");
assertEquals("testName", destp.getAttribute().getName());
// test primitive double
TestCustomConverterObjectPrime prime = newInstance(TestCustomConverterObjectPrime.class);
prime.setPrimitiveDoubleAttribute(25.00);
TestCustomConverterObject obj2 = mapper.map(prime, TestCustomConverterObject.class);
CustomDoubleObjectIF customDouble = obj2.getPrimitiveDoubleAttribute();
assertNotNull(customDouble);
assertTrue(prime.getPrimitiveDoubleAttribute() == obj2.getPrimitiveDoubleAttribute().getTheDouble());
// test conversion in the other direction
prime = mapper.map(obj2, TestCustomConverterObjectPrime.class);