### Question:
AcmDiffService { public AcmDiff compareObjects(Object oldObj, Object newObj) { Map<Object, List<AcmChange>> alreadyProcessed = new HashMap<>(); AcmObjectChange acmObjectChange = compareObjects(null, null, oldObj, newObj, alreadyProcessed); AcmDiff diff = new AcmObjectDiff(acmObjectChange, getObjectConverter()); return diff; }  void initConfigurationMap(); AcmDiff compareObjects(Object oldObj, Object newObj); AcmCollectionChange compareCollections(Collection oldCollection, Collection newCollection); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); String getJsonConfiguration(); void setJsonConfiguration(String jsonConfiguration);  }### Answer:
@Test public void compareObjectsNoChanges() { TestPerson newPerson = SerializationUtils.clone(oldPerson); AcmDiff diff = diffService.compareObjects(oldPerson, newPerson); assertEquals(0, diff.getChangesAsList().size()); }
@Test public void compareObjectsCollectionElementRemoved() { TestPerson newPerson = SerializationUtils.clone(oldPerson); newPerson.getAttributeList().remove(0); AcmDiff diff = diffService.compareObjects(oldPerson, newPerson); assertEquals(1, diff.getChangesAsList().size()); AcmChange change = diff.getChangesAsList().get(0); assertTrue(change.isLeaf()); assertTrue(change instanceof AcmCollectionElementRemoved); AcmChangeDisplayable displayable = (AcmChangeDisplayable) change; assertEquals("Value 1", displayable.getOldValue()); assertEquals(null, displayable.getNewValue()); }
@Test public void compareObjectsCollectionElementAdded() { TestPerson newPerson = SerializationUtils.clone(oldPerson); TestAttribute testAttribute = new TestAttribute(); testAttribute.setId(6L); testAttribute.setValue("value 6"); newPerson.getAttributeList().add(testAttribute); AcmDiff diff = diffService.compareObjects(oldPerson, newPerson); assertEquals(1, diff.getChangesAsList().size()); AcmChange change = diff.getChangesAsList().get(0); assertTrue(change.isLeaf()); assertTrue(change instanceof AcmCollectionElementAdded); }
@Test public void compareObjectsReplaced() { TestPerson newPerson = SerializationUtils.clone(oldPerson); TestAttribute defaultAttribute = new TestAttribute(); defaultAttribute.setId(2L); defaultAttribute.setValue("changed value"); newPerson.setDefaultAttribute(defaultAttribute); AcmDiff diff = diffService.compareObjects(oldPerson, newPerson); assertEquals(1, diff.getChangesAsList().size()); AcmChange change = diff.getChangesAsList().get(0); assertTrue(change instanceof AcmObjectReplaced); AcmObjectReplaced acmObjectReplaced = (AcmObjectReplaced) change; assertEquals(acmObjectReplaced.getOldObject(), oldPerson.getDefaultAttribute()); assertEquals(acmObjectReplaced.getNewObject(), defaultAttribute); assertEquals("Value 4", acmObjectReplaced.getOldValue()); assertEquals("changed value", acmObjectReplaced.getNewValue()); }
@Test public void compareSameObjectReference() { TestPerson newPerson = SerializationUtils.clone(oldPerson); newPerson.getDefaultAttribute().setValue("1231231"); AcmDiff diff = diffService.compareObjects(oldPerson, newPerson); assertEquals(1, diff.getChangesAsList().size()); }