@Test public void testPruningRootNodeDuringBefore() { Node root = new Node(); TreeVisitor visitor = mock(TreeVisitor.class); Node result = new TreeTraverser().traverse(root, visitor); verify(visitor).before(root, 0); verify(visitor).visit(result, 0); verify(visitor).after(result, 0); verifyNoMoreInteractions(visitor); assertNull(result); }
public Node traverse(Node node, TreeVisitor... visitors) { if (ArrayUtils.isEmpty(visitors)) { throw new IllegalArgumentException("You need to provide at least one visitor for this traverser"); } Node result = node; for (TreeVisitor visitor : visitors) { result = traverse(result, visitor, 0); } return result; }
TreeTraverser { public Node traverse(Node node, TreeVisitor... visitors) { if (ArrayUtils.isEmpty(visitors)) { throw new IllegalArgumentException("You need to provide at least one visitor for this traverser"); } Node result = node; for (TreeVisitor visitor : visitors) { result = traverse(result, visitor, 0); } return result; } }
TreeTraverser { public Node traverse(Node node, TreeVisitor... visitors) { if (ArrayUtils.isEmpty(visitors)) { throw new IllegalArgumentException("You need to provide at least one visitor for this traverser"); } Node result = node; for (TreeVisitor visitor : visitors) { result = traverse(result, visitor, 0); } return result; }  }
TreeTraverser { public Node traverse(Node node, TreeVisitor... visitors) { if (ArrayUtils.isEmpty(visitors)) { throw new IllegalArgumentException("You need to provide at least one visitor for this traverser"); } Node result = node; for (TreeVisitor visitor : visitors) { result = traverse(result, visitor, 0); } return result; }  Node traverse(Node node, TreeVisitor... visitors); }
TreeTraverser { public Node traverse(Node node, TreeVisitor... visitors) { if (ArrayUtils.isEmpty(visitors)) { throw new IllegalArgumentException("You need to provide at least one visitor for this traverser"); } Node result = node; for (TreeVisitor visitor : visitors) { result = traverse(result, visitor, 0); } return result; }  Node traverse(Node node, TreeVisitor... visitors);  }