Improve test case to cover more cases.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Apr 2014 05:10:53 +0000 (07:10 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Apr 2014 05:10:53 +0000 (07:10 +0200)
src/main/java/net/pterodactylus/irc/util/MessageCleaner.java
src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java

index 9c5aab7..4b91e4a 100644 (file)
@@ -155,7 +155,7 @@ public class MessageCleaner {
                                                } else {
                                                        inColorCode = 0;
                                                }
-                                       } else if (inColorCode == 9) {
+                                       } else {
                                                inColorCode = 0;
                                                if (c == '9') {
                                                        continue;
index bbbf507..986cbad 100644 (file)
@@ -28,6 +28,8 @@ import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
+import java.util.Collections;
+
 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
 
 import org.junit.Test;
@@ -41,50 +43,71 @@ public class MessageCleanerTest {
 
        private final MessageCleaner messageCleaner = getDefaultInstance();
 
-       /** Tests removal of {@link Attributes#bold} formatting. */
        @Test
-       public void testRemoveBold() {
-               String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(bold));
-               assertThat(clean, is("This contains bold characters."));
-
-               clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(bold));
-               assertThat(clean, is("This contains bold and \u00034color\u0003 characters."));
+       public void removeBoldFormatting() {
+               assertThat(messageCleaner.clean("Text\u0002bold", of(bold)), is("Textbold"));
        }
 
-       /** Tests removal of {@link Attributes#color} formatting. */
        @Test
-       public void testRemoveColors() {
-               String clean = messageCleaner.clean("This contains \u0002bold\u0002 characters.", of(color));
-               assertThat(clean, is("This contains \u0002bold\u0002 characters."));
-
-               clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", of(color));
-               assertThat(clean, is("This contains \u0002bold\u0002 and color characters."));
-
-               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."));
+       public void boldFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u0002bold", Collections.<Attributes>emptySet()), is("Text\u0002bold"));
        }
 
-       /** Tests removal of {@link Attributes#clear} formatting. */
        @Test
-       public void testRemoveClear() {
-               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 = 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."));
+       public void removeColorFormatting() {
+               assertThat(messageCleaner.clean("Text\u0003!color", of(color)), is("Text!color"));
+               assertThat(messageCleaner.clean("Text\u0003color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00034color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00034!color", of(color)), is("Text!color"));
+               assertThat(messageCleaner.clean("Text\u000314color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000318color", of(color)), is("Text8color"));
+               assertThat(messageCleaner.clean("Text\u000399color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00031,!color", of(color)), is("Text!color"));
+               assertThat(messageCleaner.clean("Text\u00031,color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00031,1!color", of(color)), is("Text!color"));
+               assertThat(messageCleaner.clean("Text\u00031,1color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00031,14color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00031,18color", of(color)), is("Text8color"));
+               assertThat(messageCleaner.clean("Text\u00031,99color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000314,color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000314,1color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000314,14color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000314,18color", of(color)), is("Text8color"));
+               assertThat(messageCleaner.clean("Text\u000314,99color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000399,99color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u000399,9color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00039color", of(color)), is("Textcolor"));
+               assertThat(messageCleaner.clean("Text\u00039,color", of(color)), is("Textcolor"));
        }
 
-       /** Tests removal of all formatting. */
        @Test
-       public void testRemoveAll() {
-               String clean = messageCleaner.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
-               assertThat(clean, is("This contains bold and color characters."));
+       public void colorFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u00034color", Collections.<Attributes>emptySet()), is("Text\u00034color"));
+               assertThat(messageCleaner.clean("Text\u000314color", Collections.<Attributes>emptySet()), is("Text\u000314color"));
+               assertThat(messageCleaner.clean("Text\u000318color", Collections.<Attributes>emptySet()), is("Text\u000318color"));
+               assertThat(messageCleaner.clean("Text\u000399color", Collections.<Attributes>emptySet()), is("Text\u000399color"));
+               assertThat(messageCleaner.clean("Text\u00031,color", Collections.<Attributes>emptySet()), is("Text\u00031,color"));
+               assertThat(messageCleaner.clean("Text\u00031,1color", Collections.<Attributes>emptySet()), is("Text\u00031,1color"));
+               assertThat(messageCleaner.clean("Text\u00031,14color", Collections.<Attributes>emptySet()), is("Text\u00031,14color"));
+               assertThat(messageCleaner.clean("Text\u00031,18color", Collections.<Attributes>emptySet()), is("Text\u00031,18color"));
+               assertThat(messageCleaner.clean("Text\u00031,99color", Collections.<Attributes>emptySet()), is("Text\u00031,99color"));
+               assertThat(messageCleaner.clean("Text\u000314,color", Collections.<Attributes>emptySet()), is("Text\u000314,color"));
+               assertThat(messageCleaner.clean("Text\u000314,1color", Collections.<Attributes>emptySet()), is("Text\u000314,1color"));
+               assertThat(messageCleaner.clean("Text\u000314,14color", Collections.<Attributes>emptySet()), is("Text\u000314,14color"));
+               assertThat(messageCleaner.clean("Text\u000314,18color", Collections.<Attributes>emptySet()), is("Text\u000314,18color"));
+               assertThat(messageCleaner.clean("Text\u000314,99color", Collections.<Attributes>emptySet()), is("Text\u000314,99color"));
+               assertThat(messageCleaner.clean("Text\u000399,99color", Collections.<Attributes>emptySet()), is("Text\u000399,99color"));
+               assertThat(messageCleaner.clean("Text\u00039color", Collections.<Attributes>emptySet()), is("Text\u00039color"));
+       }
 
-               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."));
+       @Test
+       public void removeClearFormatting() {
+               assertThat(messageCleaner.clean("Text\u000fclear", of(clear)), is("Textclear"));
+       }
 
-               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 clearFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u000fclear", Collections.<Attributes>emptySet()), is("Text\u000fclear"));
        }
 
        @Test
@@ -93,13 +116,28 @@ public class MessageCleanerTest {
        }
 
        @Test
+       public void underlineFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u001funderline", Collections.<Attributes>emptySet()), is("Text\u001funderline"));
+       }
+
+       @Test
        public void removeReverseFormatting() {
                assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
        }
 
        @Test
+       public void reverseFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u0016reverse", Collections.<Attributes>emptySet()), is("Text\u0016reverse"));
+       }
+
+       @Test
        public void removeItalicFormatting() {
                assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
        }
 
+       @Test
+       public void italicFormattingIsNotRemovedUnwanted() {
+               assertThat(messageCleaner.clean("Text\u001ditalics", Collections.<Attributes>emptySet()), is("Text\u001ditalics"));
+       }
+
 }