Auditor implements Serializable { public ChangeEvent detectChanges(HasUuid entity) { if (!isAudited(entity)) { return new ChangeEvent(Collections.emptySortedMap(), ChangeType.UPDATE); } else { final ChangeType changeType = detectChangeType(entity); final SortedMap<String, String> entityChanges; if (this.changes.containsKey(EntityId.getOidFromHasUuid(entity))) { ValueContainer originalContainer = this.changes.get(EntityId.getOidFromHasUuid(entity)); entityChanges = getValueContainerOf(entity).compare(originalContainer); } else { entityChanges = getValueContainerOf(entity).getChanges(); } register(entity); return new ChangeEvent(entityChanges, changeType); } }  void register(HasUuid entity); ChangeEvent detectChanges(HasUuid entity);  }
@Test public void shouldDetectNewEntity() { Entity simpleEntity = new Entity("uuid-1", false, "someValue", 2); Auditor auditor = new Auditor(); ChangeEvent changeEvent = auditor.detectChanges(simpleEntity); Map<String, String> changes = changeEvent.getNewValues(); assertThat(changeEvent.getChangeType(), is(ChangeType.CREATE)); assertThat(changes.size(), is(3)); assertThat(changes.get(Entity.STRING), is("someValue")); assertThat(changes.get(Entity.INTEGER), is("2")); }