From 98efc01af1fdafeaf17c983d13cca0dedd9d9ba3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 10 Jul 2015 10:43:57 +0200 Subject: [PATCH] Add test for text filter --- .../pterodactylus/sone/text/TextFilterTest.java | 52 ++++++++++++++++++++++ 1 file changed, 52 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..1076a8a --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/text/TextFilterTest.java @@ -0,0 +1,52 @@ +package net.pterodactylus.sone.text; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * JUnit test for {@link TextFilter}. + * + * @author David ‘Bombe’ Roden + */ +public class TextFilterTest { + + @Test + public void textFilterCanBeCreated() { + new TextFilter(); + } + + @Test + public void textFilterRemovesHttpLinkToSameHost() { + String textWithHttpLink = "Some text with an http://foo.bar/link.html in it."; + assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it.")); + } + + @Test + public void textFilterRemovesHttpsLinkToSameHost() { + String textWithHttpLink = "Some text with an https://foo.bar/link.html in it."; + assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it.")); + } + + @Test + public void textWithoutALinkIsReturnedUnmodified() { + String textWithHttpLink = "Some text without a link in it."; + assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text without a link in it.")); + } + + @Test + public void nothingIsRemovedWhenThereIsNoHostHeader() { + String textWithHttpLink = "Some text with an https://foo.bar/link.html in it."; + assertThat(TextFilter.filter(null, textWithHttpLink), is("Some text with an https://foo.bar/link.html in it.")); + } + + @Test + public void textFilterDoesNotRemoveLinksToDifferentHost() { + String textWithHttpLink = "Some text with an https://foo.bar/link.html in it."; + assertThat(TextFilter.filter("bar.baz", textWithHttpLink), is("Some text with an https://foo.bar/link.html in it.")); + } + +} -- 2.7.4