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

Commit 94a3a0be authored by Harshad Dhabu's avatar Harshad Dhabu Committed by Android (Google) Code Review
Browse files

Merge "Add new unit tests for battery_saver_supported_check_api flag" into main

parents ec4ba182 7407ed52
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -19,11 +19,17 @@ package android.os;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.Flags;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.test.AndroidTestCase;

import androidx.test.InstrumentationRegistry;
@@ -31,6 +37,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.uiautomator.UiDevice;

import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -64,6 +71,10 @@ public class PowerManagerTest extends AndroidTestCase {
        System.loadLibrary("powermanagertest_jni");
    }

    // Required for RequiresFlagsEnabled and RequiresFlagsDisabled annotations to take effect.
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    /**
     * Setup any common data for the upcoming tests.
     */
@@ -454,4 +465,27 @@ public class PowerManagerTest extends AndroidTestCase {
        parcelBatterySaverPolicyConfigToNativeAndVerify(bs2);
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_BATTERY_SAVER_SUPPORTED_CHECK_API)
    public void testBatterySaverSupported_isSupported() throws RemoteException {
        IPowerManager powerManager = mock(IPowerManager.class);
        PowerManager pm = new PowerManager(mContext, powerManager,
                mock(IThermalService.class),
                Handler.createAsync(Looper.getMainLooper()));
        when(powerManager.isBatterySaverSupported()).thenReturn(true);

        assertTrue(pm.isBatterySaverSupported());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_BATTERY_SAVER_SUPPORTED_CHECK_API)
    public void testBatterySaverSupported_isNotSupported() throws RemoteException {
        IPowerManager powerManager = mock(IPowerManager.class);
        PowerManager pm = new PowerManager(mContext, powerManager,
                mock(IThermalService.class),
                Handler.createAsync(Looper.getMainLooper()));
        when(powerManager.isBatterySaverSupported()).thenReturn(false);

        assertFalse(pm.isBatterySaverSupported());
    }
}