Traversal { public List<Integer> preOrderTraverse(BinaryTreeNode root) { List<Integer> result = new ArrayList<>(); if (root != null) { Stack<BinaryTreeNode> stack = new Stack<>(); stack.push(root); while (!stack.isEmpty()){ BinaryTreeNode node = stack.pop(); result.add(node.val); if (node.right != null) { stack.push(node.right); } if (node.left != null) { stack.push(node.left); } } } return result; }  List<Integer> preOrderTraverse(BinaryTreeNode root); List<Integer> inOrderTraverse(BinaryTreeNode root); List<Integer> postOrderTraverse(BinaryTreeNode root);  }
@Test(dataProvider = "preOrderTree") public void testPreOrder(BinaryTreeNode head, List<Integer> expectedResult){ Traversal traversal = new Traversal(); assertEquals(traversal.preOrderTraverse(head), expectedResult); }