EnumConverter extends ConverterSupport { @Override protected Object convertToObject(final String text) throws Exception { for (Enum n : (Enum[]) getType().getEnumConstants()) { if (n.name().equalsIgnoreCase(text)) { return n; } } int index = Integer.parseInt(text); Method method = getType().getMethod("values"); Object[] values = (Object[]) method.invoke(null); return values[index]; } EnumConverter(final Class type);   }
@Test public void testCaseSensitivity() throws Exception { TestEnum subject; subject = (TestEnum) new EnumConverter(TestEnum.class).convertToObject("foo"); assertThat(subject).isEqualTo(TestEnum.FOO); subject = (TestEnum) new EnumConverter(TestEnum.class).convertToObject("BaR"); assertThat(subject).isEqualTo(TestEnum.BAR); }