@Test public void testFailsWhenNoVisitorIsProvided() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("You need to provide at least one visitor for this traverser"); new TreeTraverser().traverse(new Node()); }
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);  }