Merge branch 'next' into new-database-38
[Sone.git] / src / test / java / net / pterodactylus / sone / text / SoneTextParserTest.java
index 4f9f002..3dc25e8 100644 (file)
@@ -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<Part> 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<Part> 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<Part> 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<Part> 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<Part> parts, Class<?>... validClasses) {
+       private static String convertText(Iterable<Part> 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());