ObjectConverter implements ConverterWrapper<Object, Object> { @Override public Object convertToAttribute(Object value) { if (value instanceof NamedResource) { return ((NamedResource) value).getIdentifier(); } else if (value instanceof LangString) { final LangString ls = (LangString) value; if (preferMultilingualString) { final MultilingualString ms = new MultilingualString(); ms.set(ls.getLanguage().orElse(null), ls.getValue()); return ms; } else { return ls.getValue(); } } return value; } ObjectConverter();  ObjectConverter(boolean preferMultilingualString); @Override Object convertToAxiomValue(Object value); @Override Object convertToAttribute(Object value); @Override boolean supportsAxiomValueType(Class<?> type); boolean doesPreferMultilingualString();  }
@Test void convertToAttributeDoesNothingToLiteralValues() { final Object valueOne = new Date(); final Object valueTwo = 1237; assertSame(valueOne, sut.convertToAttribute(valueOne)); assertSame(valueTwo, sut.convertToAttribute(valueTwo)); }
@Test void convertToAttributeTransformsNamedResourceToUri() { final NamedResource value = NamedResource.create(Generators.createIndividualIdentifier()); assertEquals(value.getIdentifier(), sut.convertToAttribute(value)); }
@Test void convertToAttributeTransformsLangStringToMultilingualStringWhenMultilingualStringsArePreferred() { final LangString value = new LangString("test", "en"); assertEquals(new MultilingualString(Collections.singletonMap("en", "test")), sut.convertToAttribute(value)); }
@Test void convertToAttributeTransformsLangStringToStringWhenMultilingualStringsAreNotPreferred() { this.sut = new ObjectConverter(false); final LangString value = new LangString("test", "en"); assertEquals(value.getValue(), sut.convertToAttribute(value)); }