RegexUtils { public static List<String> extractLinks(String content) { if (content == null || content.length() == 0) { return Collections.emptyList(); } List<String> extractions = new ArrayList<String>(); final Matcher matcher = LINKS_PATTERN.matcher(content); while (matcher.find()) { extractions.add(matcher.group()); } return extractions; }  static List<String> extractLinks(String content);  }
@Test public void testExtractLinksNone() { List<String> links = null; links = RegexUtils.extractLinks(null); assertNotNull(links); assertEquals(0, links.size()); links = RegexUtils.extractLinks(""); assertNotNull(links); assertEquals(0, links.size()); links = RegexUtils.extractLinks( "Test with no links " + "What about www.google.com"); assertNotNull(links); assertEquals(0, links.size()); }
@Test public void testExtractLinksHttp() { List<String> links = RegexUtils.extractLinks( "Test with http: "What about www.google.com at http: "A longer URL could be http: assertTrue("Url not found!", links.size() == 3); assertEquals("Wrong URL", "http: assertEquals("Wrong URL", "http: assertEquals("Wrong URL", "http: }
@Test public void testExtractLinksFtp() { List<String> links = RegexUtils.extractLinks( "Test with ftp: "What about www.google.com at ftp: assertTrue("Url not found!", links.size() == 2); assertEquals("Wrong URL", "ftp: assertEquals("Wrong URL", "ftp: }