StringEnumTypeConverter implements TypeConverter<String, ENUM_TYPE> { @Override public ENUM_TYPE convert(String object, SyntheticField domainField, Object domainObject, String... tags) throws JTransfoException { if (null == object || 0 == object.length()) { return null; } return (ENUM_TYPE) Enum.valueOf(enumClass, object); } StringEnumTypeConverter(Class<ENUM_TYPE> enumClass); @Override boolean canConvert(Type realToType, Type realDomainType); @Override ENUM_TYPE convert(String object, SyntheticField domainField, Object domainObject, String... tags); @Override String reverse(ENUM_TYPE object, SyntheticField toField, Object toObject, String... tags);  }
@Test public void testConvert() throws Exception { assertThat(enumTypeConverter.convert(Gender.MALE.name(), genderField, null)).isEqualTo(Gender.MALE); assertThat(enumTypeConverter.convert(Gender.FEMALE.name(), genderField, null)).isEqualTo(Gender.FEMALE); assertThat(enumTypeConverter.convert(null, genderField, null)).isNull(); assertThat(enumTypeConverter.convert("", genderField, null)).isNull(); exception.expect(IllegalArgumentException.class); assertThat(enumTypeConverter.convert("blabla", genderField, null)); }