Package de.danielbechler.diff

Examples of de.danielbechler.diff.ObjectDifferBuilder


  public static void main(final String[] args)
  {
    final User base = new User("foo", "1234");
    final User working = new User("foo", "9876");

    final ObjectDifferBuilder builder = ObjectDifferBuilder.startBuilding();

    // (Option 1) Causes the ObjectDiffer to ignore the 'password' property of the root object
    builder.inclusion().exclude().node(NodePath.with("password"));

    final DiffNode node = builder.build().compare(working, base);

    node.visit(new PrintingVisitor(working, base));

    // Output with ignore: Property at path '/' has not changed
    // Output without ignore: Property at path '/password' has changed from [ 1234 ] to [ 9876 ]
View Full Code Here


    final PropertyClass prop = new PropertyClass("1", "2");
    final EncompassingClass base = new EncompassingClass(prop);
    final PropertyClass prop2 = new PropertyClass("1", "3");
    final EncompassingClass working = new EncompassingClass(prop2);

    final ObjectDifferBuilder builder = ObjectDifferBuilder.startBuilding();

    // (Option 1) Causes the ObjectDiffer to compare using the method "getProp1" on the 'prop' property of the root object
    builder.comparison()
        .ofNode(NodePath.with("prop"))
        .toUseEqualsMethodOfValueProvidedByMethod("getProp1");

    final DiffNode node = builder.build().compare(working, base);

    node.visit(new PrintingVisitor(working, base));

    // Output with ignore:
    //  Property at path '/' has not changed
View Full Code Here

    final DiffNode verification = objectDiffer.compare(obj1, modifiedObj1);
    verification.visit(new PrintingVisitor(obj1, modifiedObj1));
    assertThat(verification).child(nodePath).hasState(DiffNode.State.CHANGED).hasChildren(1);

    // verify that the node can't be found, when it's excluded
    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    objectDifferBuilder.inclusion().exclude().node(nodePath);
    objectDiffer = objectDifferBuilder.build();
    final DiffNode node = objectDiffer.compare(obj1, modifiedObj1);
    node.visit(new PrintingVisitor(obj1, modifiedObj1));
    assertThat(node).child(nodePath).doesNotExist();
  }
View Full Code Here

  public void test_returns_full_property_graph_of_added_collection_items()
  {
    final Map<String, ObjectWithString> base = Collections.emptyMap();
    final Map<String, ObjectWithString> working = Collections.singletonMap("foo", new ObjectWithString("bar"));

    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    final ObjectDiffer differ = objectDifferBuilder.build();

    final DiffNode node = differ.compare(working, base);

    node.visit(new NodeHierarchyVisitor());
View Full Code Here

{
  @Test
  public void shouldDiffThings()
  {
    final List<String> propertyNames = asList("things", "include");
    ObjectDifferBuilder builder = ObjectDifferBuilder.startBuilding();
    for (final String name : propertyNames)
    {
      final NodePath nodePath = NodePath.with(name);
      builder.comparison().ofNode(nodePath).toUseEqualsMethod();
      builder.inclusion().include().node(nodePath);
    }

    final Thing thingOne = new Thing("a", "b");
    final Thing thingTwo = new Thing("aa", "bb");

    final ThingHolder first = new ThingHolder(singleton(thingOne), "ignore", "include");
    final ThingHolder second = new ThingHolder(singleton(thingTwo), "ignore this change", "include");
    final DiffNode compareResults = builder.build().compare(first, second);

    assertThat(compareResults.isChanged(), is(true));
  }
View Full Code Here

  public void testIncludeCollectionAttribute()
  {
    final Person a = new Person("Gulen Chongtham", Arrays.asList("Hola Espanyol", "Vicky Boss"));
    final Person b = new Person("Gulen Chongthamm", Arrays.asList("Hola Espanyol", "Vicky Boss", "Roger Harper"));

    final ObjectDifferBuilder builder = ObjectDifferBuilder.startBuilding();
    builder.inclusion().include().node(NodePath.with("aliases"));
    final ObjectDiffer differ = builder.build();

    final DiffNode root = differ.compare(b, a);
    root.visit(new PrintingVisitor(b, a));

    NodeAssertions.assertThat(root).root().hasChanges();
View Full Code Here

  private ObjectDiffer objectDiffer;

  @BeforeMethod
  public void setUp() throws Exception
  {
    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    objectDifferBuilder.circularReferenceHandling().matchCircularReferencesUsing(EQUALITY_OPERATOR);
    objectDiffer = objectDifferBuilder.build();
  }
View Full Code Here

    final GraphNode base1 = new GraphNode(1);
    final GraphNode base2 = new GraphNode(2);
    establishCircularDirectReference(base1, base2);

    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    objectDifferBuilder.filtering().returnNodesWithState(DiffNode.State.CIRCULAR);
    final DiffNode node = objectDifferBuilder.build().compare(working1, base1);
    node.visit(new NodeHierarchyVisitor());

    assertThat(node).child("value").hasState(DiffNode.State.ADDED);
    assertThat(node).child("directReference").hasState(DiffNode.State.CHANGED);
    assertThat(node).child("directReference", "value").hasState(DiffNode.State.ADDED);
View Full Code Here

    final GraphNode base1 = new GraphNode(1);
    final GraphNode base2 = new GraphNode(2);
    base1.getMap().put("foo", base2);
    base2.getMap().put("bar", base1);

    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    objectDifferBuilder.filtering().returnNodesWithState(DiffNode.State.CIRCULAR);
    final ObjectDiffer differ = objectDifferBuilder.build();

    final DiffNode node = differ.compare(working1, base1);
    node.visit(new NodeHierarchyVisitor());

    NodeAssertions.assertThat(node)
View Full Code Here

TOP

Related Classes of de.danielbechler.diff.ObjectDifferBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.