1 /* 2 * Copyright (C) 2016 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.settingslib.widget; 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.text.method.LinkMovementMethod; 24 import android.view.LayoutInflater; 25 import android.widget.TextView; 26 27 import com.android.settingslib.R; 28 import com.android.settingslib.SettingsLibRobolectricTestRunner; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.robolectric.shadows.ShadowApplication; 34 35 @RunWith(SettingsLibRobolectricTestRunner.class) 36 public class FooterPreferenceTest { 37 38 private Context mContext; 39 40 @Before 41 public void setUp() { 42 mContext = ShadowApplication.getInstance().getApplicationContext(); 43 } 44 45 @Test 46 public void createNewPreference_shouldSetKeyAndOrder() { 47 final FooterPreference preference = new FooterPreference(mContext); 48 49 assertThat(preference.getKey()).isEqualTo(FooterPreference.KEY_FOOTER); 50 assertThat(preference.getOrder()).isEqualTo(FooterPreference.ORDER_FOOTER); 51 } 52 53 @Test 54 public void bindPreference_shouldLinkifyContent() { 55 final FooterPreference preference = new FooterPreference(mContext); 56 final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests( 57 LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null)); 58 59 preference.onBindViewHolder(holder); 60 assertThat(((TextView) holder.findViewById(android.R.id.title)).getMovementMethod()) 61 .isInstanceOf(LinkMovementMethod.class); 62 } 63 } 64