ManagedTypeValueMerger implements ValueMerger { @Override public void mergeValue(FieldSpecification<?, ?> att, Object target, Object originalValue, Object mergedValue, Descriptor attributeDescriptor) { final Object toSet = getValueToSet(mergedValue, attributeDescriptor); EntityPropertiesUtils.setFieldValue(att.getJavaField(), target, toSet); } ManagedTypeValueMerger(UnitOfWorkImpl uow); @Override void mergeValue(FieldSpecification<?, ?> att, Object target, Object originalValue, Object mergedValue,
                           Descriptor attributeDescriptor);  }
@Test public void mergeValueLoadsInstanceFromRepository() throws Exception { final OWLClassA orig = Generators.generateOwlClassAInstance(); final OWLClassA merged = new OWLClassA(orig); final OWLClassD target = new OWLClassD(Generators.createIndividualIdentifier()); when(uow.readObject(OWLClassA.class, merged.getUri(), descriptor)).thenReturn(orig); merger.mergeValue(refASpec, target, null, merged, descriptor); verify(uow).readObject(OWLClassA.class, merged.getUri(), descriptor); assertSame(orig, target.getOwlClassA()); }
@Test public void mergeValueSetsValueDirectlyWhenItIsNull() throws Exception { final OWLClassD target = new OWLClassD(Generators.createIndividualIdentifier()); target.setOwlClassA(Generators.generateOwlClassAInstance()); merger.mergeValue(refASpec, target, target.getOwlClassA(), null, descriptor); assertNull(target.getOwlClassA()); }
@Test public void mergeValueSetsTheMergedValueDirectlyWhenItRepresentsANewInstance() throws Exception { final OWLClassD target = new OWLClassD(Generators.createIndividualIdentifier()); target.setOwlClassA(Generators.generateOwlClassAInstance()); final OWLClassA merged = Generators.generateOwlClassAInstance(); merger.mergeValue(refASpec, target, target.getOwlClassA(), merged, descriptor); assertSame(merged, target.getOwlClassA()); }
@Test public void mergeSetsTheMergedValueDirectlyWhenItHasNoIdentifier() throws Exception { final OWLClassD target = new OWLClassD(Generators.createIndividualIdentifier()); target.setOwlClassA(Generators.generateOwlClassAInstance()); final OWLClassA merged = Generators.generateOwlClassAInstance(); merged.setUri(null); when(uow.readObject(any(), isNull(), any())).thenThrow(new NullPointerException()); merger.mergeValue(refASpec, target, target.getOwlClassA(), merged, descriptor); assertSame(merged, target.getOwlClassA()); }