Skip to content

Commit

Permalink
Refactor the object differ for use in tests. #2643.
Browse files Browse the repository at this point in the history
This enables reliable tests that serialization / deserialization perfectly restores a Graph.
In some ways this simplifies the differ, but it also ensures that it performs a very deep recursive comparison of almost every object.
Also added tests that can compare two references to the same object, which provide strong evidence that the differ actually works.
  • Loading branch information
abyrd committed Nov 2, 2018
1 parent 98af5d2 commit ded6fd2
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 354 deletions.
10 changes: 0 additions & 10 deletions src/main/java/org/opentripplanner/common/diff/DiffPrinter.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/org/opentripplanner/common/diff/DiffType.java

This file was deleted.

39 changes: 9 additions & 30 deletions src/main/java/org/opentripplanner/common/diff/Difference.java
Expand Up @@ -17,39 +17,18 @@


public class Difference { public class Difference {


public DiffType diffType; Object a;
public String property; Object b;
public Object oldValue; String message;
public Object newValue;



public Difference(Object a, Object b) {
public Difference(String property, Object oldValue, Object newValue) { this.a = a;
this.diffType = DiffType.VALUE_CHANGE; this.b = b;
this.property = property;
this.oldValue = oldValue;
this.newValue = newValue;
}

public Difference(DiffType diffType, String property, Object oldValue, Object newValue) {
this.diffType = diffType;
this.property = property;
this.oldValue = oldValue;
this.newValue = newValue;
} }



public Difference withMessage (String formatString, Object... args) {
public String toString() { message = String.format(formatString, args);

return this;
if (DiffType.COLLECTION_ADD.equals(diffType)) {
return property + ": added " + newValue;
}

if (DiffType.COLLECTION_REMOVE.equals(diffType)) {
return property + ": removed " + oldValue;
}


return property + ": " + oldValue + " => " + newValue;
} }


} }

This file was deleted.

0 comments on commit ded6fd2

Please sign in to comment.