Add test for text filter
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 10 Jul 2015 08:43:57 +0000 (10:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 10 Jul 2015 08:44:52 +0000 (10:44 +0200)
src/test/java/net/pterodactylus/sone/text/TextFilterTest.java [new file with mode: 0644]

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 (file)
index 0000000..1076a8a
--- /dev/null
@@ -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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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."));
+       }
+
+}