TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public abstract boolean dropSubtree(TreeNode<T> subtree); TreeNode(T data);  TreeNode(); abstract Collection<? extends TreeNode<T>> subtrees(); abstract boolean add(TreeNode<T> subtree); abstract boolean dropSubtree(TreeNode<T> subtree); abstract void clear(); abstract TreeNodeIterator iterator(); T data(); void setData(T data); boolean isRoot(); TreeNode<T> root(); TreeNode<T> parent(); boolean isLeaf(); @SuppressWarnings("unchecked") TreeNode<T> find(final T data); Collection<? extends TreeNode<T>> findAll(final T data); boolean hasSubtree(TreeNode<T> subtree); boolean contains(TreeNode<T> node); boolean containsAll(Collection<TreeNode<T>> nodes); boolean remove(TreeNode<T> node); boolean removeAll(Collection<TreeNode<T>> nodes); void traversePreOrder(TraversalAction<TreeNode<T>> action); void traversePostOrder(TraversalAction<TreeNode<T>> action); Collection<TreeNode<T>> preOrdered(); Collection<TreeNode<T>> postOrdered(); Collection<? extends TreeNode<T>> path(TreeNode<T> descendant); TreeNode<T> commonAncestor(TreeNode<T> node); boolean isSiblingOf(TreeNode<T> node); boolean isAncestorOf(TreeNode<T> node); boolean isDescendantOf(TreeNode<T> node); long size(); int height(); int level(); @SuppressWarnings("unchecked") @Override TreeNode<T> clone(); @SuppressWarnings("unchecked") @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testDropSubtree() { String messageDropExpected = "The subtree was expected to be dropped, but actually was not"; String messageDropResultTrueExpected = "The subtree drop result was expected to be true, but actually was false"; assertTrue(messageDropResultTrueExpected, node3.dropSubtree(node5)); assertFalse(messageDropExpected, node3.contains(node5)); assertFalse(messageDropExpected, node3.contains(node6)); assertTrue(messageDropResultTrueExpected, root.dropSubtree(node9)); assertFalse(messageDropExpected, root.contains(node9)); assertFalse(messageDropExpected, root.contains(node10)); String messageDropNotExpected = "The subtree was not expected to be dropped, but actually was"; String messageDropResultFalseExpected = "The subtree drop result was expected to be false, but actually was true"; assertFalse(messageDropResultFalseExpected, node1.dropSubtree(node2)); assertTrue(messageDropNotExpected, root.contains(node1)); assertTrue(messageDropNotExpected, root.contains(node2)); assertFalse(messageDropResultFalseExpected, node2.dropSubtree(null)); assertTrue(messageDropNotExpected, root.contains(node2)); assertFalse(messageDropResultFalseExpected, node1.dropSubtree(root)); assertTrue(messageDropNotExpected, root.contains(node1)); TreeNode<String> mAnotherNode1 = createTreeNode(ANOTHER_NODE_DATA); TreeNode<String> mAnotherNode2 = createTreeNode(ANOTHER_NODE_DATA); node1.add(mAnotherNode1); node1.add(mAnotherNode2); assertTrue(messageDropExpected, node1.remove(mAnotherNode1)); assertFalse(messageDropNotExpected, node1.contains(mAnotherNode1)); assertTrue(messageDropNotExpected, node1.contains(mAnotherNode2)); }