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 java.util.Collections;
33 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
35 import org.junit.Test;
38 * Tests for {@link MessageCleaner}.
40 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42 public class MessageCleanerTest {
44 private final MessageCleaner messageCleaner = getDefaultInstance();
47 public void removeBoldFormatting() {
48 assertThat(messageCleaner.clean("Text\u0002bold", of(bold)), is("Textbold"));
52 public void boldFormattingIsNotRemovedUnwanted() {
53 assertThat(messageCleaner.clean("Text\u0002bold", Collections.<Attributes>emptySet()), is("Text\u0002bold"));
57 public void removeColorFormatting() {
58 assertThat(messageCleaner.clean("Text\u0003!color", of(color)), is("Text!color"));
59 assertThat(messageCleaner.clean("Text\u0003color", of(color)), is("Textcolor"));
60 assertThat(messageCleaner.clean("Text\u00034color", of(color)), is("Textcolor"));
61 assertThat(messageCleaner.clean("Text\u00034!color", of(color)), is("Text!color"));
62 assertThat(messageCleaner.clean("Text\u000314color", of(color)), is("Textcolor"));
63 assertThat(messageCleaner.clean("Text\u000318color", of(color)), is("Text8color"));
64 assertThat(messageCleaner.clean("Text\u000399color", of(color)), is("Textcolor"));
65 assertThat(messageCleaner.clean("Text\u00031,!color", of(color)), is("Text!color"));
66 assertThat(messageCleaner.clean("Text\u00031,color", of(color)), is("Textcolor"));
67 assertThat(messageCleaner.clean("Text\u00031,1!color", of(color)), is("Text!color"));
68 assertThat(messageCleaner.clean("Text\u00031,1color", of(color)), is("Textcolor"));
69 assertThat(messageCleaner.clean("Text\u00031,14color", of(color)), is("Textcolor"));
70 assertThat(messageCleaner.clean("Text\u00031,18color", of(color)), is("Text8color"));
71 assertThat(messageCleaner.clean("Text\u00031,99color", of(color)), is("Textcolor"));
72 assertThat(messageCleaner.clean("Text\u000314,color", of(color)), is("Textcolor"));
73 assertThat(messageCleaner.clean("Text\u000314,1color", of(color)), is("Textcolor"));
74 assertThat(messageCleaner.clean("Text\u000314,14color", of(color)), is("Textcolor"));
75 assertThat(messageCleaner.clean("Text\u000314,18color", of(color)), is("Text8color"));
76 assertThat(messageCleaner.clean("Text\u000314,99color", of(color)), is("Textcolor"));
77 assertThat(messageCleaner.clean("Text\u000399,99color", of(color)), is("Textcolor"));
78 assertThat(messageCleaner.clean("Text\u000399,9color", of(color)), is("Textcolor"));
79 assertThat(messageCleaner.clean("Text\u00039color", of(color)), is("Textcolor"));
80 assertThat(messageCleaner.clean("Text\u00039,color", of(color)), is("Textcolor"));
84 public void colorFormattingIsNotRemovedUnwanted() {
85 assertThat(messageCleaner.clean("Text\u00034color", Collections.<Attributes>emptySet()), is("Text\u00034color"));
86 assertThat(messageCleaner.clean("Text\u000314color", Collections.<Attributes>emptySet()), is("Text\u000314color"));
87 assertThat(messageCleaner.clean("Text\u000318color", Collections.<Attributes>emptySet()), is("Text\u000318color"));
88 assertThat(messageCleaner.clean("Text\u000399color", Collections.<Attributes>emptySet()), is("Text\u000399color"));
89 assertThat(messageCleaner.clean("Text\u00031,color", Collections.<Attributes>emptySet()), is("Text\u00031,color"));
90 assertThat(messageCleaner.clean("Text\u00031,1color", Collections.<Attributes>emptySet()), is("Text\u00031,1color"));
91 assertThat(messageCleaner.clean("Text\u00031,14color", Collections.<Attributes>emptySet()), is("Text\u00031,14color"));
92 assertThat(messageCleaner.clean("Text\u00031,18color", Collections.<Attributes>emptySet()), is("Text\u00031,18color"));
93 assertThat(messageCleaner.clean("Text\u00031,99color", Collections.<Attributes>emptySet()), is("Text\u00031,99color"));
94 assertThat(messageCleaner.clean("Text\u000314,color", Collections.<Attributes>emptySet()), is("Text\u000314,color"));
95 assertThat(messageCleaner.clean("Text\u000314,1color", Collections.<Attributes>emptySet()), is("Text\u000314,1color"));
96 assertThat(messageCleaner.clean("Text\u000314,14color", Collections.<Attributes>emptySet()), is("Text\u000314,14color"));
97 assertThat(messageCleaner.clean("Text\u000314,18color", Collections.<Attributes>emptySet()), is("Text\u000314,18color"));
98 assertThat(messageCleaner.clean("Text\u000314,99color", Collections.<Attributes>emptySet()), is("Text\u000314,99color"));
99 assertThat(messageCleaner.clean("Text\u000399,99color", Collections.<Attributes>emptySet()), is("Text\u000399,99color"));
100 assertThat(messageCleaner.clean("Text\u00039color", Collections.<Attributes>emptySet()), is("Text\u00039color"));
104 public void removeClearFormatting() {
105 assertThat(messageCleaner.clean("Text\u000fclear", of(clear)), is("Textclear"));
109 public void clearFormattingIsNotRemovedUnwanted() {
110 assertThat(messageCleaner.clean("Text\u000fclear", Collections.<Attributes>emptySet()), is("Text\u000fclear"));
114 public void removeUnderlineFormatting() {
115 assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
119 public void underlineFormattingIsNotRemovedUnwanted() {
120 assertThat(messageCleaner.clean("Text\u001funderline", Collections.<Attributes>emptySet()), is("Text\u001funderline"));
124 public void removeReverseFormatting() {
125 assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
129 public void reverseFormattingIsNotRemovedUnwanted() {
130 assertThat(messageCleaner.clean("Text\u0016reverse", Collections.<Attributes>emptySet()), is("Text\u0016reverse"));
134 public void removeItalicFormatting() {
135 assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
139 public void italicFormattingIsNotRemovedUnwanted() {
140 assertThat(messageCleaner.clean("Text\u001ditalics", Collections.<Attributes>emptySet()), is("Text\u001ditalics"));
144 public void removeEverything() {
145 assertThat(messageCleaner.clean("a\u0002b\u00031,49\u001dd\u001fe\u0016f\u000fg"), is("ab9defg"));