Add unit test for TextFilter.
[Sone.git] / src / test / java / net / pterodactylus / sone / text / TextFilterTest.java
1 package net.pterodactylus.sone.text;
2
3 import static net.pterodactylus.sone.text.TextFilter.filter;
4 import static org.hamcrest.Matchers.is;
5 import static org.junit.Assert.assertThat;
6
7 import org.junit.Test;
8
9 /**
10  * Unit test for {@link TextFilter}.
11  *
12  * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
13  */
14 public class TextFilterTest {
15
16         private static final String ORIGINAL_TEXT = "1:https://127.0.0.1/ 2:http://127.0.0.1/ 3:http://127.0.0.1 4:https://127.0.0.1 5:http://localhost/ 6:http://localhost";
17         private static final String FILTERED1 = "1: 2: 3: 4: 5:http://localhost/ 6:http://localhost";
18         private static final String FILTERED2 = "1:https://127.0.0.1/ 2:http://127.0.0.1/ 3:http://127.0.0.1 4:https://127.0.0.1 5: 6:";
19
20         @Test
21         public void canCreateTextFilter() {
22                 new TextFilter();
23         }
24
25         @Test
26         public void removeLinksTo127001() {
27                 assertThat(filter("127.0.0.1", ORIGINAL_TEXT), is(FILTERED1));
28         }
29
30         @Test
31         public void removeLinksToLocalhost() {
32                 assertThat(filter("localhost", ORIGINAL_TEXT), is(FILTERED2));
33         }
34
35         @Test
36         public void doNotRemoveLinksWithoutHostHeader() {
37                 assertThat(filter(null, ORIGINAL_TEXT), is(ORIGINAL_TEXT));
38         }
39
40 }