🔖 Set version to 81
[Sone.git] / src / test / java / net / pterodactylus / sone / text / TextFilterTest.java
1 package net.pterodactylus.sone.text;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
5
6 import org.hamcrest.MatcherAssert;
7 import org.hamcrest.Matchers;
8 import org.junit.Test;
9
10 /**
11  * JUnit test for {@link TextFilter}.
12  */
13 public class TextFilterTest {
14
15         @Test
16         public void textFilterCanBeCreated() {
17                 new TextFilter();
18         }
19
20         @Test
21         public void textFilterRemovesHttpLinkToSameHost() {
22                 String textWithHttpLink = "Some text with an http://foo.bar/link.html in it.";
23                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it."));
24         }
25
26         @Test
27         public void textFilterRemovesHttpsLinkToSameHost() {
28                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
29                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it."));
30         }
31
32         @Test
33         public void textWithoutALinkIsReturnedUnmodified() {
34                 String textWithHttpLink = "Some text without a link in it.";
35                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text without a link in it."));
36         }
37
38         @Test
39         public void nothingIsRemovedWhenThereIsNoHostHeader() {
40                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
41                 assertThat(TextFilter.filter(null, textWithHttpLink), is("Some text with an https://foo.bar/link.html in it."));
42         }
43
44         @Test
45         public void textFilterDoesNotRemoveLinksToDifferentHost() {
46                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
47                 assertThat(TextFilter.filter("bar.baz", textWithHttpLink), is("Some text with an https://foo.bar/link.html in it."));
48         }
49
50 }