Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38e025f6 authored by Raff Tsai's avatar Raff Tsai Committed by Android (Google) Code Review
Browse files

Merge "Fix robolectric error"

parents fd6309af 4950d4cb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -201,7 +201,8 @@ public class BatteryFixSlice implements CustomSliceable {
    }

    @WorkerThread
    private static List<BatteryTip> refreshBatteryTips(Context context) {
    @VisibleForTesting
    static List<BatteryTip> refreshBatteryTips(Context context) {
        final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
        final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
        final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
+4 −4
Original line number Diff line number Diff line
@@ -81,13 +81,13 @@ public class BatteryFixSliceTest {
    }

    @Test
    public void updateBatteryTipAvailabilityCache_hasImportantTip_shouldReturnTrue() {
    public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() {
        final List<BatteryTip> tips = new ArrayList<>();
        tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
        tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
        ShadowBatteryTipLoader.setBatteryTips(tips);

        BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
        BatteryFixSlice.refreshBatteryTips(mContext);

        assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue();
    }
@@ -99,7 +99,7 @@ public class BatteryFixSliceTest {
        tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
        ShadowBatteryTipLoader.setBatteryTips(tips);

        BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
        BatteryFixSlice.refreshBatteryTips(mContext);
        final Slice slice = mSlice.getSlice();

        assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
@@ -115,7 +115,7 @@ public class BatteryFixSliceTest {
        tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
        // Create fake cache data
        ShadowBatteryTipLoader.setBatteryTips(tips);
        BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
        BatteryFixSlice.refreshBatteryTips(mContext);
        // Create fake background worker data
        BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(
                BatteryFixSlice.BatteryTipWorker.class);
+0 −13
Original line number Diff line number Diff line
@@ -16,16 +16,12 @@

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 {

@@ -42,15 +38,6 @@ 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();