X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=7de50fb5a18f9ab7eb66bc2489f940963ae1a4c2;hp=b680daa51be09ea3852ff986abfff33564c0bfe4;hb=a47643aed43d118ca68044f95451bb5374cdb332;hpb=fcbcbab864988bc4abaf2cc5a8bfafd69e9b9f7f diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index b680daa..7de50fb 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -1,5 +1,5 @@ /* - * Sone - SoneTextParserTest.java - Copyright © 2011 David Roden + * Sone - SoneTextParserTest.java - Copyright © 2011–2012 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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}. @@ -29,6 +31,10 @@ import junit.framework.TestCase; */ public class SoneTextParserTest extends TestCase { + // + // ACTIONS + // + /** * Tests basic plain-text operation of the parser. * @@ -81,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 // @@ -118,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; + } + }; + } + + } + }