package org.javers.core.examples;

import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
import org.javers.core.diff.Diff;
import org.javers.core.examples.model.Address;
import org.javers.core.examples.model.Employee;
import org.javers.core.examples.model.EmployeeBuilder;
import org.junit.Test;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.javers.core.diff.ListCompareAlgorithm.LEVENSHTEIN_DISTANCE;

public class BasicEntityDiffExample {

  @Test
  public void shouldCompareTwoEntityObjects() {
    //given
    Javers javers = JaversBuilder.javers()
            .withListCompareAlgorithm(LEVENSHTEIN_DISTANCE)
            .build();

    Employee tommyOld = EmployeeBuilder.Employee("Frodo")
            .withAge(40)
            .withPosition("Townsman")
            .withSalary(10_000)
            .withPrimaryAddress(new Address("Shire"))
            .withSkills("management")
            .withSubordinates(new Employee("Sam"))
            .build();

    Employee tommyNew = EmployeeBuilder.Employee("Frodo")
            .withAge(41)
            .withPosition("Hero")
            .withBoss(new Employee("Gandalf"))
            .withPrimaryAddress(new Address("Mordor"))
            .withSalary(12_000)
            .withSkills("management", "agile coaching")
            .withSubordinates(new Employee("Sméagol"), new Employee("Sam"))
            .build();

    //when
    Diff diff = javers.compare(tommyOld, tommyNew);

    //then
    assertThat(diff.getChanges()).hasSize(9);

    System.out.println(diff);

    System.out.println(javers.getJsonConverter().toJson(diff));
  }
}

@@ -531,15 +531,10 @@
 ntit
-yObject
+ie
 s() 
@@ -1516,24 +1516,49 @@
 asSize(9);%0A%0A
+    // diff pretty print%0A
     System.o
@@ -1572,24 +1572,44 @@
 tln(diff);%0A%0A
+    // diff as JSON%0A
     System.o

test fixes