Merge "Never store battery stats for cache" into oc-dr1-dev am: 8f8797f768
am: c150df6f8e
Change-Id: Iea0ac999b8f4dea20e0252b91b3013a5740ce353
This commit is contained in:
@@ -32,7 +32,11 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -52,7 +56,7 @@ public class BatteryBroadcastReceiverTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
|
||||
mBatteryBroadcastReceiver.mBatteryLevel = BATTERY_INIT_LEVEL;
|
||||
@@ -92,4 +96,17 @@ public class BatteryBroadcastReceiverTest {
|
||||
verify(mBatteryListener, never()).onBatteryChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegister_updateBatteryStatus() {
|
||||
doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any());
|
||||
|
||||
mBatteryBroadcastReceiver.register();
|
||||
|
||||
assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(
|
||||
Utils.getBatteryPercentage(mChargingIntent));
|
||||
assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(
|
||||
Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
|
||||
verify(mBatteryListener).onBatteryChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BatteryStatsHelperLoaderTest {
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
|
||||
private Context mContext;
|
||||
private BatteryStatsHelperLoader mBatteryStatsHelperLoader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mConnectivityManager).when(mContext).getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
mBatteryStatsHelperLoader = spy(new BatteryStatsHelperLoader(mContext));
|
||||
mBatteryStatsHelperLoader.mBatteryUtils = mBatteryUtils;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadInBackground_loadWithoutBundle() {
|
||||
doReturn(mContext).when(mBatteryStatsHelperLoader).getContext();
|
||||
mBatteryStatsHelperLoader.loadInBackground();
|
||||
|
||||
verify(mBatteryUtils).initBatteryStatsHelper(any(), eq(null), any());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user