From 3119f8d4a213baf527d7f1742d28ebbf4a2a5acc Mon Sep 17 00:00:00 2001 From: Raff Tsai Date: Thu, 14 Nov 2019 12:38:04 +0800 Subject: [PATCH] Fix testcase error - Because BatteryFixSlice.updateBatteryTipAvailabilityCache() doesn't run in ShadowThreadUtils shadow function, add a function to override default behavior. Fixes: 144405844 Test: make RunSettingsRoboTests Change-Id: I72ee40a7a8fc524ab7bdc1fd838f8243159f2d21 --- .../slices/BatteryFixSliceTest.java | 3 --- .../testutils/shadow/ShadowThreadUtils.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java index e20305db77e..dcfba42c787 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java @@ -40,7 +40,6 @@ import com.android.settings.slices.SliceBackgroundWorker; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; @@ -82,7 +81,6 @@ public class BatteryFixSliceTest { } @Test - @Ignore public void updateBatteryTipAvailabilityCache_hasImportantTip_shouldReturnTrue() { final List tips = new ArrayList<>(); tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, "")); @@ -108,7 +106,6 @@ public class BatteryFixSliceTest { } @Test - @Ignore @Config(shadows = { BatteryFixSliceTest.ShadowEarlyWarningTip.class, BatteryFixSliceTest.ShadowSliceBackgroundWorker.class diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowThreadUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowThreadUtils.java index 285d88ddb47..61ce13d95b6 100644 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowThreadUtils.java +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowThreadUtils.java @@ -16,16 +16,21 @@ package com.android.settings.testutils.shadow; +import android.util.Log; + import com.android.settingslib.utils.ThreadUtils; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.annotation.Resetter; +import java.util.concurrent.Callable; + @Implements(ThreadUtils.class) public class ShadowThreadUtils { private static boolean sIsMainThread = true; + private static final String TAG = "ShadowThreadUtils"; @Resetter public static void reset() { @@ -37,6 +42,15 @@ public class ShadowThreadUtils { runnable.run(); } + @Implementation + protected static void postOnBackgroundThread(Callable callable) { + try { + callable.call(); + } catch (Exception e) { + Log.e(TAG, e.getMessage(), e); + } + } + @Implementation protected static void postOnMainThread(Runnable runnable) { runnable.run();