1 /*
2  * Copyright (C) 2024 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.display;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.platform.test.annotations.DisableFlags;
23 import android.platform.test.annotations.EnableFlags;
24 import android.platform.test.flag.junit.SetFlagsRule;
25 
26 import androidx.test.core.app.ApplicationProvider;
27 
28 import com.android.settings.accessibility.Flags;
29 import com.android.settings.core.BasePreferenceController;
30 
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.robolectric.RobolectricTestRunner;
36 
37 /** Tests for {@link ContrastPreferenceController}. */
38 @RunWith(RobolectricTestRunner.class)
39 public class ContrastPreferenceControllerTest {
40 
41     @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
42 
43     private static final String PREFERENCE_KEY = "preference_key";
44 
45     private Context mContext;
46     private ContrastPreferenceController mController;
47 
48     @Before
setUp()49     public void setUp() {
50         mContext = ApplicationProvider.getApplicationContext();
51         mController = new ContrastPreferenceController(mContext, PREFERENCE_KEY);
52     }
53 
54     @Test
55     @EnableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL)
getAvailabilityStatus_flagsEnabled_shouldReturnAvailable()56     public void getAvailabilityStatus_flagsEnabled_shouldReturnAvailable() {
57         assertThat(mController.getAvailabilityStatus())
58                 .isEqualTo(BasePreferenceController.AVAILABLE);
59     }
60 
61     @Test
62     @DisableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL)
getAvailabilityStatus_flagsDisabled_shouldReturnUnsupported()63     public void getAvailabilityStatus_flagsDisabled_shouldReturnUnsupported() {
64         assertThat(mController.getAvailabilityStatus())
65                 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
66     }
67 }
68