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