1 /* 2 * Copyright (C) 2019 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.util.AttributeSet; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.widget.LinearLayout; 26 27 import androidx.preference.PreferenceViewHolder; 28 29 import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.robolectric.RobolectricTestRunner; 35 import org.robolectric.RuntimeEnvironment; 36 import org.robolectric.annotation.Config; 37 38 @RunWith(RobolectricTestRunner.class) 39 @Config(shadows = {ShadowInteractionJankMonitor.class}) 40 public class BalanceSeekBarPreferenceTest { 41 private static final int BALANCE_CENTER_VALUE = 100; 42 private static final int BALANCE_MAX_VALUE = 200; 43 44 private Context mContext; 45 private AttributeSet mAttrs; 46 private PreferenceViewHolder mHolder; 47 private BalanceSeekBar mSeekBar; 48 private BalanceSeekBarPreference mSeekBarPreference; 49 50 @Before setUp()51 public void setUp() { 52 mContext = RuntimeEnvironment.application; 53 mSeekBarPreference = new BalanceSeekBarPreference(mContext, mAttrs); 54 LayoutInflater inflater = LayoutInflater.from(mContext); 55 final View view = 56 inflater.inflate(mSeekBarPreference.getLayoutResource(), 57 new LinearLayout(mContext), false); 58 mHolder = PreferenceViewHolder.createInstanceForTests(view); 59 mSeekBar = (BalanceSeekBar) view.findViewById(com.android.internal.R.id.seekbar); 60 } 61 62 @Test seekBarPreferenceOnBindViewHolder_shouldInitSeekBarValue()63 public void seekBarPreferenceOnBindViewHolder_shouldInitSeekBarValue() { 64 mSeekBarPreference.onBindViewHolder(mHolder); 65 66 assertThat(mSeekBar.getMax()).isEqualTo(BALANCE_MAX_VALUE); 67 assertThat(mSeekBar.getProgress()).isEqualTo(BALANCE_CENTER_VALUE); 68 } 69 } 70