bbbf5071b2d98940994f5783bd8dfa571cc9d9f8
[xudocci.git] / src / test / java / net / pterodactylus / irc / util / MessageCleanerTest.java
1 /*
2  * XdccDownloader - MessageCleanerTest.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.irc.util;
19
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;
30
31 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
32
33 import org.junit.Test;
34
35 /**
36  * Tests for {@link MessageCleaner}.
37  *
38  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39  */
40 public class MessageCleanerTest {
41
42         private final MessageCleaner messageCleaner = getDefaultInstance();
43
44         /** Tests removal of {@link Attributes#bold} formatting. */
45         @Test
46         public void testRemoveBold() {
47                 String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(bold));
48                 assertThat(clean, is("This contains bold characters."));
49
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."));
52         }
53
54         /** Tests removal of {@link Attributes#color} formatting. */
55         @Test
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."));
59
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."));
62
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."));
65         }
66
67         /** Tests removal of {@link Attributes#clear} formatting. */
68         @Test
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."));
72
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."));
75         }
76
77         /** Tests removal of all formatting. */
78         @Test
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."));
82
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."));
85
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."));
88         }
89
90         @Test
91         public void removeUnderlineFormatting() {
92                 assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
93         }
94
95         @Test
96         public void removeReverseFormatting() {
97                 assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
98         }
99
100         @Test
101         public void removeItalicFormatting() {
102                 assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
103         }
104
105 }