TreeSearch { public void inorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) inorderTraversal(root.left, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } if(!isSearched) inorderTraversal(root.right, data); }  void preorderTraversal(TreeNode<T> root, T data); void inorderTraversal(TreeNode<T> root, T data); void postorderTraversal(TreeNode<T> root, T data);  }
@Test public void inorderTraversalTest(){ TreeSearch<Integer> treeSearch = new TreeSearch<Integer>(); Integer value = 5; String expectedSearchPath = "8->4->2->5"; treeSearch.inorderTraversal(root, value); Assert.assertTrue(expectedSearchPath.equals(treeSearch.searchPath.toString())); treeSearch = new TreeSearch<Integer>(); value = 6; expectedSearchPath = "8->4->2->5->1->6"; treeSearch.inorderTraversal(root, value); Assert.assertTrue(expectedSearchPath.equals(treeSearch.searchPath.toString())); }