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 import com.android.settings.core.BasePreferenceController;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.robolectric.RobolectricTestRunner;
31 import org.robolectric.RuntimeEnvironment;
32 
33 @RunWith(RobolectricTestRunner.class)
34 public class CaptioningPreferenceControllerTest {
35     private static final int ON = 1;
36     private static final int OFF = 0;
37 
38     private Context mContext;
39     private CaptioningPreferenceController mController;
40 
41     @Before
setUp()42     public void setUp() {
43         mContext = RuntimeEnvironment.application;
44         mController = new CaptioningPreferenceController(mContext, "captioning_pref");
45     }
46 
47     @Test
getAvailabilityStatus_byDefault_shouldReturnAvailable()48     public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
49         assertThat(mController.getAvailabilityStatus())
50                 .isEqualTo(BasePreferenceController.AVAILABLE);
51     }
52 
53     @Test
getSummary_enabledCaptions_shouldReturnOnSummary()54     public void getSummary_enabledCaptions_shouldReturnOnSummary() {
55         Settings.Secure.putInt(mContext.getContentResolver(),
56                 Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, ON);
57 
58         assertThat(mController.getSummary()).isEqualTo(
59                 mContext.getText(R.string.accessibility_feature_state_on));
60     }
61 
62     @Test
getSummary_disabledCaptions_shouldReturnOffSummary()63     public void getSummary_disabledCaptions_shouldReturnOffSummary() {
64         Settings.Secure.putInt(mContext.getContentResolver(),
65                 Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, OFF);
66 
67         assertThat(mController.getSummary()).isEqualTo(
68                 mContext.getText(R.string.accessibility_feature_state_off));
69     }
70 }
71