### Question:
BinaryTreeWalker extends Walker<N> { @Override public Stream<N> breadthFirstFrom(Iterable<? extends N> roots) { return topDown(roots, Queue::add); } 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 breadthFirst_noRoot() { assertThat(Tree.<String>walker().breadthFirstFrom().map(Tree::value)) .isEmpty(); }
@Test public void breadthFirst_singleNode() { Tree<String> tree = tree("foo"); assertThat(Tree.<String>walker().breadthFirstFrom(tree).map(Tree::value)) .containsExactly("foo"); }
@Test public void breadthFirst_leftNodeIsNull() { Tree<String> tree = tree("foo").setRight("right"); assertThat(Tree.<String>walker().breadthFirstFrom(tree).map(Tree::value)) .containsExactly("foo", "right") .inOrder(); }
@Test public void breadthFirst_rightNodeIsNull() { Tree<String> tree = tree("foo").setLeft("left"); assertThat(Tree.<String>walker().breadthFirstFrom(tree).map(Tree::value)) .containsExactly("foo", "left") .inOrder(); }
@Test public void breadthFirst_deep() { Tree<String> tree = tree("a") .setLeft(tree("b") .setLeft("c") .setRight(tree("d").setLeft("e"))) .setRight(tree("f") .setLeft(tree("g").setRight("h")) .setRight("i")); assertThat(Tree.<String>walker().breadthFirstFrom(tree).map(Tree::value)) .containsExactly("a", "b", "f", "c", "d", "g", "i", "e", "h") .inOrder(); }
@Test public void breadthFirst_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().breadthFirstFrom(tree1, tree2).map(Tree::value)) .containsExactly("a", "e", "b", "c", "f", "d", "g", "h") .inOrder(); }
@Test public void breadthFirst_infiniteLeft() { Tree<Integer> tree = Tree.leftFrom(1); assertThat(Tree.<Integer>walker().breadthFirstFrom(tree).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }
@Test public void breadthFirst_infiniteRight() { Tree<Integer> tree = Tree.rightFrom(1); assertThat(Tree.<Integer>walker().breadthFirstFrom(tree).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }
@Test public void breadthFirst_alternating() { Tree<Integer> tree = Tree.leftThenRight(1); assertThat(Tree.<Integer>walker().breadthFirstFrom(tree).map(Tree::value).limit(3)) .containsExactly(1, 2, 3) .inOrder(); }