@Test
    public void testAnnotationIteration() {
        List<Annotation> allAnnotationsList = new ArrayList<>();
        for (Annotation a : tree) {
            allAnnotationsList.add(a);
        }
        Collections.sort(allAnnotationsList);

        Iterator<Annotation> allAnnotations = allAnnotationsList.iterator();

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(dummyA, allAnnotations.next());
        assertSame(a, dummyA.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(numberB, allAnnotations.next());
        assertSame(b, numberB.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(dummyD, allAnnotations.next());
        assertSame(d, dummyD.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(grapeC, allAnnotations.next());
        assertSame(c, grapeC.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(bananaC, allAnnotations.next());
        assertSame(c, bananaC.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());

        assertSame(appleC, allAnnotations.next());
        assertSame(c, appleC.getSpanNode());

        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());
        assertTrue(allAnnotations.hasNext());


        assertSame(dummyE, allAnnotations.next());
        assertSame(e, dummyE.getSpanNode());

        assertFalse(allAnnotations.hasNext());
        assertFalse(allAnnotations.hasNext());
        assertFalse(allAnnotations.hasNext());
        assertFalse(allAnnotations.hasNext());
    }
Tests iterating through all annotations in a tree.
document/src/test/java/com/yahoo/document/annotation/SpanTreeTestCase.java