Home | History | Annotate | Download | only in wifi
      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 
     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.RuntimeEnvironment;
     37 
     38 @RunWith(SettingsRobolectricTestRunner.class)
     39 public class LinkablePreferenceTest {
     40 
     41     private static final String TITLE = "Title";
     42 
     43     private Context mContext = RuntimeEnvironment.application;
     44 
     45     private LinkablePreference mPreference;
     46     private PreferenceViewHolder mHolder;
     47     private View mView;
     48 
     49     @Before
     50     public void setUp() {
     51         MockitoAnnotations.initMocks(this);
     52 
     53         mPreference = new LinkablePreference(mContext);
     54         final CharSequence linkableDescription = mContext.getText(R.string.wifi_scan_notify_text);
     55         final LinkifyUtils.OnClickListener clickListener = () -> {/* Do nothing */ };
     56         mPreference.setText(TITLE, linkableDescription, clickListener);
     57 
     58         LayoutInflater inflater = LayoutInflater.from(mContext);
     59         mView =
     60             inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
     61         mHolder = PreferenceViewHolder.createInstanceForTests(mView);
     62 
     63         mPreference.onBindViewHolder(mHolder);
     64     }
     65 
     66     @Test
     67     public void prefWithLinkShouldHaveAccessibilityMovementMethodSet() {
     68         TextView textView = mView.findViewById(android.R.id.title);
     69         assertThat(textView).isNotNull();
     70         assertThat(textView.getMovementMethod()).isNotNull();
     71     }
     72 }
     73