package net.pterodactylus.irc.util;
+import static java.util.EnumSet.of;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.bold;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.clear;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.color;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.italics;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.reverse;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.underline;
+import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import java.util.EnumSet;
-
import net.pterodactylus.irc.util.MessageCleaner.Attributes;
import org.junit.Test;
*/
public class MessageCleanerTest {
+ private final MessageCleaner messageCleaner = getDefaultInstance();
+
/** Tests removal of {@link Attributes#bold} formatting. */
@Test
public void testRemoveBold() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
-
- clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold));
+ String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(bold));
assertThat(clean, is("This contains bold characters."));
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.bold));
+ clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(bold));
assertThat(clean, is("This contains bold and \u00034color\u0003 characters."));
}
/** Tests removal of {@link Attributes#color} formatting. */
@Test
public void testRemoveColors() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
-
- clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color));
+ String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(color));
assertThat(clean, is("This contains \u0002bold\u0002 characters."));
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.color));
+ clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(color));
assertThat(clean, is("This contains \u0002bold\u0002 and color characters."));
- clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", EnumSet.of(Attributes.color));
+ clean = messageCleaner.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", of(color));
assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
}
/** Tests removal of {@link Attributes#clear} formatting. */
@Test
public void testRemoveClear() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
-
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.clear));
+ String clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(clear));
assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 characters."));
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", EnumSet.of(Attributes.clear));
+ clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", of(clear));
assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 and clear characters."));
}
/** Tests removal of all formatting. */
@Test
public void testRemoveAll() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
-
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
+ String clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
assertThat(clean, is("This contains bold and color characters."));
- clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.");
+ clean = messageCleaner.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.");
assertThat(clean, is("This contains colorful 8shit and 8stuff and characters."));
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.");
+ clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.");
assertThat(clean, is("This contains bold and color and clear characters."));
}
@Test
public void removeUnderlineFormatting() {
- MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
- assertThat(messageCleaner.clean("Text\u0016underline"), is("Textunderline"));
+ assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
}
@Test
public void removeReverseFormatting() {
- MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
- assertThat(messageCleaner.clean("Text\u001freverse"), is("Textreverse"));
+ assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
}
@Test
public void removeItalicFormatting() {
- MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
- assertThat(messageCleaner.clean("Text\u001ditalics"), is("Textitalics"));
+ assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
}
}