1 /*
2  * Copyright (C) 2019 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 
17 package com.android.settings.accessibility;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.text.method.MovementMethod;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.widget.TextView;
26 
27 import androidx.preference.PreferenceViewHolder;
28 
29 import com.android.settings.R;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.robolectric.RobolectricTestRunner;
35 import org.robolectric.RuntimeEnvironment;
36 
37 /** Tests for {@link AccessibilityFooterPreference} */
38 @RunWith(RobolectricTestRunner.class)
39 public final class AccessibilityFooterPreferenceTest {
40 
41     private AccessibilityFooterPreference mAccessibilityFooterPreference;
42     private PreferenceViewHolder mPreferenceViewHolder;
43 
44     @Before
setUp()45     public void setUp() {
46         final Context context = RuntimeEnvironment.application;
47         mAccessibilityFooterPreference = new AccessibilityFooterPreference(context);
48 
49         final LayoutInflater inflater = LayoutInflater.from(context);
50         final View view =
51                 inflater.inflate(R.layout.preference_footer, null);
52         mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
53     }
54 
55     @Test
onBindViewHolder_LinkDisabledByDefault_notReturnLinkMovement()56     public void onBindViewHolder_LinkDisabledByDefault_notReturnLinkMovement() {
57         mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
58 
59         final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
60                 android.R.id.title);
61         assertThat(summaryView.getMovementMethod()).isNull();
62     }
63 
64     @Test
onBindViewHolder_setLinkEnabled_returnLinkMovement()65     public void onBindViewHolder_setLinkEnabled_returnLinkMovement() {
66         mAccessibilityFooterPreference.setLinkEnabled(true);
67 
68         mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
69 
70         final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
71                 android.R.id.title);
72         assertThat(summaryView.getMovementMethod()).isInstanceOf(MovementMethod.class);
73     }
74 }
75