@Test public void testCircularReference() { final ObjectWithCircularReference workingA = new ObjectWithCircularReference("a"); final ObjectWithCircularReference workingB = new ObjectWithCircularReference("b"); workingA.setReference(workingB); workingB.setReference(workingA); final ObjectWithCircularReference baseA = new ObjectWithCircularReference("a"); final ObjectWithCircularReference baseB = new ObjectWithCircularReference("c"); baseA.setReference(baseB); baseB.setReference(baseA); final DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingA, baseA); assertThat(root).child("reference", "reference").isCircular(); assertThat(root) .child("reference", "reference") .hasCircularStartPathEqualTo(NodePath.withRoot()); Assertions.assertThat(root.canonicalGet(workingA)) .isSameAs(root.getChild("reference").getChild("reference").canonicalGet(workingA)); Assertions.assertThat(root.getChild("reference").getChild("reference").getCircleStartNode()) .isSameAs(root); }
@Test public void testCircularReferenceShouldBeAddedWhenEnabledInConfiguration() { final ObjectWithCircularReference workingA = new ObjectWithCircularReference("a"); final ObjectWithCircularReference workingB = new ObjectWithCircularReference("b"); final ObjectWithCircularReference workingC = new ObjectWithCircularReference("c"); workingA.setReference(workingB); workingB.setReference(workingC); workingC.setReference(workingA); final ObjectWithCircularReference baseA = new ObjectWithCircularReference("a"); final ObjectWithCircularReference baseB = new ObjectWithCircularReference("b"); final ObjectWithCircularReference baseC = new ObjectWithCircularReference("d"); baseA.setReference(baseB); baseB.setReference(baseC); baseC.setReference(baseA); final ObjectDiffer objectDiffer = ObjectDifferBuilder.buildDefault(); // objectDiffer.getConfiguration().withoutCircularNodes(); final DiffNode root = objectDiffer.compare(workingA, baseA); root.visit(new PrintingVisitor(workingA, baseA)); assertThat(root).child("reference", "reference", "reference").isCircular(); }