From 3e68053d37d71e99cc0d416e2bdc85861ef6defe Mon Sep 17 00:00:00 2001
From: Jeff Sharkey <jsharkey@google.com>
Date: Tue, 5 Dec 2023 16:17:33 -0700
Subject: [PATCH] Support more utils under Ravenwood.

Tests for these internal utils are local within the frameworks/base/
repo, instead of in CTS.

To help future-proof, bring the entire utils/* test directory by
default into the Ravenwood suites, and give developers the way to
easily opt-out with @IgnoreUnderRavenwood at the class level.

Bug: 292141694
Test: atest FrameworksCoreTestsRavenwood FrameworksCoreTests
Test: atest FrameworksUtilTestsRavenwood FrameworksUtilTests
Change-Id: Ibcabec764efa31cc8cb4c56d7815948d4029aaea
---
 core/java/android/util/DayOfMonthCursor.java  |   1 +
 .../java/android/util/KeyValueListParser.java |   1 +
 core/java/android/util/LongArrayQueue.java    |   1 +
 .../android/util/LongSparseLongArray.java     |   1 +
 .../java/android/util/MonthDisplayHelper.java |   1 +
 core/java/android/util/RecurrenceRule.java    |   1 +
 core/java/android/util/RotationUtils.java     |   1 +
 core/java/android/util/SparseDoubleArray.java |   1 +
 core/java/android/util/SparseSetArray.java    |   1 +
 core/java/android/util/StateSet.java          |   1 -
 core/java/android/util/Xml.java               |   2 +
 core/tests/coretests/Android.bp               |   9 ++
 .../src/android/util/ArrayMapTest.java        |  17 ++-
 .../src/android/util/ArraySetTest.java        |   9 +-
 .../src/android/util/Base64Test.java          | 111 +++++++++-------
 .../src/android/util/CharsetUtilsTest.java    |  14 +-
 .../src/android/util/CloseGuardTest.java      |  16 ++-
 .../android/util/DayOfMonthCursorTest.java    |  31 +++--
 .../android/util/HashedStringCacheTest.java   |  17 ++-
 .../src/android/util/LogNullabilityTest.java  |  54 ++++----
 .../coretests/src/android/util/LogTest.java   |  22 ++--
 .../android/util/LongSparseLongArrayTest.java |  13 +-
 .../src/android/util/LruCacheTest.java        |  39 +++++-
 .../android/util/MonthDisplayHelperTest.java  |  23 +++-
 .../src/android/util/NtpTrustedTimeTest.java  |   8 ++
 .../src/android/util/PatternsTest.java        | 121 +++++++++++++++++-
 .../src/android/util/RecurrenceRuleTest.java  |  28 ++--
 .../src/android/util/SparseSetArrayTest.java  |   8 ++
 .../src/android/util/StateSetTest.java        |  28 +++-
 .../util/apk/SourceStampVerifierTest.java     |  14 +-
 .../src/android/util/MetadataReaderTest.java  |   4 +-
 ...ramework-minus-apex-ravenwood-policies.txt |   1 +
 .../ravenwood-annotation-allowed-classes.txt  |   9 ++
 33 files changed, 470 insertions(+), 138 deletions(-)

diff --git a/core/java/android/util/DayOfMonthCursor.java b/core/java/android/util/DayOfMonthCursor.java
index 393b98e324d3..ac5dc3a169c8 100644
--- a/core/java/android/util/DayOfMonthCursor.java
+++ b/core/java/android/util/DayOfMonthCursor.java
@@ -32,6 +32,7 @@ package android.util;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class DayOfMonthCursor extends MonthDisplayHelper {
 
     private int mRow;
diff --git a/core/java/android/util/KeyValueListParser.java b/core/java/android/util/KeyValueListParser.java
index fbc66e6bda2a..783b2d63bcf3 100644
--- a/core/java/android/util/KeyValueListParser.java
+++ b/core/java/android/util/KeyValueListParser.java
@@ -28,6 +28,7 @@ import java.time.format.DateTimeParseException;
  * can be used.
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class KeyValueListParser {
     private final ArrayMap<String, String> mValues = new ArrayMap<>();
     private final TextUtils.StringSplitter mSplitter;
diff --git a/core/java/android/util/LongArrayQueue.java b/core/java/android/util/LongArrayQueue.java
index 354f8df0a43d..b9752fe4d1cc 100644
--- a/core/java/android/util/LongArrayQueue.java
+++ b/core/java/android/util/LongArrayQueue.java
@@ -28,6 +28,7 @@ import java.util.NoSuchElementException;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class LongArrayQueue {
 
     private long[] mValues;
diff --git a/core/java/android/util/LongSparseLongArray.java b/core/java/android/util/LongSparseLongArray.java
index d4a012602f80..86268facbec0 100644
--- a/core/java/android/util/LongSparseLongArray.java
+++ b/core/java/android/util/LongSparseLongArray.java
@@ -46,6 +46,7 @@ import com.android.internal.util.Preconditions;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class LongSparseLongArray implements Cloneable {
     @UnsupportedAppUsage(maxTargetSdk = 28) // The type isn't even public.
     private long[] mKeys;
diff --git a/core/java/android/util/MonthDisplayHelper.java b/core/java/android/util/MonthDisplayHelper.java
index c3f13fc2176b..3bd292b4ba49 100644
--- a/core/java/android/util/MonthDisplayHelper.java
+++ b/core/java/android/util/MonthDisplayHelper.java
@@ -24,6 +24,7 @@ import java.util.Calendar;
  *
  * Not thread safe.
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class MonthDisplayHelper {
 
     // display pref
diff --git a/core/java/android/util/RecurrenceRule.java b/core/java/android/util/RecurrenceRule.java
index 39d1f2cbef19..dc470d7edc53 100644
--- a/core/java/android/util/RecurrenceRule.java
+++ b/core/java/android/util/RecurrenceRule.java
@@ -42,6 +42,7 @@ import java.util.Objects;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class RecurrenceRule implements Parcelable {
     private static final String TAG = "RecurrenceRule";
     private static final boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
diff --git a/core/java/android/util/RotationUtils.java b/core/java/android/util/RotationUtils.java
index f20767b7485a..07ab996af12f 100644
--- a/core/java/android/util/RotationUtils.java
+++ b/core/java/android/util/RotationUtils.java
@@ -36,6 +36,7 @@ import android.view.SurfaceControl;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class RotationUtils {
 
     /**
diff --git a/core/java/android/util/SparseDoubleArray.java b/core/java/android/util/SparseDoubleArray.java
index 4b0cbe45d857..8a0b11e09d89 100644
--- a/core/java/android/util/SparseDoubleArray.java
+++ b/core/java/android/util/SparseDoubleArray.java
@@ -41,6 +41,7 @@ package android.util;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class SparseDoubleArray implements Cloneable {
     /**
      * The int->double map, but storing the doubles as longs using
diff --git a/core/java/android/util/SparseSetArray.java b/core/java/android/util/SparseSetArray.java
index 61f29a40ff50..80f6a4a0847f 100644
--- a/core/java/android/util/SparseSetArray.java
+++ b/core/java/android/util/SparseSetArray.java
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
  *
  * @hide
  */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
 public class SparseSetArray<T> {
     private final SparseArray<ArraySet<T>> mData;
 
diff --git a/core/java/android/util/StateSet.java b/core/java/android/util/StateSet.java
index 4bbc0f863603..16d6082649a7 100644
--- a/core/java/android/util/StateSet.java
+++ b/core/java/android/util/StateSet.java
@@ -34,7 +34,6 @@ import com.android.internal.R;
  * and not have static methods here but there is some concern about
  * performance since these methods are called during view drawing.
  */
-
 public class StateSet {
     /**
      * The order here is very important to
diff --git a/core/java/android/util/Xml.java b/core/java/android/util/Xml.java
index 2a33caaf7e28..ec6e90b4153e 100644
--- a/core/java/android/util/Xml.java
+++ b/core/java/android/util/Xml.java
@@ -334,6 +334,7 @@ public class Xml {
      *
      * @hide
      */
+    @android.ravenwood.annotation.RavenwoodKeep
     public static void copy(@NonNull XmlPullParser in, @NonNull XmlSerializer out)
             throws XmlPullParserException, IOException {
         // Some parsers may have already consumed the event that starts the
@@ -393,6 +394,7 @@ public class Xml {
      * unsupported, which can confuse serializers. This method normalizes empty
      * strings to be {@code null}.
      */
+    @android.ravenwood.annotation.RavenwoodKeep
     private static @Nullable String normalizeNamespace(@Nullable String namespace) {
         if (namespace == null || namespace.isEmpty()) {
             return null;
diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp
index 21a406988104..0ad349ba5281 100644
--- a/core/tests/coretests/Android.bp
+++ b/core/tests/coretests/Android.bp
@@ -167,13 +167,22 @@ android_library {
 
 android_ravenwood_test {
     name: "FrameworksCoreTestsRavenwood",
+    libs: [
+        "android.test.runner",
+        "android.test.base",
+    ],
     static_libs: [
+        "core-test-rules", // for libcore.dalvik.system.CloseGuardSupport
         "androidx.core_core",
         "androidx.annotation_annotation",
         "androidx.test.rules",
+        "androidx.test.ext.junit",
+        "mockito_ravenwood",
+        "platform-test-annotations",
     ],
     srcs: [
         "src/android/os/FileUtilsTest.java",
+        "src/android/util/**/*.java",
         "src/com/android/internal/util/**/*.java",
         "testdoubles/src/com/android/internal/util/**/*.java",
     ],
diff --git a/core/tests/coretests/src/android/util/ArrayMapTest.java b/core/tests/coretests/src/android/util/ArrayMapTest.java
index b212cf6b0803..1e444adbc362 100644
--- a/core/tests/coretests/src/android/util/ArrayMapTest.java
+++ b/core/tests/coretests/src/android/util/ArrayMapTest.java
@@ -14,11 +14,17 @@
 
 package android.util;
 
-import androidx.test.filters.LargeTest;
+import static org.junit.Assert.fail;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
 
-import junit.framework.TestCase;
+import androidx.test.filters.LargeTest;
+import androidx.test.runner.AndroidJUnit4;
 
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.ConcurrentModificationException;
 
@@ -26,10 +32,14 @@ import java.util.ConcurrentModificationException;
  * Unit tests for ArrayMap that don't belong in CTS.
  */
 @LargeTest
-public class ArrayMapTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class ArrayMapTest {
     private static final String TAG = "ArrayMapTest";
     ArrayMap<String, String> map = new ArrayMap<>();
 
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
     /**
      * Attempt to generate a ConcurrentModificationException in ArrayMap.
      * <p>
@@ -41,6 +51,7 @@ public class ArrayMapTest extends TestCase {
      * @throws Exception
      */
     @Test
+    @IgnoreUnderRavenwood(reason = "Long test runtime")
     public void testConcurrentModificationException() throws Exception {
         final int TEST_LEN_MS = 5000;
         System.out.println("Starting ArrayMap concurrency test");
diff --git a/core/tests/coretests/src/android/util/ArraySetTest.java b/core/tests/coretests/src/android/util/ArraySetTest.java
index f1bebfb9bd93..51de6341179b 100644
--- a/core/tests/coretests/src/android/util/ArraySetTest.java
+++ b/core/tests/coretests/src/android/util/ArraySetTest.java
@@ -16,12 +16,14 @@
 
 package android.util;
 
-import androidx.test.filters.LargeTest;
+import static org.junit.Assert.fail;
 
-import junit.framework.TestCase;
+import androidx.test.filters.LargeTest;
+import androidx.test.runner.AndroidJUnit4;
 
 import org.junit.After;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.ConcurrentModificationException;
 
@@ -29,7 +31,8 @@ import java.util.ConcurrentModificationException;
  * Unit tests for ArraySet that don't belong in CTS.
  */
 @LargeTest
-public class ArraySetTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class ArraySetTest {
     private static final String TAG = "ArraySetTest";
     ArraySet<String> mSet = new ArraySet<>();
 
diff --git a/core/tests/coretests/src/android/util/Base64Test.java b/core/tests/coretests/src/android/util/Base64Test.java
index 15c51af0b3e1..b64826611f81 100644
--- a/core/tests/coretests/src/android/util/Base64Test.java
+++ b/core/tests/coretests/src/android/util/Base64Test.java
@@ -16,9 +16,16 @@
 
 package android.util;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import androidx.test.filters.LargeTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -32,7 +39,8 @@ import java.util.Random;
 import java.util.stream.Collectors;
 
 @LargeTest
-public class Base64Test extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class Base64Test {
     private static final String TAG = "Base64Test";
 
     /** Decodes a string, returning a string. */
@@ -62,7 +70,7 @@ public class Base64Test extends TestCase {
     }
 
     /** Assert that actual equals the first len bytes of expected. */
-    private void assertEquals(byte[] expected, int len, byte[] actual) {
+    private void assertPartialEquals(byte[] expected, int len, byte[] actual) {
         assertEquals(len, actual.length);
         for (int i = 0; i < len; ++i) {
             assertEquals(expected[i], actual[i]);
@@ -70,21 +78,14 @@ public class Base64Test extends TestCase {
     }
 
     /** Assert that actual equals the first len bytes of expected. */
-    private void assertEquals(byte[] expected, int len, byte[] actual, int alen) {
+    private void assertPartialEquals(byte[] expected, int len, byte[] actual, int alen) {
         assertEquals(len, alen);
         for (int i = 0; i < len; ++i) {
             assertEquals(expected[i], actual[i]);
         }
     }
 
-    /** Assert that actual equals the first len bytes of expected. */
-    private void assertEquals(byte[] expected, byte[] actual) {
-        assertEquals(expected.length, actual.length);
-        for (int i = 0; i < expected.length; ++i) {
-            assertEquals(expected[i], actual[i]);
-        }
-    }
-
+    @Test
     public void testDecodeExtraChars() throws Exception {
         // padding 0
         assertEquals("hello, world", decodeString("aGVsbG8sIHdvcmxk"));
@@ -131,28 +132,30 @@ public class Base64Test extends TestCase {
                                           (byte) 0xcc, (byte) 0xbb, (byte) 0xaa,
                                           (byte) 0x99, (byte) 0x88, (byte) 0x77 };
 
+    @Test
     public void testBinaryDecode() throws Exception {
-        assertEquals(BYTES, 0, Base64.decode("", 0));
-        assertEquals(BYTES, 1, Base64.decode("/w==", 0));
-        assertEquals(BYTES, 2, Base64.decode("/+4=", 0));
-        assertEquals(BYTES, 3, Base64.decode("/+7d", 0));
-        assertEquals(BYTES, 4, Base64.decode("/+7dzA==", 0));
-        assertEquals(BYTES, 5, Base64.decode("/+7dzLs=", 0));
-        assertEquals(BYTES, 6, Base64.decode("/+7dzLuq", 0));
-        assertEquals(BYTES, 7, Base64.decode("/+7dzLuqmQ==", 0));
-        assertEquals(BYTES, 8, Base64.decode("/+7dzLuqmYg=", 0));
+        assertPartialEquals(BYTES, 0, Base64.decode("", 0));
+        assertPartialEquals(BYTES, 1, Base64.decode("/w==", 0));
+        assertPartialEquals(BYTES, 2, Base64.decode("/+4=", 0));
+        assertPartialEquals(BYTES, 3, Base64.decode("/+7d", 0));
+        assertPartialEquals(BYTES, 4, Base64.decode("/+7dzA==", 0));
+        assertPartialEquals(BYTES, 5, Base64.decode("/+7dzLs=", 0));
+        assertPartialEquals(BYTES, 6, Base64.decode("/+7dzLuq", 0));
+        assertPartialEquals(BYTES, 7, Base64.decode("/+7dzLuqmQ==", 0));
+        assertPartialEquals(BYTES, 8, Base64.decode("/+7dzLuqmYg=", 0));
     }
 
+    @Test
     public void testWebSafe() throws Exception {
-        assertEquals(BYTES, 0, Base64.decode("", Base64.URL_SAFE));
-        assertEquals(BYTES, 1, Base64.decode("_w==", Base64.URL_SAFE));
-        assertEquals(BYTES, 2, Base64.decode("_-4=", Base64.URL_SAFE));
-        assertEquals(BYTES, 3, Base64.decode("_-7d", Base64.URL_SAFE));
-        assertEquals(BYTES, 4, Base64.decode("_-7dzA==", Base64.URL_SAFE));
-        assertEquals(BYTES, 5, Base64.decode("_-7dzLs=", Base64.URL_SAFE));
-        assertEquals(BYTES, 6, Base64.decode("_-7dzLuq", Base64.URL_SAFE));
-        assertEquals(BYTES, 7, Base64.decode("_-7dzLuqmQ==", Base64.URL_SAFE));
-        assertEquals(BYTES, 8, Base64.decode("_-7dzLuqmYg=", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 0, Base64.decode("", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 1, Base64.decode("_w==", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 2, Base64.decode("_-4=", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 3, Base64.decode("_-7d", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 4, Base64.decode("_-7dzA==", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 5, Base64.decode("_-7dzLs=", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 6, Base64.decode("_-7dzLuq", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 7, Base64.decode("_-7dzLuqmQ==", Base64.URL_SAFE));
+        assertPartialEquals(BYTES, 8, Base64.decode("_-7dzLuqmYg=", Base64.URL_SAFE));
 
         assertEquals("", Base64.encodeToString(BYTES, 0, 0, Base64.URL_SAFE));
         assertEquals("_w==\n", Base64.encodeToString(BYTES, 0, 1, Base64.URL_SAFE));
@@ -165,6 +168,7 @@ public class Base64Test extends TestCase {
         assertEquals("_-7dzLuqmYg=\n", Base64.encodeToString(BYTES, 0, 8, Base64.URL_SAFE));
     }
 
+    @Test
     public void testFlags() throws Exception {
         assertEquals("YQ==\n",       encodeToString("a", 0));
         assertEquals("YQ==",         encodeToString("a", Base64.NO_WRAP));
@@ -195,6 +199,7 @@ public class Base64Test extends TestCase {
         assertEquals("YWJjZA\r\n",   encodeToString("abcd", Base64.CRLF | Base64.NO_PADDING));
     }
 
+    @Test
     public void testLineLength() throws Exception {
         String in_56 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd";
         String in_57 = in_56 + "e";
@@ -245,7 +250,9 @@ public class Base64Test extends TestCase {
      * us to get at package-private members (Base64.Encoder in
      * this case).
      */
-    public void XXXtestEncodeInternal() throws Exception {
+    @Test
+    @Ignore
+    public void testEncodeInternal() throws Exception {
         byte[] input = { (byte) 0x61, (byte) 0x62, (byte) 0x63 };
         byte[] output = new byte[100];
 
@@ -253,11 +260,11 @@ public class Base64Test extends TestCase {
                                                     output);
 
         encoder.process(input, 0, 3, false);
-        assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op);
+        assertPartialEquals("YWJj".getBytes(), 4, encoder.output, encoder.op);
         assertEquals(0, encoder.tailLen);
 
         encoder.process(input, 0, 3, false);
-        assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op);
+        assertPartialEquals("YWJj".getBytes(), 4, encoder.output, encoder.op);
         assertEquals(0, encoder.tailLen);
 
         encoder.process(input, 0, 1, false);
@@ -269,7 +276,7 @@ public class Base64Test extends TestCase {
         assertEquals(2, encoder.tailLen);
 
         encoder.process(input, 0, 1, false);
-        assertEquals("YWFh".getBytes(), 4, encoder.output, encoder.op);
+        assertPartialEquals("YWFh".getBytes(), 4, encoder.output, encoder.op);
         assertEquals(0, encoder.tailLen);
 
         encoder.process(input, 0, 2, false);
@@ -277,15 +284,15 @@ public class Base64Test extends TestCase {
         assertEquals(2, encoder.tailLen);
 
         encoder.process(input, 0, 2, false);
-        assertEquals("YWJh".getBytes(), 4, encoder.output, encoder.op);
+        assertPartialEquals("YWJh".getBytes(), 4, encoder.output, encoder.op);
         assertEquals(1, encoder.tailLen);
 
         encoder.process(input, 0, 2, false);
-        assertEquals("YmFi".getBytes(), 4, encoder.output, encoder.op);
+        assertPartialEquals("YmFi".getBytes(), 4, encoder.output, encoder.op);
         assertEquals(0, encoder.tailLen);
 
         encoder.process(input, 0, 1, true);
-        assertEquals("YQ".getBytes(), 2, encoder.output, encoder.op);
+        assertPartialEquals("YQ".getBytes(), 2, encoder.output, encoder.op);
     }
 
     private static final String lipsum =
@@ -311,6 +318,7 @@ public class Base64Test extends TestCase {
             "molestie dapibus commodo. Ut vel tellus at massa gravida " +
             "semper non sed orci.";
 
+    @Test
     public void testInputStream() throws Exception {
         int[] flagses = { Base64.DEFAULT,
                           Base64.NO_PADDING,
@@ -343,7 +351,7 @@ public class Base64Test extends TestCase {
             while ((b = b64is.read(actual, ap, actual.length-ap)) != -1) {
                 ap += b;
             }
-            assertEquals(actual, ap, plain);
+            assertPartialEquals(actual, ap, plain);
 
             // read individual bytes
             bais = new ByteArrayInputStream(encoded);
@@ -352,7 +360,7 @@ public class Base64Test extends TestCase {
             while ((b = b64is.read()) != -1) {
                 actual[ap++] = (byte) b;
             }
-            assertEquals(actual, ap, plain);
+            assertPartialEquals(actual, ap, plain);
 
             // mix reads of variously-sized arrays with one-byte reads
             bais = new ByteArrayInputStream(encoded);
@@ -371,7 +379,7 @@ public class Base64Test extends TestCase {
                     }
                 }
             }
-            assertEquals(actual, ap, plain);
+            assertPartialEquals(actual, ap, plain);
 
             // ----- test encoding ("plain" -> "encoded") -----
 
@@ -382,7 +390,7 @@ public class Base64Test extends TestCase {
             while ((b = b64is.read(actual, ap, actual.length-ap)) != -1) {
                 ap += b;
             }
-            assertEquals(actual, ap, encoded);
+            assertPartialEquals(actual, ap, encoded);
 
             // read individual bytes
             bais = new ByteArrayInputStream(plain);
@@ -391,7 +399,7 @@ public class Base64Test extends TestCase {
             while ((b = b64is.read()) != -1) {
                 actual[ap++] = (byte) b;
             }
-            assertEquals(actual, ap, encoded);
+            assertPartialEquals(actual, ap, encoded);
 
             // mix reads of variously-sized arrays with one-byte reads
             bais = new ByteArrayInputStream(plain);
@@ -410,11 +418,12 @@ public class Base64Test extends TestCase {
                     }
                 }
             }
-            assertEquals(actual, ap, encoded);
+            assertPartialEquals(actual, ap, encoded);
         }
     }
 
     /** http://b/3026478 */
+    @Test
     public void testSingleByteReads() throws IOException {
         InputStream in = new Base64InputStream(
                 new ByteArrayInputStream("/v8=".getBytes()), Base64.DEFAULT);
@@ -426,6 +435,7 @@ public class Base64Test extends TestCase {
      * Tests that Base64OutputStream produces exactly the same results
      * as calling Base64.encode/.decode on an in-memory array.
      */
+    @Test
     public void testOutputStream() throws Exception {
         int[] flagses = { Base64.DEFAULT,
                           Base64.NO_PADDING,
@@ -456,7 +466,7 @@ public class Base64Test extends TestCase {
             b64os.write(plain);
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(encoded, actual);
+            assertArrayEquals(encoded, actual);
 
             // many calls to write(int)
             baos = new ByteArrayOutputStream();
@@ -466,7 +476,7 @@ public class Base64Test extends TestCase {
             }
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(encoded, actual);
+            assertArrayEquals(encoded, actual);
 
             // intermixed sequences of write(int) with
             // write(byte[],int,int) of various lengths.
@@ -489,7 +499,7 @@ public class Base64Test extends TestCase {
             }
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(encoded, actual);
+            assertArrayEquals(encoded, actual);
 
             // ----- test decoding ("encoded" -> "plain") -----
 
@@ -499,7 +509,7 @@ public class Base64Test extends TestCase {
             b64os.write(encoded);
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(plain, actual);
+            assertArrayEquals(plain, actual);
 
             // many calls to write(int)
             baos = new ByteArrayOutputStream();
@@ -509,7 +519,7 @@ public class Base64Test extends TestCase {
             }
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(plain, actual);
+            assertArrayEquals(plain, actual);
 
             // intermixed sequences of write(int) with
             // write(byte[],int,int) of various lengths.
@@ -532,10 +542,11 @@ public class Base64Test extends TestCase {
             }
             b64os.close();
             actual = baos.toByteArray();
-            assertEquals(plain, actual);
+            assertArrayEquals(plain, actual);
         }
     }
 
+    @Test
     public void testOutputStream_ioExceptionDuringClose() {
         OutputStream out = new OutputStream() {
             @Override public void write(int b) throws IOException { }
@@ -551,6 +562,7 @@ public class Base64Test extends TestCase {
         }
     }
 
+    @Test
     public void testOutputStream_ioExceptionDuringCloseAndWrite() {
         OutputStream out = new OutputStream() {
             @Override public void write(int b) throws IOException {
@@ -583,6 +595,7 @@ public class Base64Test extends TestCase {
         }
     }
 
+    @Test
     public void testOutputStream_ioExceptionDuringWrite() {
         OutputStream out = new OutputStream() {
             @Override public void write(int b) throws IOException {
diff --git a/core/tests/coretests/src/android/util/CharsetUtilsTest.java b/core/tests/coretests/src/android/util/CharsetUtilsTest.java
index c29545168758..fbbe311d44fb 100644
--- a/core/tests/coretests/src/android/util/CharsetUtilsTest.java
+++ b/core/tests/coretests/src/android/util/CharsetUtilsTest.java
@@ -18,6 +18,9 @@ package android.util;
 
 import static org.junit.Assert.assertEquals;
 
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
 import androidx.test.runner.AndroidJUnit4;
 
 import com.android.internal.util.HexDump;
@@ -25,18 +28,25 @@ import com.android.internal.util.HexDump;
 import dalvik.system.VMRuntime;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 @RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = CharsetUtils.class)
 public class CharsetUtilsTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
     private byte[] dest;
     private long destPtr;
 
     @Before
     public void setUp() {
-        dest = (byte[]) VMRuntime.getRuntime().newNonMovableArray(byte.class, 8);
-        destPtr = VMRuntime.getRuntime().addressOf(dest);
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            dest = (byte[]) VMRuntime.getRuntime().newNonMovableArray(byte.class, 8);
+            destPtr = VMRuntime.getRuntime().addressOf(dest);
+        }
     }
 
     @Test
diff --git a/core/tests/coretests/src/android/util/CloseGuardTest.java b/core/tests/coretests/src/android/util/CloseGuardTest.java
index d86c7b79fad6..15c57b1aa6f7 100644
--- a/core/tests/coretests/src/android/util/CloseGuardTest.java
+++ b/core/tests/coretests/src/android/util/CloseGuardTest.java
@@ -16,6 +16,9 @@
 
 package android.util;
 
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
 import libcore.dalvik.system.CloseGuardSupport;
 
 import org.junit.Rule;
@@ -23,10 +26,21 @@ import org.junit.Test;
 import org.junit.rules.TestRule;
 
 /** Unit tests for {@link android.util.CloseGuard} */
+@IgnoreUnderRavenwood(blockedBy = CloseGuard.class)
 public class CloseGuardTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
 
     @Rule
-    public final TestRule rule = CloseGuardSupport.getRule();
+    public final TestRule rule;
+
+    public CloseGuardTest() {
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            rule = CloseGuardSupport.getRule();
+        } else {
+            rule = null;
+        }
+    }
 
     @Test
     public void testEnabled_NotOpen() throws Throwable {
diff --git a/core/tests/coretests/src/android/util/DayOfMonthCursorTest.java b/core/tests/coretests/src/android/util/DayOfMonthCursorTest.java
index 572e9b062097..72bd578ad8b9 100644
--- a/core/tests/coretests/src/android/util/DayOfMonthCursorTest.java
+++ b/core/tests/coretests/src/android/util/DayOfMonthCursorTest.java
@@ -16,30 +16,40 @@
 
 package android.util;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.Calendar;
 
 /**
  * Unit tests for {@link DayOfMonthCursor}.
  */
-public class DayOfMonthCursorTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class DayOfMonthCursorTest {
 
+    @Test
     @SmallTest
     public void testMonthRows() {
         DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                 Calendar.SEPTEMBER, 11, Calendar.SUNDAY);
 
-        assertArraysEqual(new int[]{26, 27, 28, 29, 30, 31, 1},
+        assertArrayEquals(new int[]{26, 27, 28, 29, 30, 31, 1},
                 mc.getDigitsForRow(0));
-        assertArraysEqual(new int[]{2, 3, 4, 5, 6, 7, 8},
+        assertArrayEquals(new int[]{2, 3, 4, 5, 6, 7, 8},
                 mc.getDigitsForRow(1));
-        assertArraysEqual(new int[]{30, 1, 2, 3, 4, 5, 6},
+        assertArrayEquals(new int[]{30, 1, 2, 3, 4, 5, 6},
                 mc.getDigitsForRow(5));
     }
 
+    @Test
     @SmallTest
     public void testMoveLeft() {
         DayOfMonthCursor mc = new DayOfMonthCursor(2007,
@@ -70,6 +80,7 @@ public class DayOfMonthCursorTest extends TestCase {
         assertEquals(5, mc.getSelectedColumn());
     }
 
+    @Test
     @SmallTest
     public void testMoveRight() {
         DayOfMonthCursor mc = new DayOfMonthCursor(2007,
@@ -100,6 +111,7 @@ public class DayOfMonthCursorTest extends TestCase {
         assertEquals(1, mc.getSelectedColumn());
     }
 
+    @Test
     @SmallTest
     public void testMoveUp() {
         DayOfMonthCursor mc = new DayOfMonthCursor(2007,
@@ -124,6 +136,7 @@ public class DayOfMonthCursorTest extends TestCase {
         assertEquals(4, mc.getSelectedColumn());
     }
 
+    @Test
     @SmallTest
     public void testMoveDown() {
         DayOfMonthCursor mc = new DayOfMonthCursor(2007,
@@ -147,12 +160,4 @@ public class DayOfMonthCursorTest extends TestCase {
         assertEquals(1, mc.getSelectedRow());
         assertEquals(0, mc.getSelectedColumn());
     }
-
-    private void assertArraysEqual(int[] expected, int[] actual) {
-        assertEquals("array length", expected.length, actual.length);
-        for (int i = 0; i < expected.length; i++) {
-            assertEquals("index " + i,
-                    expected[i], actual[i]);
-        }
-    }
 }
diff --git a/core/tests/coretests/src/android/util/HashedStringCacheTest.java b/core/tests/coretests/src/android/util/HashedStringCacheTest.java
index 229247353a52..08c85ac5c0d6 100644
--- a/core/tests/coretests/src/android/util/HashedStringCacheTest.java
+++ b/core/tests/coretests/src/android/util/HashedStringCacheTest.java
@@ -26,28 +26,37 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Environment;
 import android.os.storage.StorageManager;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
 
 import androidx.test.InstrumentationRegistry;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import java.io.File;
 
-
 /**
  * Unit tests for {@link HashedStringCache}.
  */
+@IgnoreUnderRavenwood(blockedBy = HashedStringCache.class)
 public class HashedStringCacheTest {
     private static final String TAG = "HashedStringCacheTest";
     private Context mContext;
     private static final String TEST_STRING = "test_string";
 
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
     @Before
     public void setup() {
-        mContext = null;
-        mContext = InstrumentationRegistry.getContext();
-        clearSharedPreferences();
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            mContext = InstrumentationRegistry.getContext();
+            clearSharedPreferences();
+        } else {
+            mContext = null;
+        }
     }
 
     @Test
diff --git a/core/tests/coretests/src/android/util/LogNullabilityTest.java b/core/tests/coretests/src/android/util/LogNullabilityTest.java
index 370885d3d4ac..475e347141df 100644
--- a/core/tests/coretests/src/android/util/LogNullabilityTest.java
+++ b/core/tests/coretests/src/android/util/LogNullabilityTest.java
@@ -19,6 +19,8 @@ package android.util;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import android.platform.test.ravenwood.RavenwoodRule;
+
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
@@ -35,8 +37,10 @@ public final class LogNullabilityTest {
         Log.i(null, "");
         Log.w(null, "");
         Log.e(null, "");
-        Log.wtf(null, "");
-        Log.wtfStack(null, "");
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf(null, "");
+            Log.wtfStack(null, "");
+        }
         Log.println(Log.INFO, null, "");
 
         // Implicit assertions of not crashing.
@@ -49,7 +53,9 @@ public final class LogNullabilityTest {
         Log.i(null, "", new Throwable());
         Log.w(null, "", new Throwable());
         Log.e(null, "", new Throwable());
-        Log.wtf(null, "", new Throwable());
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf(null, "", new Throwable());
+        }
         Log.printlns(Log.LOG_ID_MAIN, Log.INFO, null, "", new Throwable());
 
         // Implicit assertions of not crashing.
@@ -84,8 +90,10 @@ public final class LogNullabilityTest {
         } catch (NullPointerException expected) {
         }
 
-        Log.wtf("", (String) null);
-        Log.wtfStack("", (String) null);
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf("", (String) null);
+            Log.wtfStack("", (String) null);
+        }
 
         // Implicit assertion of not crashing.
 
@@ -103,15 +111,10 @@ public final class LogNullabilityTest {
         Log.i("", null, new Throwable());
         Log.w("", null, new Throwable());
         Log.e("", null, new Throwable());
-        Log.wtf("", null, new Throwable());
-
-        // Implicit assertions of not crashing.
-
-        try {
-            Log.printlns(Log.LOG_ID_MAIN, Log.INFO, "", null, new Throwable());
-            fail();
-        } catch (NullPointerException expected) {
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf("", null, new Throwable());
         }
+        Log.printlns(Log.LOG_ID_MAIN, Log.INFO, "", null, new Throwable());
     }
 
     @Test
@@ -121,7 +124,9 @@ public final class LogNullabilityTest {
         Log.i("", "", null);
         Log.w("", "", null);
         Log.e("", "", null);
-        Log.wtf("", "", null);
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf("", "", null);
+        }
 
         // Warning has its own (String, Throwable) overload.
         Log.w("", (Throwable) null);
@@ -131,10 +136,12 @@ public final class LogNullabilityTest {
         // Implicit assertions of not crashing.
 
         // WTF has its own (String, Throwable) overload with different behavior.
-        try {
-            Log.wtf("", (Throwable) null);
-            fail();
-        } catch (NullPointerException expected) {
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            try {
+                Log.wtf("", (Throwable) null);
+                fail();
+            } catch (NullPointerException expected) {
+            }
         }
     }
 
@@ -145,15 +152,10 @@ public final class LogNullabilityTest {
         Log.i("", null, null);
         Log.w("", null, null);
         Log.e("", null, null);
-        Log.wtf("", null, null);
-
-        // Implicit assertions of not crashing.
-
-        try {
-            Log.printlns(Log.LOG_ID_MAIN, Log.INFO, "", null, null);
-            fail();
-        } catch (NullPointerException expected) {
+        if (!RavenwoodRule.isUnderRavenwood()) {
+            Log.wtf("", null, null);
         }
+        Log.printlns(Log.LOG_ID_MAIN, Log.INFO, "", null, null);
     }
 
     @Test
diff --git a/core/tests/coretests/src/android/util/LogTest.java b/core/tests/coretests/src/android/util/LogTest.java
index d783c127d8c4..f9966a1cf65d 100644
--- a/core/tests/coretests/src/android/util/LogTest.java
+++ b/core/tests/coretests/src/android/util/LogTest.java
@@ -20,23 +20,24 @@ import android.os.SystemProperties;
 import android.test.PerformanceTestCase;
 
 import androidx.test.filters.Suppress;
+import androidx.test.runner.AndroidJUnit4;
 
 import junit.framework.TestCase;
 
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 //This is an empty TestCase.
 @Suppress
-public class LogTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class LogTest {
     private static final String PROPERTY_TAG = "log.tag.LogTest";
     private static final String LOG_TAG = "LogTest";
 
-
-    // TODO: remove this test once we uncomment out the following test.
-    public void testLogTestDummy() {
-      return;
-    }
-
-
-    /* TODO: This test is commented out because we will not be able to set properities. Fix the test.
+    @Test
+    @Ignore
     public void testIsLoggable() {
         // First clear any SystemProperty setting for our test key.
         SystemProperties.set(PROPERTY_TAG, null);
@@ -129,8 +130,7 @@ public class LogTest extends TestCase {
         Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.ERROR));
         Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.ASSERT));
     }
-    */
-    
+
     public static class PerformanceTest extends TestCase implements PerformanceTestCase {
         private static final int ITERATIONS = 1000;
 
diff --git a/core/tests/coretests/src/android/util/LongSparseLongArrayTest.java b/core/tests/coretests/src/android/util/LongSparseLongArrayTest.java
index a1d48e689427..9dbaae0d0555 100644
--- a/core/tests/coretests/src/android/util/LongSparseLongArrayTest.java
+++ b/core/tests/coretests/src/android/util/LongSparseLongArrayTest.java
@@ -16,9 +16,13 @@
 
 package android.util;
 
+import static org.junit.Assert.assertEquals;
+
 import androidx.test.filters.LargeTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -29,9 +33,11 @@ import java.util.Random;
  * Tests for {@link LongSparseLongArray}.
  */
 @LargeTest
-public class LongSparseLongArrayTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class LongSparseLongArrayTest {
     private static final String TAG = "LongSparseLongArrayTest";
 
+    @Test
     public void testSimplePut() throws Exception {
         final LongSparseLongArray array = new LongSparseLongArray(5);
         for (int i = 0; i < 48; i++) {
@@ -45,6 +51,7 @@ public class LongSparseLongArrayTest extends TestCase {
         }
     }
 
+    @Test
     public void testSimplePutBackwards() throws Exception {
         final LongSparseLongArray array = new LongSparseLongArray(5);
         for (int i = 47; i >= 0; i--) {
@@ -58,6 +65,7 @@ public class LongSparseLongArrayTest extends TestCase {
         }
     }
 
+    @Test
     public void testMiddleInsert() throws Exception {
         final LongSparseLongArray array = new LongSparseLongArray(5);
         for (int i = 0; i < 48; i++) {
@@ -74,6 +82,7 @@ public class LongSparseLongArrayTest extends TestCase {
         assertEquals(1024, array.get(special, -1));
     }
 
+    @Test
     public void testFuzz() throws Exception {
         final Random r = new Random();
 
diff --git a/core/tests/coretests/src/android/util/LruCacheTest.java b/core/tests/coretests/src/android/util/LruCacheTest.java
index 1928bfdfc61d..10e8308e7964 100644
--- a/core/tests/coretests/src/android/util/LruCacheTest.java
+++ b/core/tests/coretests/src/android/util/LruCacheTest.java
@@ -16,7 +16,14 @@
 
 package android.util;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -24,13 +31,15 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-public final class LruCacheTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public final class LruCacheTest {
     private int expectedCreateCount;
     private int expectedPutCount;
     private int expectedHitCount;
     private int expectedMissCount;
     private int expectedEvictionCount;
 
+    @Test
     public void testStatistics() {
         LruCache<String, String> cache = new LruCache<String, String>(3);
         assertStatistics(cache);
@@ -80,6 +89,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "e", "E", "b", "B", "c", "C");
     }
 
+    @Test
     public void testStatisticsWithCreate() {
         LruCache<String, String> cache = newCreatingCache();
         assertStatistics(cache);
@@ -104,18 +114,21 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "cc", "created-cc", "dd", "created-dd", "aa", "created-aa");
     }
 
+    @Test
     public void testCreateOnCacheMiss() {
         LruCache<String, String> cache = newCreatingCache();
         String created = cache.get("aa");
         assertEquals("created-aa", created);
     }
 
+    @Test
     public void testNoCreateOnCacheHit() {
         LruCache<String, String> cache = newCreatingCache();
         cache.put("aa", "put-aa");
         assertEquals("put-aa", cache.get("aa"));
     }
 
+    @Test
     public void testConstructorDoesNotAllowZeroCacheSize() {
         try {
             new LruCache<String, String>(0);
@@ -124,6 +137,7 @@ public final class LruCacheTest extends TestCase {
         }
     }
 
+    @Test
     public void testCannotPutNullKey() {
         LruCache<String, String> cache = new LruCache<String, String>(3);
         try {
@@ -133,6 +147,7 @@ public final class LruCacheTest extends TestCase {
         }
     }
 
+    @Test
     public void testCannotPutNullValue() {
         LruCache<String, String> cache = new LruCache<String, String>(3);
         try {
@@ -142,6 +157,7 @@ public final class LruCacheTest extends TestCase {
         }
     }
 
+    @Test
     public void testToString() {
         LruCache<String, String> cache = new LruCache<String, String>(3);
         assertEquals("LruCache[maxSize=3,hits=0,misses=0,hitRate=0%]", cache.toString());
@@ -160,6 +176,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals("LruCache[maxSize=3,hits=3,misses=2,hitRate=60%]", cache.toString());
     }
 
+    @Test
     public void testEvictionWithSingletonCache() {
         LruCache<String, String> cache = new LruCache<String, String>(1);
         cache.put("a", "A");
@@ -167,6 +184,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "b", "B");
     }
 
+    @Test
     public void testEntryEvictedWhenFull() {
         List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = newRemovalLogCache(log);
@@ -184,6 +202,7 @@ public final class LruCacheTest extends TestCase {
      * Replacing the value for a key doesn't cause an eviction but it does bring
      * the replaced entry to the front of the queue.
      */
+    @Test
     public void testPutCauseEviction() {
         List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = newRemovalLogCache(log);
@@ -196,6 +215,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "a", "A", "c", "C", "b", "B2");
     }
 
+    @Test
     public void testCustomSizesImpactsSize() {
         LruCache<String, String> cache = new LruCache<String, String>(10) {
             @Override protected int sizeOf(String key, String value) {
@@ -212,6 +232,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(6, cache.size());
     }
 
+    @Test
     public void testEvictionWithCustomSizes() {
         LruCache<String, String> cache = new LruCache<String, String>(4) {
             @Override protected int sizeOf(String key, String value) {
@@ -241,6 +262,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "j", "JJJ");
     }
 
+    @Test
     public void testEvictionThrowsWhenSizesAreInconsistent() {
         LruCache<String, int[]> cache = new LruCache<String, int[]>(4) {
             @Override protected int sizeOf(String key, int[] value) {
@@ -263,6 +285,7 @@ public final class LruCacheTest extends TestCase {
         }
     }
 
+    @Test
     public void testEvictionThrowsWhenSizesAreNegative() {
         LruCache<String, String> cache = new LruCache<String, String>(4) {
             @Override protected int sizeOf(String key, String value) {
@@ -282,6 +305,7 @@ public final class LruCacheTest extends TestCase {
      * because evicting a small element may be insufficient to make room for a
      * large element.
      */
+    @Test
     public void testDifferentElementSizes() {
         LruCache<String, String> cache = new LruCache<String, String>(10) {
             @Override protected int sizeOf(String key, String value) {
@@ -299,6 +323,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache, "e", "12345678");
     }
 
+    @Test
     public void testEvictAll() {
         List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = newRemovalLogCache(log);
@@ -310,6 +335,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(Arrays.asList("a=A", "b=B", "c=C"), log);
     }
 
+    @Test
     public void testEvictAllEvictsSizeZeroElements() {
         LruCache<String, String> cache = new LruCache<String, String>(10) {
             @Override protected int sizeOf(String key, String value) {
@@ -323,6 +349,7 @@ public final class LruCacheTest extends TestCase {
         assertSnapshot(cache);
     }
 
+    @Test
     public void testRemoveWithCustomSizes() {
         LruCache<String, String> cache = new LruCache<String, String>(10) {
             @Override protected int sizeOf(String key, String value) {
@@ -335,6 +362,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(4, cache.size());
     }
 
+    @Test
     public void testRemoveAbsentElement() {
         LruCache<String, String> cache = new LruCache<String, String>(10);
         cache.put("a", "A");
@@ -343,6 +371,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(2, cache.size());
     }
 
+    @Test
     public void testRemoveNullThrows() {
         LruCache<String, String> cache = new LruCache<String, String>(10);
         try {
@@ -352,6 +381,7 @@ public final class LruCacheTest extends TestCase {
         }
     }
 
+    @Test
     public void testRemoveCallsEntryRemoved() {
         List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = newRemovalLogCache(log);
@@ -360,6 +390,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(Arrays.asList("a=A>null"), log);
     }
 
+    @Test
     public void testPutCallsEntryRemoved() {
         List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = newRemovalLogCache(log);
@@ -368,6 +399,7 @@ public final class LruCacheTest extends TestCase {
         assertEquals(Arrays.asList("a=A>A2"), log);
     }
 
+    @Test
     public void testEntryRemovedIsCalledWithoutSynchronization() {
         LruCache<String, String> cache = new LruCache<String, String>(3) {
             @Override protected void entryRemoved(
@@ -385,6 +417,7 @@ public final class LruCacheTest extends TestCase {
         cache.evictAll();     // multiple eviction
     }
 
+    @Test
     public void testCreateIsCalledWithoutSynchronization() {
         LruCache<String, String> cache = new LruCache<String, String>(3) {
             @Override protected String create(String key) {
@@ -401,6 +434,7 @@ public final class LruCacheTest extends TestCase {
      * working. The map value should be returned by get(), and the created value
      * should be released with entryRemoved().
      */
+    @Test
     public void testCreateWithConcurrentPut() {
         final List<String> log = new ArrayList<String>();
         LruCache<String, String> cache = new LruCache<String, String>(3) {
@@ -423,6 +457,7 @@ public final class LruCacheTest extends TestCase {
      * the first create to return is returned by both gets. The other created
      * values should be released with entryRemove().
      */
+    @Test
     public void testCreateWithConcurrentCreate() {
         final List<String> log = new ArrayList<String>();
         LruCache<String, Integer> cache = new LruCache<String, Integer>(3) {
diff --git a/core/tests/coretests/src/android/util/MonthDisplayHelperTest.java b/core/tests/coretests/src/android/util/MonthDisplayHelperTest.java
index 30d5f778e945..06f970fcf77c 100644
--- a/core/tests/coretests/src/android/util/MonthDisplayHelperTest.java
+++ b/core/tests/coretests/src/android/util/MonthDisplayHelperTest.java
@@ -16,18 +16,26 @@
 
 package android.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.Calendar;
 
 /**
  * Unit tests for {@link MonthDisplayHelper}.
  */
-public class MonthDisplayHelperTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class MonthDisplayHelperTest {
 
 
+    @Test
     @SmallTest
     public void testFirstDayOfMonth() {
 
@@ -40,12 +48,14 @@ public class MonthDisplayHelperTest extends TestCase {
                 new MonthDisplayHelper(2007, Calendar.SEPTEMBER).getFirstDayOfMonth());
     }
 
+    @Test
     @SmallTest
     public void testNumberOfDaysInCurrentMonth() {
         assertEquals(30,
                 new MonthDisplayHelper(2007, Calendar.SEPTEMBER).getNumberOfDaysInMonth());
     }
 
+    @Test
     @SmallTest
     public void testMonthRows() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007, Calendar.SEPTEMBER);
@@ -59,6 +69,7 @@ public class MonthDisplayHelperTest extends TestCase {
 
     }
 
+    @Test
     @SmallTest
     public void testMonthRowsWeekStartsMonday() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -74,6 +85,7 @@ public class MonthDisplayHelperTest extends TestCase {
                 helper.getDigitsForRow(5));
     }
 
+    @Test
     @SmallTest
     public void testMonthRowsWeekStartsSaturday() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -98,6 +110,7 @@ public class MonthDisplayHelperTest extends TestCase {
                 helper.getDigitsForRow(4));
     }
 
+    @Test
     @SmallTest
     public void testGetDayAt() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -109,6 +122,7 @@ public class MonthDisplayHelperTest extends TestCase {
         assertEquals(2, helper.getDayAt(5, 2));
     }
 
+    @Test
     @SmallTest
     public void testPrevMonth() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -124,6 +138,7 @@ public class MonthDisplayHelperTest extends TestCase {
                 helper.getDigitsForRow(0));
     }
 
+    @Test
     @SmallTest
     public void testPrevMonthRollOver() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -135,6 +150,7 @@ public class MonthDisplayHelperTest extends TestCase {
         assertEquals(Calendar.DECEMBER, helper.getMonth());
     }
 
+    @Test
     @SmallTest
     public void testNextMonth() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -150,6 +166,7 @@ public class MonthDisplayHelperTest extends TestCase {
                 helper.getDigitsForRow(0));
     }
 
+    @Test
     @SmallTest
     public void testGetRowOf() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -162,6 +179,7 @@ public class MonthDisplayHelperTest extends TestCase {
         assertEquals(3, helper.getRowOf(19));
     }
 
+    @Test
     @SmallTest
     public void testGetColumnOf() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
@@ -174,6 +192,7 @@ public class MonthDisplayHelperTest extends TestCase {
         assertEquals(0, helper.getColumnOf(26));
     }
 
+    @Test
     @SmallTest
     public void testWithinCurrentMonth() {
         MonthDisplayHelper helper = new MonthDisplayHelper(2007,
diff --git a/core/tests/coretests/src/android/util/NtpTrustedTimeTest.java b/core/tests/coretests/src/android/util/NtpTrustedTimeTest.java
index 4de27c332d96..ce1eabc741a3 100644
--- a/core/tests/coretests/src/android/util/NtpTrustedTimeTest.java
+++ b/core/tests/coretests/src/android/util/NtpTrustedTimeTest.java
@@ -31,10 +31,15 @@ import static java.lang.String.join;
 import static java.util.Arrays.asList;
 
 import android.net.Network;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
 
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InOrder;
@@ -51,7 +56,10 @@ import java.util.stream.Stream;
 
 @SmallTest
 @RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = NtpTrustedTime.class)
 public class NtpTrustedTimeTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
 
     private static final Duration VALID_TIMEOUT = Duration.ofSeconds(5);
 
diff --git a/core/tests/coretests/src/android/util/PatternsTest.java b/core/tests/coretests/src/android/util/PatternsTest.java
index dd8f73fd54c4..a180ec3f9e35 100644
--- a/core/tests/coretests/src/android/util/PatternsTest.java
+++ b/core/tests/coretests/src/android/util/PatternsTest.java
@@ -16,17 +16,25 @@
 
 package android.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public class PatternsTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class PatternsTest {
 
     // Tests for Patterns.TOP_LEVEL_DOMAIN
 
+    @Test
     @SmallTest
     public void testTldPattern() throws Exception {
         boolean t;
@@ -58,36 +66,42 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.IANA_TOP_LEVEL_DOMAINS
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_matchesValidTld() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
         assertTrue("Should match 'com'", pattern.matcher("com").matches());
     }
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_matchesValidNewTld() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
         assertTrue("Should match 'me'", pattern.matcher("me").matches());
     }
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_matchesPunycodeTld() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
         assertTrue("Should match Punycode TLD", pattern.matcher("xn--qxam").matches());
     }
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_matchesIriTLD() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
         assertTrue("Should match IRI TLD", pattern.matcher("\uD55C\uAD6D").matches());
     }
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_doesNotMatchWrongTld() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
         assertFalse("Should not match 'mem'", pattern.matcher("mem").matches());
     }
 
+    @Test
     @SmallTest
     public void testIanaTopLevelDomains_doesNotMatchWrongPunycodeTld() throws Exception {
         Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
@@ -96,6 +110,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.WEB_URL
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesValidUrlWithSchemeAndHostname() throws Exception {
         String url = "http://www.android.com";
@@ -103,6 +118,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesValidUrlWithSchemeHostnameAndNewTld() throws Exception {
         String url = "http://www.android.me";
@@ -110,6 +126,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesValidUrlWithHostnameAndNewTld() throws Exception {
         String url = "android.me";
@@ -117,6 +134,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesChinesePunycodeUrlWithProtocol() throws Exception {
         String url = "http://xn--fsqu00a.xn--0zwm56d";
@@ -124,6 +142,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesChinesePunycodeUrlWithoutProtocol() throws Exception {
         String url = "xn--fsqu00a.xn--0zwm56d";
@@ -131,6 +150,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesArabicPunycodeUrlWithProtocol() throws Exception {
         String url = "http://xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
@@ -138,6 +158,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesArabicPunycodeUrlWithoutProtocol() throws Exception {
         String url = "xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
@@ -145,6 +166,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithUnicodeDomainNameWithProtocol() throws Exception {
         String url = "http://\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -152,6 +174,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithUnicodeDomainNameWithoutProtocol() throws Exception {
         String url = "\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -159,6 +182,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithUnicodeTld() throws Exception {
         String url = "\uB3C4\uBA54\uC778.\uD55C\uAD6D";
@@ -166,6 +190,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithUnicodePath() throws Exception {
         String url = "http://brainstormtech.blogs.fortune.cnn.com/2010/03/11/" +
@@ -174,19 +199,22 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_doesNotMatchValidUrlWithInvalidProtocol() throws Exception {
-        String url = "ftp://www.example.com";
+        String url = "invalid://www.example.com";
         assertFalse("Should not match URL with invalid protocol",
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesValidUrlWithPort() throws Exception {
         String url = "http://www.example.com:8080";
         assertTrue("Should match URL with port", Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithPortAndQuery() throws Exception {
         String url = "http://www.example.com:8080/?foo=bar";
@@ -194,12 +222,14 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesUrlWithTilde() throws Exception {
         String url = "http://www.example.com:8080/~user/?foo=bar";
         assertTrue("Should match URL with tilde", Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesProtocolCaseInsensitive() throws Exception {
         String url = "hTtP://android.com";
@@ -207,6 +237,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesDomainNameWithDash() throws Exception {
         String url = "http://a-nd.r-oid.com";
@@ -218,6 +249,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesDomainNameWithUnderscore() throws Exception {
         String url = "http://a_nd.r_oid.com";
@@ -229,6 +261,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesPathAndQueryWithDollarSign() throws Exception {
         String url = "http://android.com/path$?v=$val";
@@ -240,6 +273,7 @@ public class PatternsTest extends TestCase {
                 Patterns.WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testWebUrl_matchesEmptyPathWithQueryParams() throws Exception {
         String url = "http://android.com?q=v";
@@ -261,6 +295,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.AUTOLINK_WEB_URL
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesValidUrlWithSchemeAndHostname() throws Exception {
         String url = "http://www.android.com";
@@ -268,6 +303,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesValidUrlWithSchemeHostnameAndNewTld() throws Exception {
         String url = "http://www.android.me";
@@ -275,6 +311,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesValidUrlWithHostnameAndNewTld() throws Exception {
         String url = "android.me";
@@ -286,6 +323,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesChinesePunycodeUrlWithProtocol() throws Exception {
         String url = "http://xn--fsqu00a.xn--0zwm56d";
@@ -293,6 +331,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesChinesePunycodeUrlWithoutProtocol() throws Exception {
         String url = "xn--fsqu00a.xn--0zwm56d";
@@ -300,6 +339,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesArabicPunycodeUrlWithProtocol() throws Exception {
         String url = "http://xn--4gbrim.xn--rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
@@ -307,6 +347,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesArabicPunycodeUrlWithoutProtocol() throws Exception {
         String url = "xn--4gbrim.xn--rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
@@ -314,6 +355,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchPunycodeTldThatStartsWithDash() throws Exception {
         String url = "http://xn--fsqu00a.-xn--0zwm56d";
@@ -321,6 +363,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchPunycodeTldThatEndsWithDash() throws Exception {
         String url = "http://xn--fsqu00a.xn--0zwm56d-";
@@ -328,6 +371,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlWithUnicodeDomainName() throws Exception {
         String url = "http://\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -339,6 +383,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlWithUnicodeTld() throws Exception {
         String url = "\uB3C4\uBA54\uC778.\uD55C\uAD6D";
@@ -346,6 +391,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlWithUnicodePath() throws Exception {
         String url = "http://brainstormtech.blogs.fortune.cnn.com/2010/03/11/" +
@@ -354,13 +400,15 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchValidUrlWithInvalidProtocol() throws Exception {
-        String url = "ftp://www.example.com";
+        String url = "invalid://www.example.com";
         assertFalse("Should not match URL with invalid protocol",
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesValidUrlWithPort() throws Exception {
         String url = "http://www.example.com:8080";
@@ -368,6 +416,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlWithPortAndQuery() throws Exception {
         String url = "http://www.example.com:8080/?foo=bar";
@@ -375,6 +424,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlWithTilde() throws Exception {
         String url = "http://www.example.com:8080/~user/?foo=bar";
@@ -382,6 +432,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesProtocolCaseInsensitive() throws Exception {
         String url = "hTtP://android.com";
@@ -389,6 +440,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesUrlStartingWithHttpAndDoesNotHaveTld() throws Exception {
         String url = "http://android/#notld///a/n/d/r/o/i/d&p1=1&p2=2";
@@ -396,6 +448,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchUrlsWithoutProtocolAndWithUnknownTld()
             throws Exception {
@@ -405,13 +458,15 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotPartiallyMatchUnknownProtocol() throws Exception {
-        String url = "ftp://foo.bar/baz";
+        String url = "invalid://foo.bar/baz";
         assertFalse("Should not partially match URL with unknown protocol",
                 Patterns.AUTOLINK_WEB_URL.matcher(url).find());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesValidUrlWithEmoji() throws Exception {
         String url = "Thank\u263A.com";
@@ -419,6 +474,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchUrlsWithEmojiWithoutProtocolAndWithoutKnownTld()
             throws Exception {
@@ -427,6 +483,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchEmailAddress()
             throws Exception {
@@ -435,6 +492,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesDomainNameWithSurrogatePairs() throws Exception {
         String url = "android\uD83C\uDF38.com";
@@ -442,6 +500,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesTldWithSurrogatePairs() throws Exception {
         String url = "http://android.\uD83C\uDF38com";
@@ -449,6 +508,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesPathWithSurrogatePairs() throws Exception {
         String url = "http://android.com/path-with-\uD83C\uDF38?v=\uD83C\uDF38";
@@ -456,6 +516,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchUrlWithExcludedSurrogate() throws Exception {
         String url = "http://android\uD83F\uDFFE.com";
@@ -463,6 +524,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_doesNotMatchUnicodeSpaces() throws Exception {
         String part1 = "http://and";
@@ -493,6 +555,7 @@ public class PatternsTest extends TestCase {
         }
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesDomainNameWithDash() throws Exception {
         String url = "http://a-nd.r-oid.com";
@@ -504,6 +567,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesDomainNameWithUnderscore() throws Exception {
         String url = "http://a_nd.r_oid.com";
@@ -515,6 +579,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesPathAndQueryWithDollarSign() throws Exception {
         String url = "http://android.com/path$?v=$val";
@@ -526,6 +591,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkWebUrl_matchesEmptyPathWithQueryParams() throws Exception {
         String url = "http://android.com?q=v";
@@ -547,6 +613,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.IP_ADDRESS
 
+    @Test
     @SmallTest
     public void testIpPattern() throws Exception {
         boolean t;
@@ -560,6 +627,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.DOMAIN_NAME
 
+    @Test
     @SmallTest
     public void testDomain_matchesPunycodeTld() throws Exception {
         String domain = "xn--fsqu00a.xn--0zwm56d";
@@ -567,6 +635,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_doesNotMatchPunycodeThatStartsWithDash() throws Exception {
         String domain = "xn--fsqu00a.-xn--0zwm56d";
@@ -574,6 +643,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_doesNotMatchPunycodeThatEndsWithDash() throws Exception {
         String domain = "xn--fsqu00a.xn--0zwm56d-";
@@ -581,6 +651,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_doesNotMatchPunycodeLongerThanAllowed() throws Exception {
         String tld = "xn--";
@@ -592,6 +663,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesObsoleteTld() throws Exception {
         String domain = "test.yu";
@@ -599,6 +671,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesWithSubDomain() throws Exception {
         String domain = "mail.example.com";
@@ -606,6 +679,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesWithoutSubDomain() throws Exception {
         String domain = "android.me";
@@ -613,6 +687,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesUnicodeDomainNames() throws Exception {
         String domain = "\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -620,6 +695,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_doesNotMatchInvalidDomain() throws Exception {
         String domain = "__+&42.xer";
@@ -627,6 +703,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesPunycodeArabicDomainName() throws Exception {
         String domain = "xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c";
@@ -634,6 +711,7 @@ public class PatternsTest extends TestCase {
                 Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesDomainNameWithDash() throws Exception {
         String url = "http://a-nd.r-oid.com";
@@ -645,6 +723,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
     }
 
+    @Test
     @SmallTest
     public void testDomain_matchesDomainNameWithUnderscore() throws Exception {
         String url = "http://a_nd.r_oid.com";
@@ -658,6 +737,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.AUTOLINK_EMAIL_ADDRESS
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesShortValidEmail() throws Exception {
         String email = "a@a.co";
@@ -665,6 +745,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesRegularEmail() throws Exception {
         String email = "email@android.com";
@@ -672,6 +753,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesEmailWithMultipleSubdomains() throws Exception {
         String email = "email@e.somelongdomainnameforandroid.abc.uk";
@@ -679,6 +761,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithDot() throws Exception {
         String email = "e.mail@android.com";
@@ -686,6 +769,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithPlus() throws Exception {
         String email = "e+mail@android.com";
@@ -693,6 +777,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithUnderscore() throws Exception {
         String email = "e_mail@android.com";
@@ -700,6 +785,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithDash() throws Exception {
         String email = "e-mail@android.com";
@@ -707,6 +793,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithApostrophe() throws Exception {
         String email = "e'mail@android.com";
@@ -714,6 +801,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithDigits() throws Exception {
         String email = "123@android.com";
@@ -721,6 +809,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesUnicodeLocalPart() throws Exception {
         String email = "\uD604\uAE08\uC601\uC218\uC99D@android.kr";
@@ -728,6 +817,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithEmoji() throws Exception {
         String email = "smiley\u263A@android.com";
@@ -735,6 +825,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartWithSurrogatePairs() throws Exception {
         String email = "\uD83C\uDF38@android.com";
@@ -742,6 +833,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesDomainWithDash() throws Exception {
         String email = "email@an-droid.com";
@@ -749,6 +841,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesUnicodeDomain() throws Exception {
         String email = "email@\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -756,6 +849,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesUnicodeLocalPartAndDomain() throws Exception {
         String email = "\uD604\uAE08\uC601\uC218\uC99D@\uD604\uAE08\uC601\uC218\uC99D.kr";
@@ -763,6 +857,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesDomainWithEmoji() throws Exception {
         String email = "smiley@\u263Aandroid.com";
@@ -770,6 +865,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesDomainWithSurrogatePairs() throws Exception {
         String email = "email@\uD83C\uDF38android.com";
@@ -777,6 +873,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartAndDomainWithSurrogatePairs()
             throws Exception {
@@ -785,6 +882,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchStringWithoutAtSign() throws Exception {
         String email = "android.com";
@@ -792,6 +890,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchPlainString() throws Exception {
         String email = "email";
@@ -799,6 +898,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchStringWithMultipleAtSigns() throws Exception {
         String email = "email@android@android.com";
@@ -806,6 +906,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchEmailWithoutTld() throws Exception {
         String email = "email@android";
@@ -813,6 +914,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchLocalPartEndingWithDot() throws Exception {
         String email = "email.@android.com";
@@ -820,6 +922,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchLocalPartStartingWithDot() throws Exception {
         String email = ".email@android.com";
@@ -827,6 +930,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchDomainStartingWithDash() throws Exception {
         String email = "email@-android.com";
@@ -834,6 +938,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchDomainWithConsecutiveDots() throws Exception {
         String email = "email@android..com";
@@ -841,6 +946,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchEmailWithIpAsDomain() throws Exception {
         String email = "email@127.0.0.1";
@@ -848,6 +954,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_doesNotMatchEmailWithInvalidTld() throws Exception {
         String email = "email@android.c";
@@ -855,6 +962,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesLocalPartUpTo64Chars() throws Exception {
         String localPart = "";
@@ -871,6 +979,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesSubdomainUpTo63Chars() throws Exception {
         String subdomain = "";
@@ -888,6 +997,7 @@ public class PatternsTest extends TestCase {
                 Patterns.AUTOLINK_EMAIL_ADDRESS.matcher(email).matches());
     }
 
+    @Test
     @SmallTest
     public void testAutoLinkEmailAddress_matchesDomainUpTo255Chars() throws Exception {
         String longDomain = "";
@@ -909,6 +1019,7 @@ public class PatternsTest extends TestCase {
 
     // Tests for Patterns.PHONE
 
+    @Test
     @SmallTest
     public void testPhonePattern() throws Exception {
         boolean t;
diff --git a/core/tests/coretests/src/android/util/RecurrenceRuleTest.java b/core/tests/coretests/src/android/util/RecurrenceRuleTest.java
index caa12083fafb..32548b4cff19 100644
--- a/core/tests/coretests/src/android/util/RecurrenceRuleTest.java
+++ b/core/tests/coretests/src/android/util/RecurrenceRuleTest.java
@@ -16,9 +16,17 @@
 
 package android.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.time.Clock;
 import java.time.Instant;
@@ -28,19 +36,18 @@ import java.time.ZonedDateTime;
 import java.util.Iterator;
 
 @SmallTest
-public class RecurrenceRuleTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class RecurrenceRuleTest {
 
     static Clock sOriginalClock;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
         sOriginalClock = RecurrenceRule.sClock;
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
+    @After
+    public void tearDown() throws Exception {
         RecurrenceRule.sClock = sOriginalClock;
     }
 
@@ -48,6 +55,7 @@ public class RecurrenceRuleTest extends TestCase {
         RecurrenceRule.sClock = Clock.fixed(instant, ZoneId.systemDefault());
     }
 
+    @Test
     public void testSimpleMonth() throws Exception {
         setClock(Instant.parse("2015-11-20T10:15:30.00Z"));
         final RecurrenceRule r = new RecurrenceRule(
@@ -68,6 +76,7 @@ public class RecurrenceRuleTest extends TestCase {
                 ZonedDateTime.parse("2015-11-14T00:00:00.00Z")), it.next());
     }
 
+    @Test
     public void testSimpleDays() throws Exception {
         setClock(Instant.parse("2015-01-01T10:15:30.00Z"));
         final RecurrenceRule r = new RecurrenceRule(
@@ -89,6 +98,7 @@ public class RecurrenceRuleTest extends TestCase {
         assertFalse(it.hasNext());
     }
 
+    @Test
     public void testNotRecurring() throws Exception {
         setClock(Instant.parse("2015-01-01T10:15:30.00Z"));
         final RecurrenceRule r = new RecurrenceRule(
@@ -106,6 +116,7 @@ public class RecurrenceRuleTest extends TestCase {
         assertFalse(it.hasNext());
     }
 
+    @Test
     public void testNever() throws Exception {
         setClock(Instant.parse("2015-01-01T10:15:30.00Z"));
         final RecurrenceRule r = RecurrenceRule.buildNever();
@@ -116,6 +127,7 @@ public class RecurrenceRuleTest extends TestCase {
         assertFalse(it.hasNext());
     }
 
+    @Test
     public void testSane() throws Exception {
         final RecurrenceRule r = new RecurrenceRule(
                 ZonedDateTime.parse("1980-01-31T00:00:00.000Z"),
diff --git a/core/tests/coretests/src/android/util/SparseSetArrayTest.java b/core/tests/coretests/src/android/util/SparseSetArrayTest.java
index 3c17486aeb94..1df1090e0343 100644
--- a/core/tests/coretests/src/android/util/SparseSetArrayTest.java
+++ b/core/tests/coretests/src/android/util/SparseSetArrayTest.java
@@ -17,9 +17,13 @@ package android.util;
 
 import static com.google.common.truth.Truth.assertThat;
 
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -29,6 +33,9 @@ import org.junit.runner.RunWith;
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class SparseSetArrayTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
     @Test
     public void testAddAll() {
         final SparseSetArray<Integer> sparseSetArray = new SparseSetArray<>();
@@ -51,6 +58,7 @@ public class SparseSetArrayTest {
     }
 
     @Test
+    @IgnoreUnderRavenwood(reason = "b/315036461")
     public void testCopyConstructor() {
         final SparseSetArray<Integer> sparseSetArray = new SparseSetArray<>();
 
diff --git a/core/tests/coretests/src/android/util/StateSetTest.java b/core/tests/coretests/src/android/util/StateSetTest.java
index b5d62704ba29..dfd1523465ae 100644
--- a/core/tests/coretests/src/android/util/StateSetTest.java
+++ b/core/tests/coretests/src/android/util/StateSetTest.java
@@ -16,16 +16,29 @@
 
 package android.util;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 /**
  * Tests for {@link StateSet}
  */
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = StateSet.class)
+public class StateSetTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
 
-public class StateSetTest extends TestCase {
-    
+    @Test
     @SmallTest
     public void testStateSetPositiveMatches() throws Exception {
          int[] stateSpec = new int[2];
@@ -48,6 +61,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, stateSet));
      }
 
+     @Test
      @SmallTest
      public void testStatesSetMatchMixEmUp() throws Exception {
          int[] stateSpec = new int[2];
@@ -70,6 +84,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, stateSet));
      }
 
+     @Test
      @SmallTest
      public void testStateSetNegativeMatches() throws Exception {
          int[] stateSpec = new int[2];
@@ -92,6 +107,7 @@ public class StateSetTest extends TestCase {
          assertFalse(StateSet.stateSetMatches(stateSpec, stateSet));
      }
 
+     @Test
      @SmallTest
      public void testEmptySetMatchesNegtives() throws Exception {
          int[] stateSpec = {-12345, -6789};
@@ -101,6 +117,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, stateSet2));
      }
 
+     @Test
      @SmallTest
      public void testEmptySetFailsPositives() throws Exception {
          int[] stateSpec = {12345};
@@ -110,6 +127,7 @@ public class StateSetTest extends TestCase {
          assertFalse(StateSet.stateSetMatches(stateSpec, stateSet2));
      }
 
+     @Test
      @SmallTest
      public void testEmptySetMatchesWildcard() throws Exception {
          int[] stateSpec = StateSet.WILD_CARD;
@@ -119,6 +137,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, stateSet2));
      }
 
+     @Test
      @SmallTest
      public void testSingleStatePositiveMatches() throws Exception {
          int[] stateSpec = new int[2];
@@ -135,6 +154,7 @@ public class StateSetTest extends TestCase {
          assertFalse(StateSet.stateSetMatches(stateSpec, state));
      }
 
+     @Test
      @SmallTest
      public void testSingleStateNegativeMatches() throws Exception {
          int[] stateSpec = new int[2];
@@ -151,6 +171,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, state));
      }
 
+     @Test
      @SmallTest
      public void testZeroStateOnlyMatchesDefault() throws Exception {
          int[] stateSpec = new int[3];
@@ -166,6 +187,7 @@ public class StateSetTest extends TestCase {
          assertTrue(StateSet.stateSetMatches(stateSpec, state));
      }
 
+     @Test
      @SmallTest
      public void testNullStateOnlyMatchesDefault() throws Exception {
          int[] stateSpec = new int[3];
diff --git a/core/tests/coretests/src/android/util/apk/SourceStampVerifierTest.java b/core/tests/coretests/src/android/util/apk/SourceStampVerifierTest.java
index e0c583ddc978..48e76f79a928 100644
--- a/core/tests/coretests/src/android/util/apk/SourceStampVerifierTest.java
+++ b/core/tests/coretests/src/android/util/apk/SourceStampVerifierTest.java
@@ -26,12 +26,16 @@ import static org.junit.Assert.assertTrue;
 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
 
 import android.content.Context;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
 
 import androidx.test.core.app.ApplicationProvider;
 
 import libcore.io.Streams;
 
 import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -48,13 +52,21 @@ import java.util.zip.ZipFile;
 
 /** Unit test for {@link android.util.apk.SourceStampVerifier} */
 @RunWith(JUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = SourceStampVerifier.class)
 public class SourceStampVerifierTest {
+    @Rule
+    public final RavenwoodRule mRavenwood = new RavenwoodRule();
 
-    private final Context mContext = ApplicationProvider.getApplicationContext();
+    private Context mContext;
 
     private File mPrimaryApk;
     private File mSecondaryApk;
 
+    @Before
+    public void setUp() throws Exception {
+        mContext = ApplicationProvider.getApplicationContext();
+    }
+
     @After
     public void tearDown() throws Exception {
         if (mPrimaryApk != null) {
diff --git a/core/tests/utiltests/src/android/util/MetadataReaderTest.java b/core/tests/utiltests/src/android/util/MetadataReaderTest.java
index 24e9e0cd38c9..14feed8b89a1 100644
--- a/core/tests/utiltests/src/android/util/MetadataReaderTest.java
+++ b/core/tests/utiltests/src/android/util/MetadataReaderTest.java
@@ -50,13 +50,13 @@ public class MetadataReaderTest {
     private Bundle mData;
 
     @Before
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         mInputStream = getClass().getClassLoader().getResourceAsStream("res/drawable/image.jpg");
         mData = new Bundle();
     }
 
     @After
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         IoUtils.closeQuietly(mInputStream);
     }
 
diff --git a/ravenwood/framework-minus-apex-ravenwood-policies.txt b/ravenwood/framework-minus-apex-ravenwood-policies.txt
index 63f687264990..e417d37280d0 100644
--- a/ravenwood/framework-minus-apex-ravenwood-policies.txt
+++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt
@@ -74,6 +74,7 @@ class android.util.proto.ProtoUtils stubclass
 class android.util.proto.WireTypeMismatchException stubclass
 
 # Misc
+class android.util.BackupUtils stubclass
 class android.util.Dumpable stubclass
 class android.util.DebugUtils stubclass
 class android.util.MathUtils stubclass
diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt
index 0e33d5620d60..99bc88a9d3c7 100644
--- a/ravenwood/ravenwood-annotation-allowed-classes.txt
+++ b/ravenwood/ravenwood-annotation-allowed-classes.txt
@@ -4,12 +4,21 @@ com.android.internal.util.ArrayUtils
 
 android.util.AtomicFile
 android.util.DataUnit
+android.util.DayOfMonthCursor
 android.util.DumpableContainer
 android.util.EventLog
 android.util.IntArray
+android.util.KeyValueListParser
 android.util.LongArray
+android.util.LongArrayQueue
+android.util.LongSparseLongArray
 android.util.LruCache
+android.util.MonthDisplayHelper
+android.util.RecurrenceRule
+android.util.RotationUtils
 android.util.Slog
+android.util.SparseDoubleArray
+android.util.SparseSetArray
 android.util.TimeUtils
 android.util.Xml
 
-- 
GitLab