EnumConverter implements ConverterWrapper<E, Object> { @Override public E convertToAttribute(Object value) { try { return Enum.valueOf(enumType, ToLexicalFormConverter.INSTANCE.convertToAttribute(value)); } catch (IllegalArgumentException e) { throw new UnsupportedTypeTransformation("Unable to transform value " + value + " to enum " + enumType, e); } } EnumConverter(Class<E> enumType); @Override boolean supportsAxiomValueType(Class<?> type); @Override Object convertToAxiomValue(E value); @Override E convertToAttribute(Object value);  }
@Test public void convertToAttributeValueUsesEnumValueOf() { final EnumConverter<OWLClassM.Severity> sut = new EnumConverter<>(OWLClassM.Severity.class); final OWLClassM.Severity result = sut.convertToAttribute(OWLClassM.Severity.HIGH.toString()); assertEquals(OWLClassM.Severity.HIGH, result); }
@Test public void convertToAttributeValueThrowsUnsupportedTypeTransformationForUnknownEnumValue() { final EnumConverter<OWLClassM.Severity> sut = new EnumConverter<>(OWLClassM.Severity.class); assertThrows(UnsupportedTypeTransformation.class, () -> sut.convertToAttribute("test")); }