GraphSearch { public void searchDFS(GraphNode<T> root) { if (root == null) { return; } if (searchPathDFS.length() > 0) { searchPathDFS.append("->"); } searchPathDFS.append(root.data.toString()); root.visited = true; for (GraphNode<T> node : root.neighborList) { if (!node.visited) { searchDFS(node); } } }  void searchDFS(GraphNode<T> root); void searchBFS(GraphNode<T> root); public StringBuffer searchPathDFS; public StringBuffer searchPathBFS; }
@Test public void searchDFSTest(){ GraphSearch<Integer> graphSearch = new GraphSearch<Integer>(); graphSearch.searchDFS(node1); String expectedSearchPath = "1->2->4->5->6->3->7->8->9->10"; Assert.assertEquals(expectedSearchPath, graphSearch.searchPathDFS.toString()); }