X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=3dc25e8c3821c6e4a6c6064f492bc9bbb572a70f;hp=4f9f002f0d14934c01f3e88ba37675d927bad4d0;hb=771e8efcd92c7325423441d57c5a6ed90a835e6f;hpb=927de326e0af0f11a27b3444f4e25b0796c877db diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 4f9f002..3dc25e8 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.text; import java.io.IOException; import java.io.StringReader; +import java.util.Arrays; import junit.framework.TestCase; import net.pterodactylus.sone.core.SoneProvider; @@ -42,6 +43,7 @@ public class SoneTextParserTest extends TestCase { * @throws IOException * if an I/O error occurs */ + @SuppressWarnings("static-method") public void testPlainText() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts; @@ -68,6 +70,7 @@ public class SoneTextParserTest extends TestCase { * @throws IOException * if an I/O error occurs */ + @SuppressWarnings("static-method") public void testKSKLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts; @@ -94,7 +97,7 @@ public class SoneTextParserTest extends TestCase { * @throws IOException * if an I/O error occurs */ - @SuppressWarnings("synthetic-access") + @SuppressWarnings({ "synthetic-access", "static-method" }) public void testEmptyLinesAndSoneLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); Iterable parts; @@ -105,6 +108,24 @@ public class SoneTextParserTest extends TestCase { assertEquals("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", convertText(parts, PlainTextPart.class, SonePart.class)); } + /** + * Test for a bug discovered in Sone 0.8.4 where a plain “http://” would be + * parsed into a link. + * + * @throws IOException + * if an I/O error occurs + */ + @SuppressWarnings({ "synthetic-access", "static-method" }) + public void testEmpyHttpLinks() throws IOException { + SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); + Iterable parts; + + /* check empty http links. */ + parts = soneTextParser.parse(null, new StringReader("Some text. Empty link: http:// – nice!")); + assertNotNull("Parts", parts); + assertEquals("Part Text", "Some text. Empty link: http:// – nice!", convertText(parts, PlainTextPart.class)); + } + // // PRIVATE METHODS // @@ -120,7 +141,7 @@ public class SoneTextParserTest extends TestCase { * valid * @return The converted text */ - private String convertText(Iterable parts, Class... validClasses) { + private static String convertText(Iterable parts, Class... validClasses) { StringBuilder text = new StringBuilder(); for (Part part : parts) { assertNotNull("Part", part); @@ -132,7 +153,7 @@ public class SoneTextParserTest extends TestCase { } } if (!classValid) { - assertEquals("Part’s Class", null, part.getClass()); + fail("Part’s Class (" + part.getClass() + ") is not one of " + Arrays.toString(validClasses)); } if (part instanceof PlainTextPart) { text.append(((PlainTextPart) part).getText());