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.provider.Settings;
23 
24 import com.android.settings.R;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.robolectric.RobolectricTestRunner;
30 import org.robolectric.RuntimeEnvironment;
31 
32 @RunWith(RobolectricTestRunner.class)
33 public class DaltonizerPreferenceControllerTest {
34     private static final String PREF_KEY = "daltonizer_preference";
35     private static final int ON = 1;
36     private static final int OFF = 0;
37 
38     private Context mContext;
39     private DaltonizerPreferenceController mController;
40 
41     @Before
setUp()42     public void setUp() {
43         mContext = RuntimeEnvironment.application;
44         mController = new DaltonizerPreferenceController(mContext, PREF_KEY);
45     }
46 
47     @Test
getSummary_enabledColorCorrection_shouldReturnOnSummary()48     public void getSummary_enabledColorCorrection_shouldReturnOnSummary() {
49         Settings.Secure.putInt(mContext.getContentResolver(),
50                 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, ON);
51 
52         assertThat(mController.getSummary().toString().contains(
53                 mContext.getText(R.string.accessibility_feature_state_on))).isTrue();
54     }
55 
56     @Test
getSummary_disabledColorCorrection_shouldReturnOffSummary()57     public void getSummary_disabledColorCorrection_shouldReturnOffSummary() {
58         Settings.Secure.putInt(mContext.getContentResolver(),
59                 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
60 
61         assertThat(mController.getSummary().toString().contains(
62                 mContext.getText(R.string.accessibility_feature_state_off))).isTrue();
63     }
64 }
65