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 org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.is;
23 import java.util.EnumSet;
25 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
27 import org.testng.annotations.Test;
30 * Tests for {@link MessageCleaner}.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class MessageCleanerTest {
36 /** Tests removal of {@link Attributes#bold} formatting. */
38 public void testRemoveBold() {
39 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
42 clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold));
43 assertThat(clean, is("This contains bold characters."));
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."));
49 /** Tests removal of {@link Attributes#color} formatting. */
51 public void testRemoveColors() {
52 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
55 clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color));
56 assertThat(clean, is("This contains \u0002bold\u0002 characters."));
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."));
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."));
65 /** Tests removal of {@link Attributes#clear} formatting. */
67 public void testRemoveClear() {
68 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
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."));
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."));
78 /** Tests removal of all formatting. */
80 public void testRemoveAll() {
81 MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
84 clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
85 assertThat(clean, is("This contains bold and color characters."));
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."));
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."));