2 * XdccDownloader - MessageCleanerTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.irc.util;
20 import static java.util.EnumSet.of;
21 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.bold;
22 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.clear;
23 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.color;
24 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.italics;
25 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.reverse;
26 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.underline;
27 import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
28 import static org.hamcrest.MatcherAssert.assertThat;
29 import static org.hamcrest.Matchers.is;
31 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
33 import org.junit.Test;
36 * Tests for {@link MessageCleaner}.
38 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
40 public class MessageCleanerTest {
42 private final MessageCleaner messageCleaner = getDefaultInstance();
44 /** Tests removal of {@link Attributes#bold} formatting. */
46 public void testRemoveBold() {
47 String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(bold));
48 assertThat(clean, is("This contains bold characters."));
50 clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(bold));
51 assertThat(clean, is("This contains bold and \u00034color\u0003 characters."));
54 /** Tests removal of {@link Attributes#color} formatting. */
56 public void testRemoveColors() {
57 String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(color));
58 assertThat(clean, is("This contains \u0002bold\u0002 characters."));
60 clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(color));
61 assertThat(clean, is("This contains \u0002bold\u0002 and color characters."));
63 clean = messageCleaner.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", of(color));
64 assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
67 /** Tests removal of {@link Attributes#clear} formatting. */
69 public void testRemoveClear() {
70 String clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(clear));
71 assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 characters."));
73 clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", of(clear));
74 assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 and clear characters."));
77 /** Tests removal of all formatting. */
79 public void testRemoveAll() {
80 String clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
81 assertThat(clean, is("This contains bold and color characters."));
83 clean = messageCleaner.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.");
84 assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
86 clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.");
87 assertThat(clean, is("This contains bold and color and clear characters."));
91 public void removeUnderlineFormatting() {
92 assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
96 public void removeReverseFormatting() {
97 assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
101 public void removeItalicFormatting() {
102 assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));