2 * Copyright (C) 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.fuelgauge.batterytip.detectors;
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.spy;
22 import android.content.ContentResolver;
23 import android.content.Context;
24 import android.provider.Settings;
26 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
27 import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
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;
37 @RunWith(SettingsRobolectricTestRunner.class)
38 public class SmartBatteryDetectorTest {
40 private Context mContext;
41 private ContentResolver mContentResolver;
42 private SmartBatteryDetector mSmartBatteryDetector;
43 private BatteryTipPolicy mPolicy;
47 MockitoAnnotations.initMocks(this);
49 mContext = RuntimeEnvironment.application;
50 mContentResolver = mContext.getContentResolver();
51 mPolicy = spy(new BatteryTipPolicy(mContext));
52 mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContentResolver);
56 public void testDetect_testFeatureOn_tipNew() {
57 ReflectionHelpers.setField(mPolicy, "testSmartBatteryTip", true);
59 assertThat(mSmartBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);
63 public void testDetect_smartBatteryOff_tipVisible() {
64 Settings.Global.putInt(mContentResolver,
65 Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 0);
67 assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
71 public void testDetect_smartBatteryOn_tipInvisible() {
72 Settings.Global.putInt(mContentResolver,
73 Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 1);
75 assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();