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.accessibility;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.when;
23 
24 import android.app.settings.SettingsEnums;
25 import android.content.Context;
26 import android.content.res.Resources;
27 
28 import androidx.test.core.app.ApplicationProvider;
29 
30 import com.android.settings.R;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.robolectric.RobolectricTestRunner;
36 
37 /** Tests for {@link VibrationIntensitySettingsFragment}. */
38 @RunWith(RobolectricTestRunner.class)
39 public class VibrationIntensitySettingsFragmentTest {
40 
41     private Context mContext;
42     private Resources mResources;
43     private VibrationIntensitySettingsFragment mFragment;
44 
45     @Before
setUp()46     public void setUp() {
47         mContext = spy(ApplicationProvider.getApplicationContext());
48         mResources = spy(mContext.getResources());
49         when(mContext.getResources()).thenReturn(mResources);
50         mFragment = new VibrationIntensitySettingsFragment();
51     }
52 
53     @Test
getMetricsCategory_returnsCorrectCategory()54     public void getMetricsCategory_returnsCorrectCategory() {
55         assertThat(mFragment.getMetricsCategory()).isEqualTo(
56                 SettingsEnums.ACCESSIBILITY_VIBRATION);
57     }
58 
59     @Test
getHelpResource_returnsCorrectString()60     public void getHelpResource_returnsCorrectString() {
61         assertThat(mFragment.getHelpResource()).isEqualTo(
62                 R.string.help_uri_accessibility_vibration);
63     }
64 
65     @Test
getPreferenceScreenResId_returnsCorrectXml()66     public void getPreferenceScreenResId_returnsCorrectXml() {
67         assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
68                 R.xml.accessibility_vibration_intensity_settings);
69     }
70 
71     @Test
getLogTag_returnsCorrectTag()72     public void getLogTag_returnsCorrectTag() {
73         assertThat(mFragment.getLogTag()).isEqualTo("VibrationIntensitySettings");
74     }
75 
76     @Test
isPageSearchEnabled_oneIntensityLevel_returnsFalse()77     public void isPageSearchEnabled_oneIntensityLevel_returnsFalse() {
78         when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
79                 .thenReturn(1);
80         assertThat(VibrationIntensitySettingsFragment.isPageSearchEnabled(mContext)).isFalse();
81     }
82 
83     @Test
isPageSearchEnabled_multipleIntensityLevels_returnsTrue()84     public void isPageSearchEnabled_multipleIntensityLevels_returnsTrue() {
85         when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
86                 .thenReturn(2);
87         assertThat(VibrationIntensitySettingsFragment.isPageSearchEnabled(mContext)).isTrue();
88     }
89 }
90