LinkifyTest.java revision 0dc59e78e18493aecd37427531d093e800846c3e
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text.util;
18
19import android.test.AndroidTestCase;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.test.suitebuilder.annotation.SmallTest;
22import android.text.method.LinkMovementMethod;
23import android.text.util.Linkify;
24import android.widget.TextView;
25
26/**
27 * LinkifyTest tests {@link Linkify}.
28 */
29public class LinkifyTest extends AndroidTestCase {
30
31    @SmallTest
32    public void testNothing() throws Exception {
33        TextView tv;
34
35        tv = new TextView(getContext());
36        tv.setText("Hey, foo@google.com, call 415-555-1212.");
37
38        assertFalse(tv.getMovementMethod() instanceof LinkMovementMethod);
39        assertTrue(tv.getUrls().length == 0);
40    }
41
42    @MediumTest
43    public void testNormal() throws Exception {
44        TextView tv;
45
46        tv = new TextView(getContext());
47        tv.setAutoLinkMask(Linkify.ALL);
48        tv.setText("Hey, foo@google.com, call 415-555-1212.");
49
50        assertTrue(tv.getMovementMethod() instanceof LinkMovementMethod);
51        assertTrue(tv.getUrls().length == 2);
52    }
53
54    @SmallTest
55    public void testUnclickable() throws Exception {
56        TextView tv;
57
58        tv = new TextView(getContext());
59        tv.setAutoLinkMask(Linkify.ALL);
60        tv.setLinksClickable(false);
61        tv.setText("Hey, foo@google.com, call 415-555-1212.");
62
63        assertFalse(tv.getMovementMethod() instanceof LinkMovementMethod);
64        assertTrue(tv.getUrls().length == 2);
65    }
66}
67