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

Commit 04c486e3 authored by Steven Ng's avatar Steven Ng
Browse files

Mock isDeviceEligibleForDesktopMode in WallpaperManagerServiceTests

Improve the robustness of WallpaperManagerServiceTests by mocking DesktopModeHelper#isDeviceEligibleForDesktopMode,
preventing implementation changes in that method from causing test failures.

Test: atests FrameworksMockingServicesTests:WallpaperManagerServiceTests
Flag: EXEMPTED: tests only change
Bug: 397611386
Change-Id: I3ba574ed5fa7d93de171946372382a6d86d4aa00
parent d1406116
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public final class DesktopModeHelper {
    }

    @VisibleForTesting
    static boolean isDeviceEligibleForDesktopMode(@NonNull Context context) {
    public static boolean isDeviceEligibleForDesktopMode(@NonNull Context context) {
        if (!shouldEnforceDeviceRestrictions()) {
            return true;
        }
+4 −7
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.graphics.Color;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
@@ -95,6 +94,7 @@ import com.android.internal.R;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.LocalServices;
import com.android.server.wm.DesktopModeHelper;
import com.android.server.wm.WindowManagerInternal;

import org.hamcrest.CoreMatchers;
@@ -154,8 +154,6 @@ public class WallpaperManagerServiceTests {

    private IPackageManager mIpm = AppGlobals.getPackageManager();

    private Resources mResources = sContext.getResources();

    @Mock
    private DisplayManager mDisplayManager;

@@ -177,6 +175,7 @@ public class WallpaperManagerServiceTests {
                .spyStatic(WallpaperUtils.class)
                .spyStatic(LocalServices.class)
                .spyStatic(WallpaperManager.class)
                .spyStatic(DesktopModeHelper.class)
                .startMocking();

        sWindowManagerInternal = mock(WindowManagerInternal.class);
@@ -245,6 +244,8 @@ public class WallpaperManagerServiceTests {
            int userId = (invocation.getArgument(0));
            return getWallpaperTestDir(userId);
        }).when(() -> WallpaperUtils.getWallpaperDir(anyInt()));
        ExtendedMockito.doAnswer(invocation -> true).when(
                () -> DesktopModeHelper.isDeviceEligibleForDesktopMode(any()));

        sContext.addMockSystemService(DisplayManager.class, mDisplayManager);

@@ -256,10 +257,6 @@ public class WallpaperManagerServiceTests {
        doReturn(displays).when(mDisplayManager).getDisplays();

        spyOn(mIpm);
        spyOn(mResources);
        doReturn(true).when(mResources).getBoolean(eq(R.bool.config_isDesktopModeSupported));
        doReturn(true).when(mResources).getBoolean(
                eq(R.bool.config_canInternalDisplayHostDesktops));
        mService = new TestWallpaperManagerService(sContext);
        spyOn(mService);
        mService.systemReady();