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 package com.android.settings.fuelgauge; 17 18 import static org.mockito.Mockito.doReturn; 19 import static org.mockito.Mockito.verify; 20 21 import android.content.Context; 22 import android.os.BatteryStats; 23 import android.os.Bundle; 24 import android.os.UserManager; 25 26 import com.android.internal.os.BatteryStatsHelper; 27 import com.android.settings.SettingsRobolectricTestRunner; 28 import com.android.settings.TestConfig; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.annotation.Config; 36 37 @RunWith(SettingsRobolectricTestRunner.class) 38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 39 public class BatteryStatsHelperLoaderTest { 40 @Mock 41 private BatteryStatsHelper mBatteryStatsHelper; 42 @Mock 43 private Bundle mBundle; 44 @Mock 45 private Context mContext; 46 @Mock 47 private UserManager mUserManager; 48 private BatteryStatsHelperLoader mLoader; 49 50 @Before setUp()51 public void setUp() { 52 MockitoAnnotations.initMocks(this); 53 54 mLoader = new BatteryStatsHelperLoader(mContext, mBundle); 55 mLoader.mUserManager = mUserManager; 56 } 57 58 @Test testInitBatteryStatsHelper_init()59 public void testInitBatteryStatsHelper_init() { 60 mLoader.initBatteryStatsHelper(mBatteryStatsHelper); 61 62 verify(mBatteryStatsHelper).create(mBundle); 63 verify(mBatteryStatsHelper).refreshStats(BatteryStats.STATS_SINCE_CHARGED, 64 mUserManager.getUserProfiles()); 65 } 66 } 67