1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.utils;
18
19 import java.util.List;
20 import junit.framework.TestCase;
21
22
23
24
25
26
27 public class RegexUtilsTest extends TestCase {
28
29
30
31
32
33 public void testExtractLinksNone() {
34 List<String> links = null;
35
36 links = RegexUtils.extractLinks(null);
37 assertNotNull(links);
38 assertEquals(0, links.size());
39
40 links = RegexUtils.extractLinks("");
41 assertNotNull(links);
42 assertEquals(0, links.size());
43
44 links = RegexUtils.extractLinks(
45 "Test with no links " +
46 "What about www.google.com");
47 assertNotNull(links);
48 assertEquals(0, links.size());
49 }
50
51
52
53
54
55 public void testExtractLinksHttp() {
56 List<String> links = RegexUtils.extractLinks(
57 "Test with http://www.nutch.org/index.html is it found? " +
58 "What about www.google.com at http://www.google.de " +
59 "A longer URL could be http://www.sybit.com/solutions/portals.html");
60
61 assertTrue("Url not found!", links.size() == 3);
62 assertEquals("Wrong URL", "http://www.nutch.org/index.html", links.get(0));
63 assertEquals("Wrong URL", "http://www.google.de", links.get(1));
64 assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", links.get(2));
65 }
66
67
68
69
70 public void testExtractLinksFtp() {
71 List<String> links = RegexUtils.extractLinks(
72 "Test with ftp://www.nutch.org is it found? " +
73 "What about www.google.com at ftp://www.google.de");
74
75 assertTrue("Url not found!", links.size() == 2);
76 assertEquals("Wrong URL", "ftp://www.nutch.org", links.get(0));
77 assertEquals("Wrong URL", "ftp://www.google.de", links.get(1));
78 }
79 }