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 VibrationSettings} fragment. */
38 @RunWith(RobolectricTestRunner.class)
39 public class VibrationSettingsTest {
40     private Context mContext;
41     private Resources mResources;
42     private VibrationSettings mFragment;
43 
44     @Before
setUp()45     public void setUp() {
46         mContext = spy(ApplicationProvider.getApplicationContext());
47         mResources = spy(mContext.getResources());
48         when(mContext.getResources()).thenReturn(mResources);
49         mFragment = new VibrationSettings();
50     }
51 
52     @Test
getMetricsCategory_returnsCorrectCategory()53     public void getMetricsCategory_returnsCorrectCategory() {
54         assertThat(mFragment.getMetricsCategory()).isEqualTo(
55                 SettingsEnums.ACCESSIBILITY_VIBRATION);
56     }
57 
58     @Test
getHelpResource_returnsCorrectString()59     public void getHelpResource_returnsCorrectString() {
60         assertThat(mFragment.getHelpResource()).isEqualTo(
61                 R.string.help_uri_accessibility_vibration);
62     }
63 
64     @Test
getPreferenceScreenResId_returnsCorrectXml()65     public void getPreferenceScreenResId_returnsCorrectXml() {
66         assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
67                 R.xml.accessibility_vibration_settings);
68     }
69 
70     @Test
getLogTag_returnsCorrectTag()71     public void getLogTag_returnsCorrectTag() {
72         assertThat(mFragment.getLogTag()).isEqualTo("VibrationSettings");
73     }
74 
75     @Test
isPageSearchEnabled_oneIntensityLevel_returnsTrue()76     public void isPageSearchEnabled_oneIntensityLevel_returnsTrue() {
77         when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
78                 .thenReturn(1);
79         assertThat(VibrationSettings.isPageSearchEnabled(mContext)).isTrue();
80     }
81 
82     @Test
isPageSearchEnabled_multipleIntensityLevels_returnsFalse()83     public void isPageSearchEnabled_multipleIntensityLevels_returnsFalse() {
84         when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
85                 .thenReturn(2);
86         assertThat(VibrationSettings.isPageSearchEnabled(mContext)).isFalse();
87     }
88 }
89