@Test
    public void testApi() {
        // Prepare
        AnnotationType type1 = new AnnotationType("type1", DataType.STRING);
        AnnotationType type2 = new AnnotationType("type2", DataType.INT);
        StringFieldValue output = new StringFieldValue("foo bar");
        SpanTree tree;

        // no shortcuts
        {
            SpanList root = new SpanList();
            tree = new SpanTree("SpanTree1", root);
            SpanNode node = new Span(0, 3);
            tree.annotate(node, new Annotation(type1, new StringFieldValue("text")));
            tree.annotate(node, new Annotation(type2, new IntegerFieldValue(1)));
            root.add(node);
            output.setSpanTree(tree);
        }

        // short
        {
            SpanList root = new SpanList();
            output.setSpanTree(new SpanTree("SpanTree2", root));
            SpanNode node = root.add(new Span(0, 3));
            node.annotate(type1, "text").annotate(type2, 1);
        }

        // shorter
        {
            SpanList root = output.setSpanTree(new SpanTree("SpanTree3")).spanList();
            root.span(0, 3).annotate(type1, "text").annotate(type2, 1);
        }

        // shortest
        {
            output.setSpanTree(new SpanTree("SpanTree4")).spanList().span(0, 3).annotate(type1, "text")
                  .annotate(type2, 1);
        }
    }
A test case taken from real use to verify the API ease of use
document/src/test/java/com/yahoo/document/annotation/AnnotationTestCase.java