• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 import org.robolectric.RuntimeEnvironment;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class BalanceSeekBarPreferenceTest {
37     private static final int BALANCE_CENTER_VALUE = 100;
38     private static final int BALANCE_MAX_VALUE = 200;
39 
40     private Context mContext;
41     private AttributeSet mAttrs;
42     private PreferenceViewHolder mHolder;
43     private BalanceSeekBar mSeekBar;
44     private BalanceSeekBarPreference mSeekBarPreference;
45 
46     @Before
setUp()47     public void setUp() {
48         mContext = RuntimeEnvironment.application;
49         mSeekBarPreference = new BalanceSeekBarPreference(mContext, mAttrs);
50         LayoutInflater inflater = LayoutInflater.from(mContext);
51         final View view =
52                 inflater.inflate(mSeekBarPreference.getLayoutResource(),
53                         new LinearLayout(mContext), false);
54         mHolder = PreferenceViewHolder.createInstanceForTests(view);
55         mSeekBar = (BalanceSeekBar) view.findViewById(com.android.internal.R.id.seekbar);
56     }
57 
58     @Test
seekBarPreferenceOnBindViewHolder_shouldInitSeekBarValue()59     public void seekBarPreferenceOnBindViewHolder_shouldInitSeekBarValue() {
60         mSeekBarPreference.onBindViewHolder(mHolder);
61 
62         assertThat(mSeekBar.getMax()).isEqualTo(BALANCE_MAX_VALUE);
63         assertThat(mSeekBar.getProgress()).isEqualTo(BALANCE_CENTER_VALUE);
64     }
65 }
66