1 /* 2 * Copyright (C) 2023 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; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.os.BatteryManager; 23 24 import androidx.test.core.app.ApplicationProvider; 25 26 import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy; 27 import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; 28 import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.robolectric.RobolectricTestRunner; 34 35 import java.util.ArrayList; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class BatterySettingsFeatureProviderImplTest { 39 private BatterySettingsFeatureProviderImpl mImpl; 40 private Context mContext; 41 42 @Before setUp()43 public void setUp() { 44 mImpl = new BatterySettingsFeatureProviderImpl(); 45 mContext = ApplicationProvider.getApplicationContext(); 46 } 47 48 @Test isManufactureDateAvailable_returnFalse()49 public void isManufactureDateAvailable_returnFalse() { 50 assertThat(mImpl.isManufactureDateAvailable(mContext, 1000L)).isFalse(); 51 } 52 53 @Test isFirstUseDateAvailable_returnFalse()54 public void isFirstUseDateAvailable_returnFalse() { 55 assertThat(mImpl.isFirstUseDateAvailable(mContext, 1000L)).isFalse(); 56 } 57 58 @Test isBatteryInfoEnabled_returnFalse()59 public void isBatteryInfoEnabled_returnFalse() { 60 assertThat(mImpl.isBatteryInfoEnabled(mContext)).isFalse(); 61 } 62 63 @Test addBatteryTipDetector_containsLowBatteryTip()64 public void addBatteryTipDetector_containsLowBatteryTip() { 65 var tips = new ArrayList<BatteryTip>(); 66 67 mImpl.addBatteryTipDetector( 68 mContext, tips, new BatteryInfo(), new BatteryTipPolicy(mContext)); 69 70 var expectedResult = tips.stream().anyMatch(tip -> tip instanceof LowBatteryTip); 71 assertThat(expectedResult).isTrue(); 72 } 73 74 @Test getWirelessChargingLabel_returnNull()75 public void getWirelessChargingLabel_returnNull() { 76 assertThat(mImpl.getWirelessChargingLabel(mContext, new BatteryInfo())).isNull(); 77 } 78 79 @Test getWirelessChargingContentDescription_returnNull()80 public void getWirelessChargingContentDescription_returnNull() { 81 assertThat(mImpl.getWirelessChargingContentDescription(mContext, new BatteryInfo())) 82 .isNull(); 83 } 84 85 @Test getWirelessChargingRemainingLabel_returnNull()86 public void getWirelessChargingRemainingLabel_returnNull() { 87 assertThat(mImpl.getWirelessChargingRemainingLabel(mContext, 1000L, 1000L)).isNull(); 88 } 89 90 @Test isChargingOptimizationMode_default_returnFalse()91 public void isChargingOptimizationMode_default_returnFalse() { 92 assertThat(mImpl.isChargingOptimizationMode(mContext)).isFalse(); 93 } 94 95 @Test getChargingOptimizationRemainingLabel_default_returnNull()96 public void getChargingOptimizationRemainingLabel_default_returnNull() { 97 assertThat( 98 mImpl.getChargingOptimizationRemainingLabel( 99 mContext, 75, BatteryManager.BATTERY_PLUGGED_AC, 1000L, 1000L)) 100 .isNull(); 101 } 102 103 @Test getChargingOptimizationChargeLabel_default_returnNull()104 public void getChargingOptimizationChargeLabel_default_returnNull() { 105 assertThat(mImpl.getChargingOptimizationChargeLabel(mContext, 70, "70%", 1000L, 1000L)) 106 .isNull(); 107 } 108 } 109