From: David ‘Bombe’ Roden Date: Fri, 10 Jul 2015 08:43:57 +0000 (+0200) Subject: Add test for text filter X-Git-Tag: 0.9^2~4 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=98efc01af1fdafeaf17c983d13cca0dedd9d9ba3;p=Sone.git Add test for text filter --- 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.")); + } + +}