@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("32a00", MyCustomEnum.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("32a00 is not a valid option."))); } }
@SuppressWarnings("unchecked") public T convert(String value, Class<? extends T> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } if (Character.isDigit(value.charAt(0))) { return resolveByOrdinal(value, (Class<T>) type, bundle); } else { return resolveByName(value, (Class<T>) type, bundle); } }
EnumConverter implements Converter<T> { @SuppressWarnings("unchecked") public T convert(String value, Class<? extends T> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } if (Character.isDigit(value.charAt(0))) { return resolveByOrdinal(value, (Class<T>) type, bundle); } else { return resolveByName(value, (Class<T>) type, bundle); } } }
EnumConverter implements Converter<T> { @SuppressWarnings("unchecked") public T convert(String value, Class<? extends T> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } if (Character.isDigit(value.charAt(0))) { return resolveByOrdinal(value, (Class<T>) type, bundle); } else { return resolveByName(value, (Class<T>) type, bundle); } }  }
EnumConverter implements Converter<T> { @SuppressWarnings("unchecked") public T convert(String value, Class<? extends T> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } if (Character.isDigit(value.charAt(0))) { return resolveByOrdinal(value, (Class<T>) type, bundle); } else { return resolveByName(value, (Class<T>) type, bundle); } }  @SuppressWarnings("unchecked") T convert(String value, Class<? extends T> type, ResourceBundle bundle); }
EnumConverter implements Converter<T> { @SuppressWarnings("unchecked") public T convert(String value, Class<? extends T> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } if (Character.isDigit(value.charAt(0))) { return resolveByOrdinal(value, (Class<T>) type, bundle); } else { return resolveByName(value, (Class<T>) type, bundle); } }  @SuppressWarnings("unchecked") T convert(String value, Class<? extends T> type, ResourceBundle bundle);  }