### Question:
EnumPropertyConverter extends AbstractPropertyConverter { @Override public Object convert(String value, Context context) throws IllegalArgumentException { value = value.trim(); Enum[] names = (Enum[]) context.getTargetType().getEnumConstants(); for (Enum name : names) { if (name.name().equals(value) || name.toString().equals(value)) return name; } throw new IllegalArgumentException("value must be one of " + allowedNames(names)); }  @Override boolean supports(Class<?> type); @Override Object convert(String value, Context context);  }### Answer:
@Test public void testConvert() throws Exception { context.checking(new Expectations() { { oneOf(converterContext).getTargetType(); will(returnValue(Color.class)); } }); assertThat((Color) converter.convert(Color.RED.name(), converterContext), is(equalTo(Color.RED))); }
@Test public void testConvertUsingEnumWithToString() throws Exception { context.checking(new Expectations() { { oneOf(converterContext).getTargetType(); will(returnValue(BadColor.class)); } }); assertThat((BadColor) converter.convert("RED", converterContext), is(equalTo(BadColor.RED))); }
@Test(expected = IllegalArgumentException.class) public void testConvertWithInvalidName() throws Exception { context.checking(new Expectations() { { oneOf(converterContext).getTargetType(); will(returnValue(Color.class)); } }); converter.convert("NOT A COLOR", converterContext); }