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

Commit 20812b93 authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Work around Mockito mocking all static methods" into main

parents d68ec619 40e1fa45
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@ public class SystemServicesTestRule implements TestRule {
    private void setUpSystemCore() {
        doReturn(mock(Watchdog.class)).when(Watchdog::getInstance);
        doAnswer(invocation -> {
            if ("addOnPropertiesChangedListener".equals(invocation.getMethod().getName())) {
                // Exclude CONSTRAIN_DISPLAY_APIS because ActivityRecord#sConstrainDisplayApisConfig
                // only registers once and it doesn't reference to outside.
                if (!NAMESPACE_CONSTRAIN_DISPLAY_APIS.equals(invocation.getArgument(0))) {
@@ -215,8 +216,10 @@ public class SystemServicesTestRule implements TestRule {
                }
                // SizeCompatTests uses setNeverConstrainDisplayApisFlag, and ActivityRecordTests
                // uses splash_screen_exception_list. So still execute real registration.
            }
            return invocation.callRealMethod();
        }).when(() -> DeviceConfig.addOnPropertiesChangedListener(anyString(), any(), any()));
        }).when(() -> DeviceConfig.addOnPropertiesChangedListener(
                anyString(), any(), any(DeviceConfig.OnPropertiesChangedListener.class)));

        mContext = getInstrumentation().getTargetContext();
        spyOn(mContext);
@@ -397,6 +400,7 @@ public class SystemServicesTestRule implements TestRule {
    }

    private void tearDown() {
        if (mWmService != null) {
            for (int i = mWmService.mRoot.getChildCount() - 1; i >= 0; i--) {
                final DisplayContent dc = mWmService.mRoot.getChildAt(i);
                // Unregister SettingsObserver.
@@ -407,10 +411,13 @@ public class SystemServicesTestRule implements TestRule {
                    dc.mDisplayRotationCompatPolicy.dispose();
                }
            }
        }

        if (mAtmService != null) {
            // Unregister display listener from root to avoid issues with subsequent tests.
            mContext.getSystemService(DisplayManager.class)
                    .unregisterDisplayListener(mAtmService.mRootWindowContainer);
        }

        for (int i = mDeviceConfigListeners.size() - 1; i >= 0; i--) {
            DeviceConfig.removeOnPropertiesChangedListener(mDeviceConfigListeners.get(i));