From: David ‘Bombe’ Roden Date: Sat, 2 Nov 2013 11:30:21 +0000 (+0100) Subject: Add unit test for TextFilter. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=042ca46393daa78c474f7835dbe1b460101f3ce3;p=Sone.git Add unit test for TextFilter. --- diff --git a/src/test/java/net/pterodactylus/sone/text/TextFilterTest.java b/src/test/java/net/pterodactylus/sone/text/TextFilterTest.java new file mode 100644 index 0000000..39fa5a3 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/text/TextFilterTest.java @@ -0,0 +1,40 @@ +package net.pterodactylus.sone.text; + +import static net.pterodactylus.sone.text.TextFilter.filter; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Unit test for {@link TextFilter}. + * + * @author David Roden + */ +public class TextFilterTest { + + private static final String ORIGINAL_TEXT = "1:https://127.0.0.1/ 2:http://127.0.0.1/ 3:http://127.0.0.1 4:https://127.0.0.1 5:http://localhost/ 6:http://localhost"; + private static final String FILTERED1 = "1: 2: 3: 4: 5:http://localhost/ 6:http://localhost"; + private static final String FILTERED2 = "1:https://127.0.0.1/ 2:http://127.0.0.1/ 3:http://127.0.0.1 4:https://127.0.0.1 5: 6:"; + + @Test + public void canCreateTextFilter() { + new TextFilter(); + } + + @Test + public void removeLinksTo127001() { + assertThat(filter("127.0.0.1", ORIGINAL_TEXT), is(FILTERED1)); + } + + @Test + public void removeLinksToLocalhost() { + assertThat(filter("localhost", ORIGINAL_TEXT), is(FILTERED2)); + } + + @Test + public void doNotRemoveLinksWithoutHostHeader() { + assertThat(filter(null, ORIGINAL_TEXT), is(ORIGINAL_TEXT)); + } + +}