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

Commit 5a78970b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[Ravenwood] Add runtime Mockito version check" into main am: 8eee2da7

parents bc43c77e 8eee2da7
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,8 @@ import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_RESOUR
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERBOSE_LOGGING;
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERBOSE_LOGGING;
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERSION_JAVA_SYSPROP;
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERSION_JAVA_SYSPROP;


import static org.junit.Assert.assertThrows;

import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.Instrumentation;
import android.app.ResourcesManager;
import android.app.ResourcesManager;
@@ -167,6 +169,8 @@ public class RavenwoodRuntimeEnvironmentController {
        // This will let AndroidJUnit4 use the original runner.
        // This will let AndroidJUnit4 use the original runner.
        System.setProperty("android.junit.runner",
        System.setProperty("android.junit.runner",
                "androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner");
                "androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner");

        assertMockitoVersion();
    }
    }


    /**
    /**
@@ -381,6 +385,28 @@ public class RavenwoodRuntimeEnvironmentController {
        }
        }
    }
    }


    private static final String MOCKITO_ERROR = "FATAL: Unsupported Mockito detected!"
            + " Your test or its dependencies use one of the \"mockito-target-*\""
            + " modules as static library, which is unusable on host side."
            + " Please switch over to use \"mockito-ravenwood-prebuilt\" as shared library, or"
            + " as a last resort, set `ravenizer: { strip_mockito: true }` in your test module.";

    /**
     * Assert the Mockito version at runtime to ensure no incorrect Mockito classes are loaded.
     */
    private static void assertMockitoVersion() {
        // DexMaker should not exist
        assertThrows(
                MOCKITO_ERROR,
                ClassNotFoundException.class,
                () -> Class.forName("com.android.dx.DexMaker"));
        // Mockito 2 should not exist
        assertThrows(
                MOCKITO_ERROR,
                ClassNotFoundException.class,
                () -> Class.forName("org.mockito.Matchers"));
    }

    @SuppressWarnings("unused")  // Called from native code (ravenwood_sysprop.cpp)
    @SuppressWarnings("unused")  // Called from native code (ravenwood_sysprop.cpp)
    private static void checkSystemPropertyAccess(String key, boolean write) {
    private static void checkSystemPropertyAccess(String key, boolean write) {
        boolean result = write ? sProps.isKeyWritable(key) : sProps.isKeyReadable(key);
        boolean result = write ? sProps.isKeyWritable(key) : sProps.isKeyReadable(key);