1/*
2 * Copyright (C) 2017 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 com.android.settings.wifi;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.content.Context;
22import android.support.v7.preference.PreferenceViewHolder;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.widget.LinearLayout;
26import android.widget.TextView;
27
28import com.android.settings.LinkifyUtils;
29import com.android.settings.R;
30import com.android.settings.SettingsRobolectricTestRunner;
31import com.android.settings.TestConfig;
32
33import org.junit.Before;
34import org.junit.Test;
35import org.junit.runner.RunWith;
36import org.mockito.MockitoAnnotations;
37import org.robolectric.RuntimeEnvironment;
38import org.robolectric.annotation.Config;
39
40@RunWith(SettingsRobolectricTestRunner.class)
41@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
42public class LinkablePreferenceTest {
43
44    private static final String TITLE = "Title";
45
46    private Context mContext = RuntimeEnvironment.application;
47
48    private LinkablePreference mPreference;
49    private PreferenceViewHolder mHolder;
50    private View mView;
51
52    @Before
53    public void setUp() {
54        MockitoAnnotations.initMocks(this);
55
56        mPreference = new LinkablePreference(mContext);
57        final CharSequence linkableDescription =
58                mContext.getResources().getText(R.string.wifi_scan_notify_text);
59        final LinkifyUtils.OnClickListener clickListener = () -> {/* Do nothing */ };
60        mPreference.setText(TITLE, linkableDescription, clickListener);
61
62        LayoutInflater inflater = LayoutInflater.from(mContext);
63        mView = inflater.inflate(
64                mPreference.getLayoutResource(), new LinearLayout(mContext), false);
65        mHolder = PreferenceViewHolder.createInstanceForTests(mView);
66
67        mPreference.onBindViewHolder(mHolder);
68    }
69
70    @Test
71    public void prefWithLinkShouldHaveAccessibilityMovementMethodSet() {
72        TextView textView = mView.findViewById(android.R.id.title);
73        assertThat(textView.getMovementMethod()).isNotNull();
74    }
75}
76