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

Commit 4950d4cb authored by Raff Tsai's avatar Raff Tsai
Browse files

Fix robolectric error

Fixes: 144551238
Fixes: 144551930
Test: Robolectric
Change-Id: I33851ae2c4a06495f73e8db5d4df0992df5e7f3e
parent 9096329b
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();