Skip to content

Commit

Permalink
#642 Support the conversion of String In Map To Enum (#643)
Browse files Browse the repository at this point in the history
* #642 Support the conversion of String In Map To Enum

*  #642 Support the conversion of String In Map To Enum

* Refactor after code review

* Update according to the comments of review
  • Loading branch information
yuanpli authored and garethahealy committed Jun 11, 2018
1 parent 213d0a7 commit d5de712
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public boolean accepts(Class<?> aClass) {
|| Character.class.equals(aClass)
|| Boolean.class.equals(aClass)
|| java.util.Date.class.isAssignableFrom(aClass)
|| java.util.Calendar.class.isAssignableFrom(aClass);
|| java.util.Calendar.class.isAssignableFrom(aClass)
|| aClass.isEnum();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.dozermapper.core.functional_tests;

import java.util.HashMap;
import java.util.Map;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
Expand Down Expand Up @@ -91,6 +92,15 @@ public static void setup() {
.build();
}

@Test
public void canStringInMapMapsToEnum() {
Map src = newInstance(HashMap.class);
src.put("destType", "FOO");

MyBeanPrime dest = enumMappingOverriedEnumToBasedEnum.map(src, MyBeanPrime.class);
assertEquals("FOO", dest.getDestType().toString());
}

@Test
public void canOverriddenEnumMapsToBasedEnum() {
MyBean src = newInstance(MyBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public class EnumMapping_WithExceptionsLoggedTest extends AbstractFunctionalTest
public void testEnumMapsToNonexistEnumValue() {
LOG.error("WithExceptionsLoggedTest; 'IllegalArgumentException: No enum constant com.github.dozermapper.core.vo.enumtest.DestType.BAR'");

testEnumMapsToNonexistEnumValueEE.expectMessage("No enum constant com.github.dozermapper.core.vo.enumtest.DestType.BAR");
testEnumMapsToNonexistEnumValueEE.expect(IllegalArgumentException.class);
testEnumMapsToNonexistEnumValueEE.expectMessage("Cannot convert [BAR] to enum of type class com.github.dozermapper.core.vo.enumtest.DestType");
testEnumMapsToNonexistEnumValueEE.expect(MappingException.class);

mapper = getMapper("mappings/enumMapping.xml");

Expand Down

0 comments on commit d5de712

Please sign in to comment.