Home | History | Annotate | Download | only in display
      1 /*
      2  * Copyright (C) 2017 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.car.settings.display;
     18 
     19 import android.content.Context;
     20 import android.provider.Settings;
     21 
     22 import org.junit.Before;
     23 import org.junit.Test;
     24 import org.junit.runner.RunWith;
     25 import org.robolectric.RuntimeEnvironment;
     26 import org.robolectric.annotation.Config;
     27 import org.robolectric.Robolectric;
     28 
     29 import static com.google.common.truth.Truth.assertThat;
     30 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
     31 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
     32 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
     33 
     34 import com.android.car.settings.CarSettingsRobolectricTestRunner;
     35 import com.android.car.settings.TestConfig;
     36 
     37 @RunWith(CarSettingsRobolectricTestRunner.class)
     38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     39 public class AutoBrightnessLineItemTest {
     40     private Context mContext;
     41 
     42     private AutoBrightnessLineItem mAutoBrightnessLineItem;
     43 
     44     @Before
     45     public void setUp() {
     46         mContext = RuntimeEnvironment.application;
     47         mAutoBrightnessLineItem = new AutoBrightnessLineItem(mContext);
     48     }
     49 
     50     @Test
     51     public void testIsChecked() {
     52         Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
     53             SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
     54         assertThat(mAutoBrightnessLineItem.isChecked()).isTrue();
     55         Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
     56             SCREEN_BRIGHTNESS_MODE_MANUAL);
     57         assertThat(mAutoBrightnessLineItem.isChecked()).isFalse();
     58     }
     59 
     60     @Test
     61     public void testOnClick() {
     62         mAutoBrightnessLineItem.onClick(false);
     63         assertThat(Settings.System.getInt(mContext.getContentResolver(),
     64             SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL))
     65             .isEqualTo(SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
     66         mAutoBrightnessLineItem.onClick(true);
     67         assertThat(Settings.System.getInt(mContext.getContentResolver(),
     68             SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL))
     69             .isEqualTo(SCREEN_BRIGHTNESS_MODE_MANUAL);
     70     }
     71 }
     72