Add message cleaner.
[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 org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.is;
22
23 import java.util.EnumSet;
24
25 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
26
27 import org.testng.annotations.Test;
28
29 /**
30  * Tests for {@link MessageCleaner}.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 public class MessageCleanerTest {
35
36         /** Tests removal of {@link Attributes#bold} formatting. */
37         @Test
38         public void testRemoveBold() {
39                 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
40                 String clean;
41
42                 clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold));
43                 assertThat(clean, is("This contains bold characters."));
44
45                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.bold));
46                 assertThat(clean, is("This contains bold and \u00034color\u0003 characters."));
47         }
48
49         /** Tests removal of {@link Attributes#color} formatting. */
50         @Test
51         public void testRemoveColors() {
52                 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
53                 String clean;
54
55                 clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color));
56                 assertThat(clean, is("This contains \u0002bold\u0002 characters."));
57
58                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.color));
59                 assertThat(clean, is("This contains \u0002bold\u0002 and color characters."));
60
61                 clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", EnumSet.of(Attributes.color));
62                 assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
63         }
64
65         /** Tests removal of {@link Attributes#clear} formatting. */
66         @Test
67         public void testRemoveClear() {
68                 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
69                 String clean;
70
71                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.clear));
72                 assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 characters."));
73
74                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", EnumSet.of(Attributes.clear));
75                 assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 and clear characters."));
76         }
77
78         /** Tests removal of all formatting. */
79         @Test
80         public void testRemoveAll() {
81                 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
82                 String clean;
83
84                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
85                 assertThat(clean, is("This contains bold and color characters."));
86
87                 clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.");
88                 assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
89
90                 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.");
91                 assertThat(clean, is("This contains bold and color and clear characters."));
92         }
93
94 }