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;
21 import static org.mockito.Mockito.spy;
23 import android.content.Context;
24 import android.provider.Settings;
26 import com.android.settings.TestConfig;
27 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
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.annotation.Config;
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;
46 MockitoAnnotations.initMocks(this);
48 mContext = RuntimeEnvironment.application;
49 mPolicy = spy(new BatteryTipPolicy(mContext));
50 mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContext.getContentResolver());
54 public void testDetect_smartBatteryOff_tipVisible() {
55 Settings.Global.putInt(mContext.getContentResolver(),
56 Settings.Global.APP_STANDBY_ENABLED, 0);
58 assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
62 public void testDetect_smartBatteryOn_tipInvisible() {
63 Settings.Global.putInt(mContext.getContentResolver(),
64 Settings.Global.APP_STANDBY_ENABLED, 1);
66 assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();