TableOfContentsCreator { public void appendItem(String text, long pageNumber, PDPage page) { requireNotBlank(text, "ToC item cannot be blank"); requireArg(pageNumber > 0, "ToC item cannot point to a negative page"); requireNotNullArg(page, "ToC page cannot be null"); if (shouldGenerateToC()) { items.add(new ToCItem(text, pageNumber, linkAnnotationFor(page))); recalculateDimensions(); } } TableOfContentsCreator(MergeParameters params, PDDocument document); void appendItem(String text, long pageNumber, PDPage page); void addToC(); void addToC(int beforePageNumber); boolean hasToc(); boolean shouldGenerateToC(); void pageSizeIfNotSet(PDRectangle pageSize); float getFontSize(); long tocNumberOfPages();  }
@Test(expected = IllegalArgumentException.class) public void testAppendItemInvalidString() { new TableOfContentsCreator(new MergeParameters(), new PDDocument()).appendItem(" ", 10, new PDPage()); }
@Test(expected = IllegalArgumentException.class) public void testAppendItemInvalidPage() { new TableOfContentsCreator(new MergeParameters(), new PDDocument()).appendItem("Text", -10, new PDPage()); }
@Test(expected = IllegalArgumentException.class) public void testAppendItemInvalidAnnotation() { new TableOfContentsCreator(new MergeParameters(), new PDDocument()).appendItem("Text", 10, null); }
@Test public void testAppendItem() { MergeParameters params = new MergeParameters(); params.setTableOfContentsPolicy(ToCPolicy.DOC_TITLES); TableOfContentsCreator victim = new TableOfContentsCreator(params, new PDDocument()); assertFalse(victim.hasToc()); victim.appendItem("text", 10, new PDPage()); assertTrue(victim.hasToc()); }