From 042ca46393daa78c474f7835dbe1b460101f3ce3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 2 Nov 2013 12:30:21 +0100 Subject: [PATCH] Add unit test for TextFilter. --- .../pterodactylus/sone/text/TextFilterTest.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/text/TextFilterTest.java 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)); + } + +} -- 2.7.4