From: David ‘Bombe’ Roden Date: Fri, 16 Sep 2011 10:27:21 +0000 (+0200) Subject: Add test case for fixed parser bug. X-Git-Tag: 0.7^2~4 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=143137ab32369113b98e85ec4258ee87f732265b Add test case for fixed parser bug. --- diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 0343f05..d98d4ec 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.StringReader; import junit.framework.TestCase; +import net.pterodactylus.sone.core.SoneProvider; +import net.pterodactylus.sone.data.Sone; /** * JUnit test case for {@link SoneTextParser}. @@ -85,6 +87,23 @@ public class SoneTextParserTest extends TestCase { assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", convertText(parts, PlainTextPart.class, FreenetLinkPart.class)); } + /** + * Test case for a bug that was discovered in 0.6.7. + * + * @throws IOException + * if an I/O error occurs + */ + @SuppressWarnings("synthetic-access") + public void testEmptyLinesAndSoneLinks() throws IOException { + SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); + Iterable parts; + + /* check basic links. */ + parts = soneTextParser.parse(null, new StringReader("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.")); + assertNotNull("Parts", parts); + assertEquals("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", convertText(parts, PlainTextPart.class, SonePart.class)); + } + // // PRIVATE METHODS // @@ -122,9 +141,38 @@ public class SoneTextParserTest extends TestCase { } else if (part instanceof LinkPart) { LinkPart linkPart = (LinkPart) part; text.append('[').append(linkPart.getLink()).append('|').append(linkPart.getTitle()).append('|').append(linkPart.getText()).append(']'); + } else if (part instanceof SonePart) { + SonePart sonePart = (SonePart) part; + text.append("[Sone|").append(sonePart.getSone().getId()).append(']'); } } return text.toString(); } + /** + * Mock Sone provider. + * + * @author David ‘Bombe’ Roden + */ + private static class TestSoneProvider implements SoneProvider { + + /** + * {@inheritDoc} + */ + @Override + public Sone getSone(final String soneId, boolean create) { + return new Sone(soneId) { + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return soneId; + } + }; + } + + } + }