|
| 1 | +package org.nibor.autolink; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.EnumSet; |
| 5 | + |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import org.junit.runners.Parameterized; |
| 9 | +import org.junit.runners.Parameterized.Parameter; |
| 10 | +import org.junit.runners.Parameterized.Parameters; |
| 11 | + |
| 12 | +@RunWith(Parameterized.class) |
| 13 | +public class AutolinkWwwUrlTest extends AutolinkUrlTest { |
| 14 | + |
| 15 | + @Parameters(name = "{1}") |
| 16 | + public static Iterable<Object[]> data() { |
| 17 | + return Arrays.asList(new Object[][]{ |
| 18 | + {LinkExtractor.builder().linkTypes(EnumSet.of(LinkType.URL)).build(), "URL"}, |
| 19 | + {LinkExtractor.builder().build(), "all"} |
| 20 | + }); |
| 21 | + } |
| 22 | + |
| 23 | + @Parameter(0) |
| 24 | + public LinkExtractor linkExtractor; |
| 25 | + |
| 26 | + @Parameter(1) |
| 27 | + public String description; |
| 28 | + |
| 29 | + @Test |
| 30 | + public void notLinked() { |
| 31 | + assertNotLinked(""); |
| 32 | + assertNotLinked("wwwsomething.com"); |
| 33 | + assertNotLinked("ww.foo.com"); |
| 34 | + assertNotLinked("w.bar.foo.co"); |
| 35 | + assertNotLinked("www.something"); |
| 36 | + assertNotLinked("www.go"); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void linked() { |
| 41 | + assertLinked("www.s.com","|www.s.com|"); |
| 42 | + assertLinked("www.fo.uk","|www.fo.uk|"); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void schemes() { |
| 47 | + assertLinked("http://www.something.com","|http://www.something.com|"); |
| 48 | + assertLinked("http://something.com","|http://something.com|"); |
| 49 | + assertLinked("http://something.co.uk","|http://something.co.uk|"); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + protected LinkExtractor getLinkExtractor() { |
| 54 | + return linkExtractor; |
| 55 | + } |
| 56 | + |
| 57 | + private void assertLinked(String input, String expected) { |
| 58 | + super.assertLinked(input, expected, LinkType.URL); |
| 59 | + } |
| 60 | +} |
0 commit comments