2 * Sone - FreenetLinkParserTest.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.text;
20 import java.io.IOException;
21 import java.io.StringReader;
23 import junit.framework.TestCase;
24 import net.pterodactylus.util.template.HtmlFilter;
25 import net.pterodactylus.util.template.TemplateContextFactory;
28 * JUnit test case for {@link FreenetLinkParser}.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class FreenetLinkParserTest extends TestCase {
38 * if an I/O error occurs
40 public void testParser() throws IOException {
41 TemplateContextFactory templateContextFactory = new TemplateContextFactory();
42 templateContextFactory.addFilter("html", new HtmlFilter());
43 FreenetLinkParser parser = new FreenetLinkParser(null, templateContextFactory);
44 FreenetLinkParserContext context = new FreenetLinkParserContext(null);
47 part = parser.parse(context, new StringReader("Text."));
48 assertEquals("Text.", part.toString());
50 part = parser.parse(context, new StringReader("Text.\nText."));
51 assertEquals("Text.\nText.", part.toString());
53 part = parser.parse(context, new StringReader("Text.\n\nText."));
54 assertEquals("Text.\n\nText.", part.toString());
56 part = parser.parse(context, new StringReader("Text.\n\n\nText."));
57 assertEquals("Text.\n\nText.", part.toString());
59 part = parser.parse(context, new StringReader("\nText.\n\n\nText."));
60 assertEquals("Text.\n\nText.", part.toString());
62 part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n"));
63 assertEquals("Text.\n\nText.", part.toString());
65 part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n\n"));
66 assertEquals("Text.\n\nText.", part.toString());
68 part = parser.parse(context, new StringReader("\nText.\n\n\n\nText.\n\n\n"));
69 assertEquals("Text.\n\nText.", part.toString());
71 part = parser.parse(context, new StringReader("\n\nText.\n\n\n\nText.\n\n\n"));
72 assertEquals("Text.\n\nText.", part.toString());
74 part = parser.parse(context, new StringReader("\n\nText. KSK@a text.\n\n\n\nText.\n\n\n"));
75 assertEquals("Text. <a class=\"freenet\" href=\"/KSK@a\" title=\"KSK@a\">a</a> text.\n\nText.", part.toString());