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.ComponentName;
22 import android.content.Context;
23 
24 import androidx.test.core.app.ApplicationProvider;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.robolectric.RobolectricTestRunner;
29 
30 /** Tests for {@link AccessibilityQuickSettingUtils}. */
31 @RunWith(RobolectricTestRunner.class)
32 public final class AccessibilityQuickSettingUtilsTest {
33     private static final String DUMMY_PACKAGE_NAME = "com.mock.example";
34     private static final String DUMMY_CLASS_NAME = DUMMY_PACKAGE_NAME + ".mock_a11y_service";
35     private static final String DUMMY_CLASS_NAME2 = DUMMY_PACKAGE_NAME + ".mock_a11y_service2";
36     private static final ComponentName DUMMY_COMPONENT_NAME = new ComponentName(DUMMY_PACKAGE_NAME,
37             DUMMY_CLASS_NAME);
38     private static final ComponentName DUMMY_COMPONENT_NAME2 = new ComponentName(DUMMY_PACKAGE_NAME,
39             DUMMY_CLASS_NAME2);
40     private final Context mContext = ApplicationProvider.getApplicationContext();
41 
42     @Test
optInValueToSharedPreferences_optInValue_haveMatchString()43     public void optInValueToSharedPreferences_optInValue_haveMatchString() {
44         AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
45                 DUMMY_COMPONENT_NAME);
46 
47         assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
48                 DUMMY_COMPONENT_NAME)).isTrue();
49     }
50 
51     @Test
optInValueToSharedPreferences_optInTwoValues_haveMatchString()52     public void optInValueToSharedPreferences_optInTwoValues_haveMatchString() {
53         AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
54                 DUMMY_COMPONENT_NAME);
55         AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
56                 DUMMY_COMPONENT_NAME2);
57 
58         assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
59                 DUMMY_COMPONENT_NAME)).isTrue();
60         assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
61                 DUMMY_COMPONENT_NAME2)).isTrue();
62     }
63 }
64