1 /* 2 * Copyright (C) 2023 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.inputmethod; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.spy; 22 23 import android.content.Context; 24 import android.content.Intent; 25 import android.view.View; 26 import android.view.textservice.SpellCheckerInfo; 27 28 import androidx.preference.PreferenceViewHolder; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.robolectric.RobolectricTestRunner; 34 import org.robolectric.RuntimeEnvironment; 35 36 @RunWith(RobolectricTestRunner.class) 37 public class SpellCheckerPreferenceTest { 38 39 private Context mContext; 40 private PreferenceViewHolder mViewHolder; 41 private View mDivider; 42 private SpellCheckerPreference mPreference; 43 private final SpellCheckerInfo[] mScis = new SpellCheckerInfo[]{}; 44 45 @Before setUp()46 public void setUp() { 47 mContext = RuntimeEnvironment.application; 48 mPreference = new SpellCheckerPreference(mContext, mScis); 49 } 50 51 @Test onBindViewHolder_withIntent_DividerIsVisible()52 public void onBindViewHolder_withIntent_DividerIsVisible() { 53 final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); 54 mViewHolder = PreferenceViewHolder.createInstanceForTests(view); 55 mDivider = view.findViewById( 56 com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); 57 mPreference.mIntent = new Intent(Intent.ACTION_MAIN); 58 59 mPreference.onBindViewHolder(mViewHolder); 60 61 assertThat(mDivider.getVisibility()).isEqualTo(View.VISIBLE); 62 } 63 64 @Test onBindViewHolder_withoutIntent_DividerIsNotExist()65 public void onBindViewHolder_withoutIntent_DividerIsNotExist() { 66 final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); 67 mViewHolder = PreferenceViewHolder.createInstanceForTests(view); 68 mDivider = view.findViewById( 69 com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); 70 71 mPreference.onBindViewHolder(mViewHolder); 72 73 assertThat(mDivider.getVisibility()).isEqualTo(View.GONE); 74 } 75 } 76