MultiTreeNode extends TreeNode<T> { public boolean addSubtrees(Collection<? extends MultiTreeNode<T>> subtrees) { if (areAllNulls(subtrees)) { return false; } for (MultiTreeNode<T> subtree : subtrees) { linkParent(subtree, this); if (!add(subtree)) { return false; } } return true; } MultiTreeNode(T data); boolean addSubtrees(Collection<? extends MultiTreeNode<T>> subtrees); Collection<? extends MultiTreeNode<T>> siblings(); boolean hasSubtrees(Collection<? extends MultiTreeNode<T>> subtrees); boolean dropSubtrees(Collection<? extends MultiTreeNode<T>> subtrees);  }
@Test public void testAddSubtrees() { String messageAddExpected = "The specified tree node was expected to be added but actually was not"; String messageAddResultTrueExpected = "The tree nodes addition result was expected to be true, but actually was false"; Collection<MultiTreeNode<String>> mSubtreesToAdd = new ArrayList<>(3); MultiTreeNode<String> nodeToAdd1 = (MultiTreeNode<String>) createTreeNode("NODE_TO_ADD_1"); MultiTreeNode<String> nodeToAdd2 = (MultiTreeNode<String>) createTreeNode("NODE_TO_ADD_2"); MultiTreeNode<String> nodeToAdd3 = (MultiTreeNode<String>) createTreeNode("NODE_TO_ADD_3"); mSubtreesToAdd.add(nodeToAdd1); mSubtreesToAdd.add(nodeToAdd2); mSubtreesToAdd.add(nodeToAdd3); assertTrue(messageAddResultTrueExpected, ((MultiTreeNode<String>) node7).addSubtrees(mSubtreesToAdd)); assertTrue(messageAddExpected, node7.hasSubtree(nodeToAdd1)); assertTrue(messageAddExpected, node7.hasSubtree(nodeToAdd2)); assertTrue(messageAddExpected, node7.hasSubtree(nodeToAdd3)); String messageAddResultFalseExpected = "The tree nodes addition result was expected to be false, but actually was true"; assertFalse(messageAddResultFalseExpected, ((MultiTreeNode<String>) node8).addSubtrees(null)); assertFalse(messageAddResultFalseExpected, ((MultiTreeNode<String>) node1).addSubtrees(Collections.<MultiTreeNode<String>>singletonList(null))); assertFalse(messageAddResultFalseExpected, ((MultiTreeNode<String>) node10).addSubtrees(Collections.<MultiTreeNode<String>>emptyList())); }