Add message cleaner.
[xudocci.git] / src / test / java / net / pterodactylus / irc / util / MessageCleanerTest.java
diff --git a/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java b/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java
new file mode 100644 (file)
index 0000000..6ab7b0a
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * XdccDownloader - MessageCleanerTest.java - Copyright © 2013 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.irc.util;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.util.EnumSet;
+
+import net.pterodactylus.irc.util.MessageCleaner.Attributes;
+
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link MessageCleaner}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class MessageCleanerTest {
+
+       /** Tests removal of {@link Attributes#bold} formatting. */
+       @Test
+       public void testRemoveBold() {
+               MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
+               String clean;
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold));
+               assertThat(clean, is("This contains bold characters."));
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.bold));
+               assertThat(clean, is("This contains bold and \u00034color\u0003 characters."));
+       }
+
+       /** Tests removal of {@link Attributes#color} formatting. */
+       @Test
+       public void testRemoveColors() {
+               MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
+               String clean;
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color));
+               assertThat(clean, is("This contains \u0002bold\u0002 characters."));
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.color));
+               assertThat(clean, is("This contains \u0002bold\u0002 and color characters."));
+
+               clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", EnumSet.of(Attributes.color));
+               assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
+       }
+
+       /** Tests removal of {@link Attributes#clear} formatting. */
+       @Test
+       public void testRemoveClear() {
+               MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
+               String clean;
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.clear));
+               assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 characters."));
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", EnumSet.of(Attributes.clear));
+               assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 and clear characters."));
+       }
+
+       /** Tests removal of all formatting. */
+       @Test
+       public void testRemoveAll() {
+               MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
+               String clean;
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
+               assertThat(clean, is("This contains bold and color characters."));
+
+               clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.");
+               assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
+
+               clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.");
+               assertThat(clean, is("This contains bold and color and clear characters."));
+       }
+
+}