MapValueMerger implements ValueMerger { @Override public void mergeValue(FieldSpecification<?, ?> att, Object target, Object originalValue, Object mergedValue, Descriptor attributeDescriptor) { final Map<?, ?> mergedMap = (Map<?, ?>) mergedValue; if (mergedMap == null) { EntityPropertiesUtils.setFieldValue(att.getJavaField(), target, null); return; } final Map<Object, Object> newMap = CollectionFactory.createDefaultMap(); newMap.putAll(mergedMap); EntityPropertiesUtils.setFieldValue(att.getJavaField(), target, newMap); }  @Override void mergeValue(FieldSpecification<?, ?> att, Object target, Object originalValue, Object mergedValue,
                           Descriptor attributeDescriptor);  }
@Test public void mergeMergesPropertiesMap() throws Exception { final OWLClassB orig = new OWLClassB(Generators.createIndividualIdentifier()); orig.setProperties(Generators.generateStringProperties()); final OWLClassB merged = new OWLClassB(orig.getUri()); merged.setProperties(new HashMap<>(orig.getProperties())); final String newKey = Generators.createPropertyIdentifier().toString(); merged.getProperties().put(newKey, new HashSet<>()); final String vOne = "valueOne"; final String vTwo = "valueTwo"; merged.getProperties().get(newKey).add(vOne); merged.getProperties().get(newKey).add(vTwo); merger.mergeValue(propertiesSpec, orig, orig.getProperties(), merged.getProperties(), descriptor); assertEquals(merged.getProperties(), orig.getProperties()); }
@Test public void mergeSetsFieldValueToNullWhenMergedInstanceValueIsNull() throws Exception { final OWLClassB orig = new OWLClassB(Generators.createIndividualIdentifier()); orig.setProperties(Generators.generateStringProperties()); final OWLClassB merged = new OWLClassB(orig.getUri()); merged.setProperties(null); merger.mergeValue(propertiesSpec, orig, orig.getProperties(), merged.getProperties(), descriptor); assertNull(orig.getProperties()); }