### Question:
BinaryTreeWalker extends Walker<N> { @Override public Stream<N> preOrderFrom(Iterable<? extends N> roots) { return inBinaryTree(getRight, getLeft).topDown(roots, Deque::push); } BinaryTreeWalker(UnaryOperator<N> getLeft, UnaryOperator<N> getRight); @Override Stream<N> breadthFirstFrom(Iterable<? extends N> roots); @Override Stream<N> preOrderFrom(Iterable<? extends N> roots); @Override Stream<N> postOrderFrom(Iterable<? extends N> roots); @SafeVarargs final Stream<N> inOrderFrom(N... roots); Stream<N> inOrderFrom(Iterable<? extends N> roots);  }### Answer:
@Test public void preOrder_noRoot() { assertThat(Tree.<String>walker().preOrderFrom().map(Tree::value)) .isEmpty(); }
@Test public void preOrder_singleNode() { assertThat(Tree.<String>walker().preOrderFrom(tree("foo")).map(Tree::value)) .containsExactly("foo"); }
@Test public void preOrder_leftNodeIsNull() { Tree<String> tree = tree("foo").setRight("right"); assertThat(Tree.<String>walker().preOrderFrom(tree).map(Tree::value)) .containsExactly("foo", "right") .inOrder(); }
@Test public void preOrder_rightNodeIsNull() { Tree<String> tree = tree("foo").setLeft("left"); assertThat(Tree.<String>walker().preOrderFrom(tree).map(Tree::value)) .containsExactly("foo", "left") .inOrder(); }
@Test public void preOrder_deep() { Tree<String> tree = tree("a") .setLeft(tree("b") .setLeft("c") .setRight(tree("d").setLeft("e"))) .setRight(tree("f") .setLeft(tree("g").setRight("h"))); assertThat(Tree.<String>walker().preOrderFrom(tree).map(Tree::value)) .containsExactly("a", "b", "c", "d", "e", "f", "g", "h") .inOrder(); }
@Test public void preOrder_infiniteLeft() { assertThat(Tree.<Integer>walker().preOrderFrom(Tree.leftFrom(1)).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }
@Test public void preOrder_infiniteRight() { assertThat(Tree.<Integer>walker().preOrderFrom(Tree.rightFrom(1)).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }
@Test public void preOrder_infiniteAlternating() { assertThat(Tree.<Integer>walker().preOrderFrom(Tree.leftThenRight(1)).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }
@Test public void preOrder_twoRoots() { Tree<String> tree1 = tree("a") .setLeft("b") .setRight(tree("c").setRight("d")); Tree<String> tree2 = tree("e") .setLeft(tree("f") .setLeft("g") .setRight("h")); assertThat(Tree.<String>walker().preOrderFrom(tree1, tree2).map(Tree::value)) .containsExactly("a", "b", "c", "d", "e", "f", "g", "h") .inOrder(); }