@Test(expected = IllegalArgumentException.class) public void testConvertInvalid() throws Exception { converter.convert("BEST"); }
@Override public T convert(String name) throws IllegalArgumentException { if (name == null) { throw new IllegalArgumentException("Cant convert 'null' to " + enumClass.getSimpleName()); } try { return Enum.valueOf(enumClass, name); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase()); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase().replace("-", "_")); } catch (IllegalArgumentException e) { } throw new IllegalArgumentException("Can't convert " + name + " to " + enumClass.getSimpleName()); }
EnumValueConverter extends AbstractValueConverter<T> { @Override public T convert(String name) throws IllegalArgumentException { if (name == null) { throw new IllegalArgumentException("Cant convert 'null' to " + enumClass.getSimpleName()); } try { return Enum.valueOf(enumClass, name); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase()); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase().replace("-", "_")); } catch (IllegalArgumentException e) { } throw new IllegalArgumentException("Can't convert " + name + " to " + enumClass.getSimpleName()); } }
EnumValueConverter extends AbstractValueConverter<T> { @Override public T convert(String name) throws IllegalArgumentException { if (name == null) { throw new IllegalArgumentException("Cant convert 'null' to " + enumClass.getSimpleName()); } try { return Enum.valueOf(enumClass, name); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase()); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase().replace("-", "_")); } catch (IllegalArgumentException e) { } throw new IllegalArgumentException("Can't convert " + name + " to " + enumClass.getSimpleName()); } EnumValueConverter(Class<T> enumClass); }
EnumValueConverter extends AbstractValueConverter<T> { @Override public T convert(String name) throws IllegalArgumentException { if (name == null) { throw new IllegalArgumentException("Cant convert 'null' to " + enumClass.getSimpleName()); } try { return Enum.valueOf(enumClass, name); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase()); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase().replace("-", "_")); } catch (IllegalArgumentException e) { } throw new IllegalArgumentException("Can't convert " + name + " to " + enumClass.getSimpleName()); } EnumValueConverter(Class<T> enumClass); @Override T convert(String name); @Override String toString(T value); }
EnumValueConverter extends AbstractValueConverter<T> { @Override public T convert(String name) throws IllegalArgumentException { if (name == null) { throw new IllegalArgumentException("Cant convert 'null' to " + enumClass.getSimpleName()); } try { return Enum.valueOf(enumClass, name); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase()); } catch (IllegalArgumentException e) { } try { return Enum.valueOf(enumClass, name.toUpperCase().replace("-", "_")); } catch (IllegalArgumentException e) { } throw new IllegalArgumentException("Can't convert " + name + " to " + enumClass.getSimpleName()); } EnumValueConverter(Class<T> enumClass); @Override T convert(String name); @Override String toString(T value);  }