use of org.javers.core.Javers in project backend by CatalogueOfLife.
the class ResourceTestBase method printDiff.
protected void printDiff(Object o1, Object o2) {
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(o1, o2);
System.out.println(diff);
}
use of org.javers.core.Javers in project tutorials by eugenp.
the class JaversUnitTest method givenListOfPersons_whenCompare_ThenShouldDetectChanges.
@Test
public void givenListOfPersons_whenCompare_ThenShouldDetectChanges() {
// given
Javers javers = JaversBuilder.javers().build();
Person personThatWillBeRemoved = new Person(2, "Thomas Link");
List<Person> oldList = Lists.asList(new Person(1, "Michael Program"), personThatWillBeRemoved);
List<Person> newList = Lists.asList(new Person(1, "Michael Not Program"));
// when
Diff diff = javers.compareCollections(oldList, newList, Person.class);
// then
assertThat(diff.getChanges()).hasSize(3);
ValueChange valueChange = diff.getChangesByType(ValueChange.class).get(0);
assertThat(valueChange.getPropertyName()).isEqualTo("name");
assertThat(valueChange.getLeft()).isEqualTo("Michael Program");
assertThat(valueChange.getRight()).isEqualTo("Michael Not Program");
ObjectRemoved objectRemoved = diff.getChangesByType(ObjectRemoved.class).get(0);
assertThat(objectRemoved.getAffectedObject().get().equals(personThatWillBeRemoved)).isTrue();
ListChange listChange = diff.getChangesByType(ListChange.class).get(0);
assertThat(listChange.getValueRemovedChanges().size()).isEqualTo(1);
}
use of org.javers.core.Javers in project tutorials by eugenp.
the class JaversUnitTest method givenListOfPerson_whenPersonRemovedAddress_thenDetectThatChange.
@Test
public void givenListOfPerson_whenPersonRemovedAddress_thenDetectThatChange() {
// given
Javers javers = JaversBuilder.javers().build();
PersonWithAddress person = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England")));
PersonWithAddress personWithNewAddress = new PersonWithAddress(1, "Tom", Collections.emptyList());
// when
Diff diff = javers.compare(person, personWithNewAddress);
List objectsByChangeType = diff.getObjectsByChangeType(ObjectRemoved.class);
// then
assertThat(objectsByChangeType).hasSize(1);
assertThat(objectsByChangeType.get(0).equals(new Address("England")));
}
use of org.javers.core.Javers in project concord by walmartlabs.
the class DiffUtils method compare.
public static Map<String, Object> compare(Object left, Object right) {
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(left, right);
CustomChangeProcessor changeProcessor = new CustomChangeProcessor();
javers.processChangeList(diff.getChanges(), changeProcessor);
Map<String, Object> m = changeProcessor.result();
removeIfEmpty(m, KEY_PREVIOUS);
removeIfEmpty(m, KEY_NEW);
return m;
}
use of org.javers.core.Javers in project tutorials by eugenp.
the class JaversUnitTest method givenListOfPerson_whenPersonHasNewAddress_thenDetectThatChange.
@Test
public void givenListOfPerson_whenPersonHasNewAddress_thenDetectThatChange() {
// given
Javers javers = JaversBuilder.javers().build();
PersonWithAddress person = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England")));
PersonWithAddress personWithNewAddress = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England"), new Address("USA")));
// when
Diff diff = javers.compare(person, personWithNewAddress);
List objectsByChangeType = diff.getObjectsByChangeType(NewObject.class);
// then
assertThat(objectsByChangeType).hasSize(1);
assertThat(objectsByChangeType.get(0).equals(new Address("USA")));
}
Aggregations