OSDN Git Service

Merge "Updated the Bluetooth Settings owners list" am: 5a56c31913 am: b1230be1b8
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / fuelgauge / batterytip / detectors / SmartBatteryDetectorTest.java
1 /*
2  * Copyright (C) 2018 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.fuelgauge.batterytip.detectors;
18
19 import static com.google.common.truth.Truth.assertThat;
20
21 import static org.mockito.Mockito.spy;
22
23 import android.content.Context;
24 import android.provider.Settings;
25
26 import com.android.settings.TestConfig;
27 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.RuntimeEnvironment;
35 import org.robolectric.annotation.Config;
36
37 @RunWith(SettingsRobolectricTestRunner.class)
38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
39 public class SmartBatteryDetectorTest {
40     private Context mContext;
41     private BatteryTipPolicy mPolicy;
42     private SmartBatteryDetector mSmartBatteryDetector;
43
44     @Before
45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47
48         mContext = RuntimeEnvironment.application;
49         mPolicy = spy(new BatteryTipPolicy(mContext));
50         mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContext.getContentResolver());
51     }
52
53     @Test
54     public void testDetect_smartBatteryOff_tipVisible() {
55         Settings.Global.putInt(mContext.getContentResolver(),
56                 Settings.Global.APP_STANDBY_ENABLED, 0);
57
58         assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
59     }
60
61     @Test
62     public void testDetect_smartBatteryOn_tipInvisible() {
63         Settings.Global.putInt(mContext.getContentResolver(),
64                 Settings.Global.APP_STANDBY_ENABLED, 1);
65
66         assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
67     }
68 }