summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@google.com> 2023-11-29 12:17:43 -0700
committer Jeff Sharkey <jsharkey@google.com> 2023-11-29 12:17:47 -0700
commitde3447105cdc56c6d84b690567c2a30f134c3284 (patch)
treec20495c83a5d4cccb1001e4d328ca062d2e70c65
parent3c941e1af17f1ab705bd4c328d7174c4903a398f (diff)
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
-rw-r--r--Ravenwood.bp2
-rw-r--r--core/java/android/content/ContextWrapper.java3
-rw-r--r--ravenwood/OWNERS2
-rw-r--r--ravenwood/framework-minus-apex-ravenwood-policies.txt4
-rw-r--r--ravenwood/ravenwood-annotation-allowed-classes.txt1
-rw-r--r--test-mock/Android.bp23
-rw-r--r--test-mock/tests/src/android/test/mock/MockContextTest.java30
-rw-r--r--test-mock/tests/src/android/test/mock/MockPackageManagerTest.java30
8 files changed, 93 insertions, 2 deletions
diff --git a/Ravenwood.bp b/Ravenwood.bp
index ca73378c8e81..df9ac82ca263 100644
--- a/Ravenwood.bp
+++ b/Ravenwood.bp
@@ -80,7 +80,7 @@ android_ravenwood_libgroup {
"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 4327c7acf0f0..0a8029c44d73 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -71,6 +71,7 @@ import java.util.function.IntConsumer;
* 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 @@ public class ContextWrapper extends Context {
* @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 @@ public class ContextWrapper extends Context {
* @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 c06b3b9c2d11..41fd68e6c2d9 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 79bfa443b330..96cfa4896808 100644
--- a/ravenwood/framework-minus-apex-ravenwood-policies.txt
+++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt
@@ -134,6 +134,8 @@ class com.android.modules.utils.TypedXmlSerializer stubclass
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 07c2cd7c26b3..e29473373440 100644
--- a/ravenwood/ravenwood-annotation-allowed-classes.txt
+++ b/ravenwood/ravenwood-annotation-allowed-classes.txt
@@ -30,6 +30,7 @@ android.content.ClipDescription
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 22320fd53631..2ff74132ffbb 100644
--- a/test-mock/Android.bp
+++ b/test-mock/Android.bp
@@ -54,6 +54,29 @@ java_sdk_library {
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 000000000000..6e28267de46d
--- /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 000000000000..5b860f169193
--- /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();
+ }
+}