Update battery tips cards test.
Test: manual
Bug: 291689623
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:71c4b617ccbf15200816b59d037991bcb1f4adcd)
Change-Id: Ifd429e10b09fb2e740b644131c6fdedce574aaa5
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
index 09b0c24..91fe59c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
@@ -36,11 +36,12 @@
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
- private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
private final String[] mPowerAnomalyKeys;
@VisibleForTesting
BatteryTipsCardPreference mCardPreference;
+ @VisibleForTesting
+ PowerUsageFeatureProvider mPowerUsageFeatureProvider;
public BatteryTipsController(Context context) {
super(context, ROOT_PREFERENCE_KEY);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreferenceTest.java
index cebfa1b..bc787f1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreferenceTest.java
@@ -19,20 +19,14 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import android.content.Context;
-import android.content.Intent;
-import android.view.View;
import com.android.settings.R;
-import com.android.settings.testutils.BatteryTestUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -42,8 +36,6 @@
private Context mContext;
private BatteryTipsCardPreference mBatteryTipsCardPreference;
private BatteryTipsController mBatteryTipsController;
- @Mock
- private View mMockButton;
@Before
public void setUp() {
@@ -51,7 +43,6 @@
mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /*attrs=*/ null);
mBatteryTipsController = new BatteryTipsController(mContext);
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
- mMockButton.setId(R.id.action_button);
}
@Test
@@ -59,16 +50,4 @@
assertThat(mBatteryTipsCardPreference.getLayoutResource()).isEqualTo(
R.layout.battery_tips_card);
}
-
- @Test
- public void onClick_actionBtn_getAdaptiveBrightnessLauncher() {
- final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
- PowerAnomalyEvent adaptiveBrightnessAnomaly =
- BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
-
- mBatteryTipsController.handleBatteryTipsCardUpdated(adaptiveBrightnessAnomaly);
- mBatteryTipsCardPreference.onClick(mMockButton);
-
- verify(mContext).startActivity(captor.capture());
- }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsControllerTest.java
index 5e42855..0c9a0b0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsControllerTest.java
@@ -21,11 +21,13 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.os.LocaleList;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.BatteryTestUtils;
import org.junit.Before;
@@ -48,6 +50,9 @@
@Mock
private BatteryTipsCardPreference mBatteryTipsCardPreference;
+ @Mock
+ private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -60,6 +65,7 @@
doReturn(resources).when(mContext).getResources();
mBatteryTipsController = new BatteryTipsController(mContext);
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
+ mBatteryTipsController.mPowerUsageFeatureProvider = mPowerUsageFeatureProvider;
}
@Test
@@ -87,16 +93,15 @@
@Test
public void handleBatteryTipsCardUpdated_adaptiveBrightnessAnomaly_showAnomaly() {
PowerAnomalyEvent event = BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
+ when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
// Check pre-defined string
verify(mBatteryTipsCardPreference).setTitle(
"Turn on adaptive brightness to extend battery life");
- verify(mBatteryTipsCardPreference).setMainButtonLabel(
- "View Settings");
- verify(mBatteryTipsCardPreference).setDismissButtonLabel(
- "Got it");
+ verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
+ verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
// Check proto info
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
"com.android.settings.display.AutoBrightnessSettings",
@@ -107,15 +112,13 @@
@Test
public void handleBatteryTipsCardUpdated_screenTimeoutAnomaly_showAnomaly() {
PowerAnomalyEvent event = BatteryTestUtils.createScreenTimeoutAnomalyEvent();
+ when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
- verify(mBatteryTipsCardPreference).setTitle(
- "Reduce screen timeout to extend battery life");
- verify(mBatteryTipsCardPreference).setMainButtonLabel(
- "View Settings");
- verify(mBatteryTipsCardPreference).setDismissButtonLabel(
- "Got it");
+ verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life");
+ verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
+ verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
"com.android.settings.display.ScreenTimeoutSettings",
1852);
@@ -131,15 +134,13 @@
.setTitleString(testTitle)
.build())
.build();
+ when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
- verify(mBatteryTipsCardPreference).setTitle(
- testTitle);
- verify(mBatteryTipsCardPreference).setMainButtonLabel(
- "View Settings");
- verify(mBatteryTipsCardPreference).setDismissButtonLabel(
- "Got it");
+ verify(mBatteryTipsCardPreference).setTitle(testTitle);
+ verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
+ verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
"com.android.settings.display.ScreenTimeoutSettings",
1852);