Verify `android.test.mock` under Ravenwood.
Even though developers are encouraged to use Mockito, existing tests
may still be using this old library for their mocking.
We'll circle back later to consider support for components such as
ContentProvider, Service, etc.
Clean up OWNERS.
Bug: 310268946
Test: atest android.test.mock.ravenwood.tests
Change-Id: Ie3f4ccea9cf6719d61cff277a627825868edc992
diff --git a/Ravenwood.bp b/Ravenwood.bp
index ca73378..df9ac82 100644
--- a/Ravenwood.bp
+++ b/Ravenwood.bp
@@ -80,7 +80,7 @@
"junit",
"truth",
"ravenwood-junit-impl",
- "android.test.mock",
+ "android.test.mock.ravenwood",
],
}
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index 4327c7a..0a8029c 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -71,6 +71,7 @@
* another Context. Can be subclassed to modify behavior without changing
* the original Context.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class ContextWrapper extends Context {
@UnsupportedAppUsage
Context mBase;
@@ -1430,6 +1431,7 @@
* @throws IllegalStateException if this method calls before {@link #attachBaseContext(Context)}
*/
@Override
+ @android.ravenwood.annotation.RavenwoodThrow
public void registerComponentCallbacks(ComponentCallbacks callback) {
if (mBase != null) {
mBase.registerComponentCallbacks(callback);
@@ -1464,6 +1466,7 @@
* @throws IllegalStateException if this method calls before {@link #attachBaseContext(Context)}
*/
@Override
+ @android.ravenwood.annotation.RavenwoodThrow
public void unregisterComponentCallbacks(ComponentCallbacks callback) {
// It usually means the ComponentCallbacks is registered before this ContextWrapper attaches
// to a base Context and Application is targeting prior to S-v2. We should unregister the
diff --git a/ravenwood/OWNERS b/ravenwood/OWNERS
index c06b3b9..41fd68e 100644
--- a/ravenwood/OWNERS
+++ b/ravenwood/OWNERS
@@ -1,3 +1,5 @@
+set noparent
+
jsharkey@google.com
omakoto@google.com
jaggies@google.com
diff --git a/ravenwood/framework-minus-apex-ravenwood-policies.txt b/ravenwood/framework-minus-apex-ravenwood-policies.txt
index 79bfa44..96cfa48 100644
--- a/ravenwood/framework-minus-apex-ravenwood-policies.txt
+++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt
@@ -134,6 +134,8 @@
class android.net.Uri stubclass
class android.net.UriCodec stubclass
-# Context: just enough to support wrapper, no further functionality
+# Just enough to support mocking, no further functionality
class android.content.Context stub
method <init> ()V stub
+class android.content.pm.PackageManager stub
+ method <init> ()V stub
diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt
index 07c2cd7c..e294733 100644
--- a/ravenwood/ravenwood-annotation-allowed-classes.txt
+++ b/ravenwood/ravenwood-annotation-allowed-classes.txt
@@ -30,6 +30,7 @@
android.content.ComponentName
android.content.ContentUris
android.content.ContentValues
+android.content.ContextWrapper
android.content.Intent
android.content.IntentFilter
android.content.UriMatcher
diff --git a/test-mock/Android.bp b/test-mock/Android.bp
index 22320fd..2ff7413 100644
--- a/test-mock/Android.bp
+++ b/test-mock/Android.bp
@@ -54,6 +54,29 @@
dist_group: "android",
}
+java_library {
+ name: "android.test.mock.ravenwood",
+ srcs: [":android-test-mock-sources"],
+ visibility: [
+ "//frameworks/base",
+ ],
+}
+
+android_ravenwood_test {
+ name: "android.test.mock.ravenwood.tests",
+ libs: [
+ "android.test.mock.ravenwood",
+ ],
+ static_libs: [
+ "androidx.annotation_annotation",
+ "androidx.test.rules",
+ ],
+ srcs: [
+ "tests/**/*.java",
+ ],
+ auto_gen_config: true,
+}
+
// Make the current.txt available for use by the cts/tests/signature tests.
// ========================================================================
filegroup {
diff --git a/test-mock/tests/src/android/test/mock/MockContextTest.java b/test-mock/tests/src/android/test/mock/MockContextTest.java
new file mode 100644
index 0000000..6e28267
--- /dev/null
+++ b/test-mock/tests/src/android/test/mock/MockContextTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test.mock;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class MockContextTest {
+ @Test
+ public void testConstructor() {
+ new MockContext();
+ }
+}
diff --git a/test-mock/tests/src/android/test/mock/MockPackageManagerTest.java b/test-mock/tests/src/android/test/mock/MockPackageManagerTest.java
new file mode 100644
index 0000000..5b860f1
--- /dev/null
+++ b/test-mock/tests/src/android/test/mock/MockPackageManagerTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test.mock;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class MockPackageManagerTest {
+ @Test
+ public void testConstructor() {
+ new MockPackageManager();
+ }
+}