Skip test if battery is not present
The battery stats won't be updated if the device has no battery
which causes the test failed. Thus the test should be skipped
if the device has no battery.
Bug: 245075045
Test: Build
Change-Id: I0ae1e030c7e178ced91c94a8bc65a1d279ba37b3
diff --git a/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java b/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java
index 6b2a1ee..e2821cb 100644
--- a/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java
@@ -21,12 +21,14 @@
import static androidx.test.InstrumentationRegistry.getContext;
+import static com.android.compatibility.common.util.BatteryUtils.hasBattery;
import static com.android.compatibility.common.util.SystemUtil.runShellCommand;
import static com.android.testutils.MiscAsserts.assertThrows;
import static com.android.testutils.TestPermissionUtil.runAsShell;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -97,6 +99,7 @@
@RequiresDevice // Virtual hardware does not support wifi battery stats
public void testReportNetworkInterfaceForTransports() throws Exception {
try {
+ assumeTrue("Battery is not present. Ignore test.", hasBattery());
// Simulate the device being unplugged from charging.
executeShellCommand("cmd battery unplug");
executeShellCommand("cmd battery set status " + BATTERY_STATUS_DISCHARGING);