X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=d98d4ec79f4f922e6d900413272150e60669cceb;hp=0343f05dcf3870b7039212c9ee5b33054e9a9e8d;hb=143137ab32369113b98e85ec4258ee87f732265b;hpb=79f1429cf43a59b6e539934555844b3d3ae6bee7 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; + } + }; + } + + } + }