diff options
Diffstat (limited to 'ravenwood/junit-impl-src')
-rw-r--r-- | ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java index 805b0c161cb3..4ae5bd1f7b71 100644 --- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java @@ -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_VERSION_JAVA_SYSPROP; +import static org.junit.Assert.assertThrows; + import android.app.ActivityManager; import android.app.Instrumentation; import android.app.ResourcesManager; @@ -167,6 +169,8 @@ public class RavenwoodRuntimeEnvironmentController { // This will let AndroidJUnit4 use the original runner. System.setProperty("android.junit.runner", "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) private static void checkSystemPropertyAccess(String key, boolean write) { boolean result = write ? sProps.isKeyWritable(key) : sProps.isKeyReadable(key); |