From 6b9c7c806fd1fc168e598d6e4eb6ee46ad2aa6fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 9 Jun 2011 10:37:34 +0200 Subject: [PATCH] First basic test case for SoneTextParser. --- .../sone/text/SoneTextParserTest.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java 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()); + } + +} -- 2.7.4