summaryrefslogtreecommitdiff
path: root/ravenwood/junit-impl-src
diff options
context:
space:
mode:
author John Wu <topjohnwu@google.com> 2024-10-04 00:43:21 +0000
committer John Wu <topjohnwu@google.com> 2024-10-04 07:56:21 +0000
commit3257839d747c76a35472016fe4f81ef9d5cf1ad0 (patch)
tree89ee770aeb4f9c31d4562b678ef42c9bc4d9e121 /ravenwood/junit-impl-src
parent75816497097b3597d685caf148d02ae6c00c69c4 (diff)
[Ravenwood] Add runtime Mockito version check
To prevent future Ravenwood tests from using an incorrect Mockito version, add this new runtime environment check. Bug: 292141694 Flag: EXEMPT host test change only Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Change-Id: I52303e744465c26721baaba85aded907af2a06eb
Diffstat (limited to 'ravenwood/junit-impl-src')
-rw-r--r--ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java26
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);