1 /* 2 * Copyright (C) 2022 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.accessibility; 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.FrameLayout; 25 26 import androidx.preference.PreferenceViewHolder; 27 import androidx.test.core.app.ApplicationProvider; 28 29 import com.android.settings.R; 30 31 import org.junit.Before; 32 import org.junit.Rule; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.Mock; 36 import org.mockito.junit.MockitoJUnit; 37 import org.mockito.junit.MockitoRule; 38 import org.robolectric.RobolectricTestRunner; 39 40 /** 41 * Tests for {@link TextReadingResetPreference}. 42 */ 43 @RunWith(RobolectricTestRunner.class) 44 public class TextReadingResetPreferenceTest { 45 private final Context mContext = ApplicationProvider.getApplicationContext(); 46 private TextReadingResetPreference mResetPreference; 47 private PreferenceViewHolder mHolder; 48 private View mButtonView; 49 50 @Rule 51 public final MockitoRule mMockitoRule = MockitoJUnit.rule(); 52 53 @Mock 54 private View.OnClickListener mOnResetClickListener; 55 56 @Before setUp()57 public void setUp() { 58 mResetPreference = new TextReadingResetPreference(mContext, /* attrs= */ null); 59 final LayoutInflater inflater = LayoutInflater.from(mContext); 60 final View view = inflater.inflate(mResetPreference.getLayoutResource(), 61 new FrameLayout(mContext), false); 62 mHolder = PreferenceViewHolder.createInstanceForTests(view); 63 mButtonView = view.findViewById(R.id.reset_button); 64 } 65 66 @Test setResetListener_success()67 public void setResetListener_success() { 68 mResetPreference.setOnResetClickListener(mOnResetClickListener); 69 mResetPreference.onBindViewHolder(mHolder); 70 71 assertThat(mButtonView.hasOnClickListeners()).isTrue(); 72 } 73 } 74