First basic test case for SoneTextParser.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Jun 2011 08:37:34 +0000 (10:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Jun 2011 08:37:34 +0000 (10:37 +0200)
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java
new file mode 100644 (file)
index 0000000..f0b0e1b
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Sone - SoneTextParserTest.java - Copyright © 2011 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit test case for {@link SoneTextParser}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneTextParserTest extends TestCase {
+
+       /**
+        * Tests basic plain-text operation of the parser.
+        *
+        * @throws IOException
+        *             if an I/O error occurs
+        */
+       public void testPlainText() throws IOException {
+               SoneTextParser soneTextParser = new SoneTextParser(null, null);
+               Iterable<Part> parts;
+               StringBuilder text = new StringBuilder();
+
+               /* check basic operation. */
+               text.setLength(0);
+               parts = soneTextParser.parse(null, new StringReader("Test."));
+               assertNotNull("Parts", parts);
+               for (Part part : parts) {
+                       assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+                       text.append(((PlainTextPart) part).getText());
+               }
+               assertEquals("Part Text", "Test.", text.toString());
+
+               /* check empty lines at start and end. */
+               text.setLength(0);
+               parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n"));
+               assertNotNull("Parts", parts);
+               for (Part part : parts) {
+                       assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+                       text.append(((PlainTextPart) part).getText());
+               }
+               assertEquals("Part Text", "Test.", text.toString());
+
+               /* check duplicate empty lines in the text. */
+               text.setLength(0);
+               parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n\nTest."));
+               assertNotNull("Parts", parts);
+               for (Part part : parts) {
+                       assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+                       text.append(((PlainTextPart) part).getText());
+               }
+               assertEquals("Part Text", "Test.\n\nTest.", text.toString());
+       }
+
+}