### Question:
Constructor implements TreeConstructor<E, MutableNode<E>, PathCopyTree<E>> { @Override public PathCopyTree<E> build(E e, PathCopyTree<E>[] subtrees) { final PathCopyTree<E> tree = new PathCopyTree<>(); final PathCopyNode<E> root = tree.setRoot(e); for (PathCopyTree<E> subtree : subtrees) { final PathCopyNode<E> subRoot = subtree.getRoot(); final MutableNode<E> newSubRoot = root.addChild(subRoot.getElement()); copyChildren(newSubRoot, subRoot); } return tree; }  @Override PathCopyTree<E> build(E e, PathCopyTree<E>[] subtrees); @Override Class<? extends Tree> forClass();  }### Answer:
@SuppressWarnings("unchecked") @Test public void build0() { final Constructor<String> constructor = new Constructor<>(); final PathCopyTree<String> tree = constructor.build("root", new PathCopyTree[] {}); assertEquals("root", tree.getRoot().getElement()); assertTrue(tree.getRoot().isLeaf()); assertFalse(tree.isEmpty()); }
@SuppressWarnings("unchecked") @Test public void build1() { final Constructor<String> constructor = new Constructor<>(); final PathCopyTree<String> tree = constructor.build("root", new PathCopyTree[] { constructor.build("left", new PathCopyTree[] {})}); assertEquals("root", tree.getRoot().getElement()); assertFalse(tree.getRoot().isLeaf()); assertFalse(tree.isEmpty()); final Iterator<MutableNode<String>> iterator = tree.getRoot().childIterator(); assertEquals("left", iterator.next().getElement()); assertFalse(iterator.hasNext()); }
@SuppressWarnings("unchecked") @Test public void build2() { final Constructor<String> constructor = new Constructor<>(); final PathCopyTree<String> tree = constructor.build("root", new PathCopyTree[] { constructor.build("left", new PathCopyTree[] { constructor.build("left-left", new PathCopyTree[] {}) })}); assertEquals("root", tree.getRoot().getElement()); assertFalse(tree.getRoot().isLeaf()); assertFalse(tree.isEmpty()); final Iterator<MutableNode<String>> iterator = tree.getRoot().childIterator(); final MutableNode<String> child = iterator.next(); assertEquals("left", child.getElement()); assertFalse(child.isLeaf()); assertFalse(iterator.hasNext()); final Iterator<? extends MutableNode<String>> deeperIterator = child.childIterator(); final MutableNode<String> leaf = deeperIterator.next(); assertEquals("left-left", leaf.getElement()); assertTrue(leaf.isLeaf()); assertFalse(deeperIterator.hasNext()); }