OSDN Git Service

Disable lowBatteryTip and ReducedBatteryTip
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / fuelgauge / batterytip / detectors / LowBatteryDetectorTest.java
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.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.text.format.DateUtils;
25
26 import com.android.settings.TestConfig;
27 import com.android.settings.fuelgauge.BatteryInfo;
28 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RuntimeEnvironment;
37 import org.robolectric.annotation.Config;
38 import org.robolectric.util.ReflectionHelpers;
39
40 @RunWith(SettingsRobolectricTestRunner.class)
41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
42 public class LowBatteryDetectorTest {
43     private Context mContext;
44     @Mock
45     private BatteryInfo mBatteryInfo;
46     private BatteryTipPolicy mPolicy;
47     private LowBatteryDetector mLowBatteryDetector;
48
49     @Before
50     public void setUp() {
51         MockitoAnnotations.initMocks(this);
52
53         mContext = RuntimeEnvironment.application;
54         mPolicy = spy(new BatteryTipPolicy(mContext));
55         ReflectionHelpers.setField(mPolicy, "lowBatteryEnabled", true);
56
57         mLowBatteryDetector = new LowBatteryDetector(mPolicy, mBatteryInfo);
58     }
59
60     @Test
61     public void testDetect_disabledByPolicy_tipInvisible() {
62         ReflectionHelpers.setField(mPolicy, "lowBatteryEnabled", false);
63
64         assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
65     }
66
67     @Test
68     public void testDetect_shortBatteryLife_tipVisible() {
69         mBatteryInfo.discharging = true;
70         mBatteryInfo.remainingTimeUs = 1 * DateUtils.MINUTE_IN_MILLIS;
71
72         assertThat(mLowBatteryDetector.detect().isVisible()).isTrue();
73     }
74
75     @Test
76     public void testDetect_longBatteryLife_tipInvisible() {
77         mBatteryInfo.discharging = true;
78         mBatteryInfo.remainingTimeUs = 1 * DateUtils.DAY_IN_MILLIS;
79
80         assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
81     }
82 }