### Question:
JSPWikiMarkupParser extends MarkupParser { @Override public WikiDocument parse() throws IOException { final WikiDocument d = new WikiDocument( m_context.getPage() ); d.setContext( m_context ); final Element rootElement = new Element("domroot"); d.setRootElement( rootElement ); fillBuffer( rootElement ); paragraphify(rootElement); return d; } JSPWikiMarkupParser( final Context context, final Reader in ); Element makeHeading( final int level, final String title, final Heading hd ); @Override WikiDocument parse();  }### Answer:
@Test public void testCollectingLinks() throws Exception { final LinkCollector coll = new LinkCollector(); final String src = "[Test]"; final WikiContext context = new WikiContext( testEngine, Wiki.contents().page(testEngine,PAGE_NAME) ); final MarkupParser p = new JSPWikiMarkupParser( context, new BufferedReader( new StringReader(src)) ); p.addLocalLinkHook( coll ); p.addExternalLinkHook( coll ); p.addAttachmentLinkHook( coll ); p.parse(); final Collection< String > links = coll.getLinks(); Assertions.assertEquals( 1, links.size(), "no links found" ); Assertions.assertEquals( "Test", links.iterator().next(), "wrong link" ); }
@Test public void testCollectingLinks2() throws Exception { final LinkCollector coll = new LinkCollector(); final String src = "["+PAGE_NAME+"/Test.txt]"; final WikiContext context = new WikiContext( testEngine, Wiki.contents().page(testEngine,PAGE_NAME) ); final MarkupParser p = new JSPWikiMarkupParser( context, new BufferedReader( new StringReader(src)) ); p.addLocalLinkHook( coll ); p.addExternalLinkHook( coll ); p.addAttachmentLinkHook( coll ); p.parse(); final Collection< String > links = coll.getLinks(); Assertions.assertEquals( 1, links.size(), "no links found" ); Assertions.assertEquals( PAGE_NAME+"/Test.txt", links.iterator().next(), "wrong link" ); }
@Test public void testCollectingLinksAttachment() throws Exception { try { testEngine.saveText( PAGE_NAME, "content" ); final Attachment att = Wiki.contents().attachment( testEngine, PAGE_NAME, "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine.getManager( AttachmentManager.class ).storeAttachment( att, testEngine.makeAttachmentFile() ); final LinkCollector coll = new LinkCollector(); final LinkCollector coll_others = new LinkCollector(); final String src = "[TestAtt.txt]"; final WikiContext context = new WikiContext( testEngine, Wiki.contents().page(testEngine,PAGE_NAME) ); final MarkupParser p = new JSPWikiMarkupParser( context, new BufferedReader( new StringReader(src)) ); p.addLocalLinkHook( coll_others ); p.addExternalLinkHook( coll_others ); p.addAttachmentLinkHook( coll ); p.parse(); final Collection< String > links = coll.getLinks(); Assertions.assertEquals( 1, links.size(), "no links found" ); Assertions.assertEquals( PAGE_NAME+"/TestAtt.txt", links.iterator().next(), "wrong link" ); Assertions.assertEquals( 0, coll_others.getLinks().size(), "wrong links found" ); } finally { final String files = testEngine.getWikiProperties().getProperty( AttachmentProvider.PROP_STORAGEDIR ); final File storagedir = new File( files, PAGE_NAME+BasicAttachmentProvider.DIR_EXTENSION ); if( storagedir.exists() && storagedir.isDirectory() ) { TestEngine.deleteAll( storagedir ); } } }