OSDN Git Service

Hook up Adaptive Battery to new flag.
[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 import static org.mockito.Mockito.spy;
21
22 import android.content.ContentResolver;
23 import android.content.Context;
24 import android.provider.Settings;
25
26 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
27 import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
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.util.ReflectionHelpers;
36
37 @RunWith(SettingsRobolectricTestRunner.class)
38 public class SmartBatteryDetectorTest {
39
40     private Context mContext;
41     private ContentResolver mContentResolver;
42     private SmartBatteryDetector mSmartBatteryDetector;
43     private BatteryTipPolicy mPolicy;
44
45     @Before
46     public void setUp() {
47         MockitoAnnotations.initMocks(this);
48
49         mContext = RuntimeEnvironment.application;
50         mContentResolver = mContext.getContentResolver();
51         mPolicy = spy(new BatteryTipPolicy(mContext));
52         mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContentResolver);
53     }
54
55     @Test
56     public void testDetect_testFeatureOn_tipNew() {
57         ReflectionHelpers.setField(mPolicy, "testSmartBatteryTip", true);
58
59         assertThat(mSmartBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);
60     }
61
62     @Test
63     public void testDetect_smartBatteryOff_tipVisible() {
64         Settings.Global.putInt(mContentResolver,
65                 Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 0);
66
67         assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
68     }
69
70     @Test
71     public void testDetect_smartBatteryOn_tipInvisible() {
72         Settings.Global.putInt(mContentResolver,
73                 Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 1);
74
75         assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
76     }
77 }