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
17package com.android.car.settings.display;
18
19import android.content.Context;
20import android.provider.Settings;
21
22import com.android.car.settings.CarSettingsRobolectricTestRunner;
23import com.android.car.settings.TestConfig;
24
25import org.junit.Before;
26import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.robolectric.RuntimeEnvironment;
29import org.robolectric.annotation.Config;
30import org.robolectric.Robolectric;
31
32import static com.google.common.truth.Truth.assertThat;
33import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
34
35@RunWith(CarSettingsRobolectricTestRunner.class)
36@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
37public class BrightnessLineItemTest {
38    private Context mContext;
39
40    private BrightnessLineItem mBrightnessLineItem;
41
42    @Before
43    public void setUp() {
44        mContext = RuntimeEnvironment.application;
45        mBrightnessLineItem = new BrightnessLineItem(mContext);
46    }
47
48    @Test
49    public void testInitialValue() throws Exception {
50        // for some reason in robolectric test, I can't set this value over 100
51        for (int brightness = 0; brightness < 100; ++brightness) {
52            Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS, brightness);
53            assertThat(mBrightnessLineItem.getSeekbarValue()).isEqualTo(brightness);
54        }
55    }
56
57    @Test
58    public void testOnSeekbarChanged() throws Exception {
59        for (int brightness = 0; brightness < 255; ++brightness) {
60            mBrightnessLineItem.onSeekbarChanged(brightness);
61            assertThat(Settings.System.getInt(mContext.getContentResolver(),
62                    SCREEN_BRIGHTNESS)).isEqualTo(brightness);
63        }
64    }
65}
66