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.support.v7.preference.PreferenceViewHolder; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.widget.LinearLayout; 26 import android.widget.TextView; 27 28 import com.android.settings.LinkifyUtils; 29 import com.android.settings.R; 30 import com.android.settings.testutils.SettingsRobolectricTestRunner; 31 import com.android.settings.TestConfig; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.mockito.MockitoAnnotations; 37 import org.robolectric.RuntimeEnvironment; 38 import org.robolectric.annotation.Config; 39 40 @RunWith(SettingsRobolectricTestRunner.class) 41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 42 public 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