From: David ‘Bombe’ Roden Date: Thu, 9 Jun 2011 08:37:34 +0000 (+0200) Subject: First basic test case for SoneTextParser. X-Git-Tag: 0.6.5^2~8^2~8 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6b9c7c806fd1fc168e598d6e4eb6ee46ad2aa6fd;p=Sone.git First basic test case for SoneTextParser. --- 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 index 0000000..f0b0e1b --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -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 . + */ + +package net.pterodactylus.sone.text; + +import java.io.IOException; +import java.io.StringReader; + +import junit.framework.TestCase; + +/** + * JUnit test case for {@link SoneTextParser}. + * + * @author David ‘Bombe’ Roden + */ +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 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()); + } + +}