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
This commit is contained in:
Raff Tsai
2019-11-14 12:38:04 +08:00
parent b22bbffe90
commit 3119f8d4a2
2 changed files with 14 additions and 3 deletions

View File

@@ -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();