aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/androidTest/java/org/wordpress/android/util/AutolinkUtilsTest.java
blob: 5341c96bd95bf63729337a8874feb5c69c79a622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

public class AutolinkUtilsTest extends InstrumentationTestCase {
    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testNullString() {
        AutolinkUtils.autoCreateLinks(null);
    }

    public void testEmptyString() {
        String sourceTest = "";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        assertEquals(sourceTest, output);
    }

    public void testNonBlacklistedUrl1() {
        String sourceTest = "http://test.com";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        String expected = "<a href=\"http://test.com\">http://test.com</a>";
        assertEquals(expected, output);
    }

    public void testNonBlacklistedUrl2() {
        String sourceTest = "http://test.com http://test.com";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        String expected = "<a href=\"http://test.com\">http://test.com</a> <a href=\"http://test.com\">http://test.com</a>";
        assertEquals(expected, output);
    }

    public void testNonBlacklistedUrl3() {
        String sourceTest = "http://test.com\nhttp://test.com";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        String expected = "<a href=\"http://test.com\">http://test.com</a>\n<a href=\"http://test.com\">http://test.com</a>";
        assertEquals(expected, output);
    }

    public void testBlacklistedUrl1() {
        String sourceTest = "http://youtube.com/watch?test";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        assertEquals(sourceTest, output);
    }

    public void testMixedUrls1() {
        String sourceTest = "hey http://youtube.com/watch?test salut http://test.com hello";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        String expected = "hey http://youtube.com/watch?test salut <a href=\"http://test.com\">http://test.com</a> hello";
        assertEquals(expected, output);
    }

    public void testExistingAHref1() {
        String sourceTest = "<a href=\"http://test.com\">http://test.com</a>";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        assertEquals(sourceTest, output);
    }

    public void testUndetectable1() {
        String sourceTest = "testhttp://test.com";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        assertEquals(sourceTest, output);
    }

    public void testUndetectable2() {
        String sourceTest = "\"http://test.com\"";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        assertEquals(sourceTest, output);
    }

    public void testMixedUrls2() {
        String sourceTest = "http://test.com http://www.youtube.com/watch?test http://test.com http://youtu.be/wat";
        String output = AutolinkUtils.autoCreateLinks(sourceTest);
        String expected = "<a href=\"http://test.com\">http://test.com</a> http://www.youtube.com/watch?test <a href=\"http://test.com\">http://test.com</a> http://youtu.be/wat";
        assertEquals(expected, output);
    }
}