### Question:
HyphenateEnumConverter implements Converter<E>, Serializable { @Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); } HyphenateEnumConverter(Class<E> enumType); static HyphenateEnumConverter<E> of(Class<E> enumType); @Override E convert(String value);  }### Answer:
@Test public void convertMyEnum() { hyphenateEnumConverter = new HyphenateEnumConverter(MyEnum.class); MyEnum myEnum = (MyEnum) hyphenateEnumConverter.convert("DISCARD"); assertEquals(myEnum, MyEnum.DISCARD); myEnum = (MyEnum) hyphenateEnumConverter.convert("discard"); assertEquals(myEnum, MyEnum.DISCARD); myEnum = (MyEnum) hyphenateEnumConverter.convert("READ_UNCOMMITTED"); assertEquals(myEnum, MyEnum.READ_UNCOMMITTED); myEnum = (MyEnum) hyphenateEnumConverter.convert("read-uncommitted"); assertEquals(myEnum, MyEnum.READ_UNCOMMITTED); myEnum = (MyEnum) hyphenateEnumConverter.convert("SIGUSR1"); assertEquals(myEnum, MyEnum.SIGUSR1); myEnum = (MyEnum) hyphenateEnumConverter.convert("sigusr1"); assertEquals(myEnum, MyEnum.SIGUSR1); myEnum = (MyEnum) hyphenateEnumConverter.convert("TrendBreaker"); assertEquals(myEnum, MyEnum.TrendBreaker); myEnum = (MyEnum) hyphenateEnumConverter.convert("trend-breaker"); assertEquals(myEnum, MyEnum.TrendBreaker); myEnum = (MyEnum) hyphenateEnumConverter.convert("MAKING_LifeDifficult"); assertEquals(myEnum, MyEnum.MAKING_LifeDifficult); myEnum = (MyEnum) hyphenateEnumConverter.convert("making-life-difficult"); assertEquals(myEnum, MyEnum.MAKING_LifeDifficult); myEnum = (MyEnum) hyphenateEnumConverter.convert("YeOldeJBoss"); assertEquals(myEnum, MyEnum.YeOldeJBoss); myEnum = (MyEnum) hyphenateEnumConverter.convert("ye-olde-jboss"); assertEquals(myEnum, MyEnum.YeOldeJBoss); }
@Test public void convertMyOtherEnum() { hyphenateEnumConverter = new HyphenateEnumConverter(MyOtherEnum.class); MyOtherEnum myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("makingLifeDifficult"); assertEquals(myOtherEnum, MyOtherEnum.makingLifeDifficult); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("making-life-difficult"); assertEquals(myOtherEnum, MyOtherEnum.makingLifeDifficult); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("READ__UNCOMMITTED"); assertEquals(myOtherEnum, MyOtherEnum.READ__UNCOMMITTED); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("read-uncommitted"); assertEquals(myOtherEnum, MyOtherEnum.READ__UNCOMMITTED); }
@Test public void testIllegalEnumConfigUtilConversion() { hyphenateEnumConverter = new HyphenateEnumConverter(MyEnum.class); assertThrows(IllegalArgumentException.class, () -> hyphenateEnumConverter.convert("READUNCOMMITTED")); }