### Question:
BackPath { public List<N> toPath() { BackPath<E, N> currentPath = this; final Stack<N> nodes = new Stack<>(); nodes.push(currentPath.node); while (currentPath.parent != null) { currentPath = currentPath.parent; nodes.push(currentPath.node); } final List<N> path = new ArrayList<>(); while (!nodes.isEmpty()) { path.add(nodes.pop()); } return path; } BackPath(BackPath<E, N> parent, N node); BackPath<E, N> getParent(); N getNode(); List<N> toPath();  }### Answer:
@Test public void testToTrivialPath() throws Exception { final BackPath<String, BinaryTreeNode<String>> backPath = new BackPath<>(null, node); final List<BinaryTreeNode<String>> path = backPath.toPath(); assertEquals(1, path.size()); assertEquals(node, path.get(0)); }
@Test public void testToSimplePath() throws Exception { final BackPath<String, BinaryTreeNode<String>> backPath = new BackPath<>(new BackPath<>(null, parent), node); final List<BinaryTreeNode<String>> path = backPath.toPath(); assertEquals(2, path.size()); assertEquals(parent, path.get(0)); assertEquals(node, path.get(1)); }