@Test
    public void assertTree() {

        if (debug) {
            consumeAnnotations((SpanList)tree.getRoot());
        }

        assertEquals(0, root.getFrom());
        assertEquals(30, root.getTo());
        assertEquals(0, alternate1.getFrom());
        assertEquals(20, alternate1.getTo());
        assertEquals(0, alternate2.getFrom());
        assertEquals(22, alternate2.getTo());
        assertEquals(5, alternate3.getFrom());
        assertEquals(20, alternate3.getTo());
        assertFalse(root.numChildren() != 3 || alternate1.numChildren() != 4 || alternate2.numChildren() != 3 || alternate3.numChildren() != 2);

        ArrayList<SpanNode> al = new ArrayList<SpanNode>();
        al.add(span333);
        al.add(alternate1);
        al.add(alternate2);
        ListIterator<SpanNode> iter = root.childIterator();
        while (iter.hasNext()) {
            SpanNode sn = iter.next();
            int i = 0;
            for (i = 0; i < al.size(); i ++) {
                if (sn == al.get(i)) {
                    break;
                }
            }
            assertFalse(i >= al.size());
        }

        iter = root.childIteratorRecursive();
        boolean nodeFound = false;
        while (iter.hasNext()) {
            SpanNode sn = iter.next();
            if (sn == span222 || sn == span111) {
                nodeFound = true;
                break;
            }
        }
        assertTrue(nodeFound);

        alternate1.sortChildren();
        SpanNode ssn = new Span(2, 1);
        alternate1.add(ssn);
        alternate1.sortChildren();

        iter = alternate1.childIterator();
        int from = -1;
        while (iter.hasNext()) {
            SpanNode sn = iter.next();
            if (from == -1) {
                from = sn.getFrom();
                continue;
            }
            assertFalse(sn.getFrom() < from);
            from = sn.getFrom();
        }
        alternate1.remove(ssn);

        SpanList sl = alternate3.remove(span111);
        assertFalse (sl != alternate3);
        assertFalse(span111.isValid());

        alternate1.remove(alternate3);
        assertFalse(alternate3.isValid());
        assertFalse(span222.isValid());

        int noofChild = alternate1.numChildren();
        for (int i = 0; i < alternate1.numChildren(); ) {
            alternate1.remove(i);
        }
        assertFalse(alternate1.numChildren() != 0);

        int noAnnotations = tree.numAnnotations();
        tree.cleanup();
        assertFalse(tree.numAnnotations() != (noAnnotations - 5));

        root.clearChildren();
        tree.cleanup();
        assertFalse(tree.numAnnotations() != 0);

        sl = new SpanList(alternate1);
        root.add(sl);
        assertFalse(root.getFrom() != -1 || root.getTo() != -1);

        SpanNode newSpan1 = new Span(0, 10);
        SpanNode newSpan2 = new Span(12, 8);
        alternate3 = new SpanList();
        alternate3.add(newSpan1);
        alternate3.add(newSpan2);
        alternate2.add(alternate3);

        SpanList newA2 = new SpanList(alternate2);
        root.add(newA2);
        assertFalse(root.getFrom() != newA2.getFrom() || root.getTo() != newA2.getTo());
        assertFalse(newA2.numChildren() != 4);
    }
@author <a href="mailto:mpraveen@yahoo-inc.com">Praveen Mohan</a>

This test covers all possible scenarios in a SpanList.
document/src/test/java/com/yahoo/document/annotation/SpanListAdvTestCase.java