🔀 Merge branch 'release/v82'
[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.junit.Test;
7
8 /**
9  * JUnit test for {@link TextFilter}.
10  */
11 public class TextFilterTest {
12
13         @Test
14         public void textFilterCanBeCreated() {
15                 new TextFilter();
16         }
17
18         @Test
19         public void textFilterRemovesHttpLinkToSameHost() {
20                 String textWithHttpLink = "Some text with an http://foo.bar/link.html in it.";
21                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it."));
22         }
23
24         @Test
25         public void textFilterRemovesHttpsLinkToSameHost() {
26                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
27                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text with an link.html in it."));
28         }
29
30         @Test
31         public void textWithoutALinkIsReturnedUnmodified() {
32                 String textWithHttpLink = "Some text without a link in it.";
33                 assertThat(TextFilter.filter("foo.bar", textWithHttpLink), is("Some text without a link in it."));
34         }
35
36         @Test
37         public void nothingIsRemovedWhenThereIsNoHostHeader() {
38                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
39                 assertThat(TextFilter.filter(null, textWithHttpLink), is("Some text with an https://foo.bar/link.html in it."));
40         }
41
42         @Test
43         public void textFilterDoesNotRemoveLinksToDifferentHost() {
44                 String textWithHttpLink = "Some text with an https://foo.bar/link.html in it.";
45                 assertThat(TextFilter.filter("bar.baz", textWithHttpLink), is("Some text with an https://foo.bar/link.html in it."));
46         }
47
48 }