Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whys this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException is caught in com.github.dozermapper.core.converters.EnumConverter#convert and then it is wrapped in MappingException and threw out.
So the expected exception should be MappingException, not the original IllegalArgumentException.


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

Expand Down