Merge "Fix robolectric error"

This commit is contained in:
Raff Tsai
2019-11-18 05:05:37 +00:00
committed by Android (Google) Code Review
3 changed files with 6 additions and 18 deletions

View File

@@ -201,7 +201,8 @@ public class BatteryFixSlice implements CustomSliceable {
} }
@WorkerThread @WorkerThread
private static List<BatteryTip> refreshBatteryTips(Context context) { @VisibleForTesting
static List<BatteryTip> refreshBatteryTips(Context context) {
final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context); final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
final BatteryStatsHelper statsHelper = statsLoader.loadInBackground(); final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper); final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);

View File

@@ -81,13 +81,13 @@ public class BatteryFixSliceTest {
} }
@Test @Test
public void updateBatteryTipAvailabilityCache_hasImportantTip_shouldReturnTrue() { public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() {
final List<BatteryTip> tips = new ArrayList<>(); final List<BatteryTip> tips = new ArrayList<>();
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, "")); tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
ShadowBatteryTipLoader.setBatteryTips(tips); ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext); BatteryFixSlice.refreshBatteryTips(mContext);
assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue(); assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue();
} }
@@ -99,7 +99,7 @@ public class BatteryFixSliceTest {
tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false)); tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
ShadowBatteryTipLoader.setBatteryTips(tips); ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext); BatteryFixSlice.refreshBatteryTips(mContext);
final Slice slice = mSlice.getSlice(); final Slice slice = mSlice.getSlice();
assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue(); assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
@@ -115,7 +115,7 @@ public class BatteryFixSliceTest {
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
// Create fake cache data // Create fake cache data
ShadowBatteryTipLoader.setBatteryTips(tips); ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext); BatteryFixSlice.refreshBatteryTips(mContext);
// Create fake background worker data // Create fake background worker data
BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock( BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(
BatteryFixSlice.BatteryTipWorker.class); BatteryFixSlice.BatteryTipWorker.class);

View File

@@ -16,16 +16,12 @@
package com.android.settings.testutils.shadow; package com.android.settings.testutils.shadow;
import android.util.Log;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter; import org.robolectric.annotation.Resetter;
import java.util.concurrent.Callable;
@Implements(ThreadUtils.class) @Implements(ThreadUtils.class)
public class ShadowThreadUtils { public class ShadowThreadUtils {
@@ -42,15 +38,6 @@ public class ShadowThreadUtils {
runnable.run(); runnable.run();
} }
@Implementation
protected static void postOnBackgroundThread(Callable callable) {
try {
callable.call();
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
@Implementation @Implementation
protected static void postOnMainThread(Runnable runnable) { protected static void postOnMainThread(Runnable runnable) {
runnable.run(); runnable.run();