Merge "Test the listener callback sequence"
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleDef.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleDef.java
index 2c3f96b..8324d35 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleDef.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleDef.java
@@ -217,6 +217,7 @@
     public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
         IModuleListener moduleListener = new ModuleListener(this, listener);
 
+        CLog.d("Running module %s", toString());
         // Setup
         for (ITargetPreparer preparer : mPreparers) {
             String preparerName = preparer.getClass().getCanonicalName();
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmStartOptionsTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmStartOptionsTests.java
index 2c5255e..0a6eb2d 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmStartOptionsTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmStartOptionsTests.java
@@ -28,18 +28,25 @@
     private static final String SINGLE_TASK_ACTIVITY_NAME = "SingleTaskActivity";
 
     public void testDashD() throws Exception {
-        final String[] waitForActivitiesVisible = new String[] {TEST_ACTIVITY_NAME};
-        AmStartLogcatVerifier verifier = new AmStartLogcatVerifier("android.server.cts", TEST_ACTIVITY_NAME);
+        final String activityComponentName =
+                ActivityManagerTestBase.getActivityComponentName(TEST_ACTIVITY_NAME);
+
+        final String[] waitForActivityRecords = new String[] {activityComponentName};
 
         // Run at least 2 rounds to verify that -D works with an existing process.
         // -D could fail in this case if the force stop of process is broken.
+        int prevProcId = -1;
         for (int i = 0; i < 2; i++) {
-            clearLogcat();
             executeShellCommand(getAmStartCmd(TEST_ACTIVITY_NAME) + " -D");
 
-            // visibleOnly=false as the first window popping up will be the debugger window.
-            mAmWmState.computeState(mDevice, false, waitForActivitiesVisible);
-            verifier.verifyDashD();
+            mAmWmState.waitForDebuggerWindowVisible(mDevice, waitForActivityRecords);
+            int procId = mAmWmState.getAmState().getActivityProcId(activityComponentName);
+
+            assertTrue("Invalid ProcId.", procId >= 0);
+            if (i > 0) {
+                assertTrue("Run " + i + " didn't start new proc.", prevProcId != procId);
+            }
+            prevProcId = procId;
         }
     }
 
@@ -53,29 +60,18 @@
 
     private void testDashW(final String entryActivity, final String actualActivity)
             throws Exception {
-        AmStartLogcatVerifier verifier = new AmStartLogcatVerifier("android.server.cts", actualActivity);
-
         // Test cold start
-        startActivityAndVerifyResult(verifier, entryActivity, actualActivity, true);
+        startActivityAndVerifyResult(entryActivity, actualActivity, true);
 
         // Test warm start
         pressHomeButton();
-        startActivityAndVerifyResult(verifier, entryActivity, actualActivity, false);
+        startActivityAndVerifyResult(entryActivity, actualActivity, false);
 
         // Test "hot" start (app already in front)
-        startActivityAndVerifyResult(verifier, entryActivity, actualActivity, false);
+        startActivityAndVerifyResult(entryActivity, actualActivity, false);
     }
 
-    private static final Pattern sNotStartedWarningPattern = Pattern.compile(
-            "Warning: Activity not started(.*)");
-    private static final Pattern sStatusPattern = Pattern.compile(
-            "Status: (.*)");
-    private static final Pattern sActivityPattern = Pattern.compile(
-            "Activity: (.*)");
-    private static final String sStatusOk = "ok";
-
-    private void startActivityAndVerifyResult(
-            final AmStartLogcatVerifier verifier, final String entryActivity,
+    private void startActivityAndVerifyResult(final String entryActivity,
             final String actualActivity, boolean shouldStart) throws Exception {
         clearLogcat();
 
@@ -90,9 +86,17 @@
         verifyShellOutput(result, actualActivity, shouldStart);
 
         // Verify adb logcat log
-        verifier.verifyDashW(shouldStart);
+        verifyLogcat(actualActivity, shouldStart);
     }
 
+    private static final Pattern sNotStartedWarningPattern = Pattern.compile(
+            "Warning: Activity not started(.*)");
+    private static final Pattern sStatusPattern = Pattern.compile(
+            "Status: (.*)");
+    private static final Pattern sActivityPattern = Pattern.compile(
+            "Activity: (.*)");
+    private static final String sStatusOk = "ok";
+
     private void verifyShellOutput(
             final String result, final String activity, boolean shouldStart) {
         boolean warningFound = false;
@@ -129,99 +133,38 @@
         }
     }
 
-    private static final Pattern sStartProcPattern =
-            Pattern.compile("(.+): Start proc (\\d+):(.*) for activity (.*)");
-    private static final Pattern sKillingPattern =
-            Pattern.compile("(.+): Killing (\\d+):(.*)");
-    private static final Pattern sWaitingForDebuggerPattern =
-            Pattern.compile("(.+): Application (.+) is waiting for the debugger (.*)");
     private static final Pattern sDisplayTimePattern =
             Pattern.compile("(.+): Displayed (.*): (\\+{0,1})([0-9]+)ms(.*)");
 
-    private class AmStartLogcatVerifier {
-        private String mPrevProcId;
-        private final String mPackageName;
-        private final String mActivityName;
+    void verifyLogcat(String actualActivityName, boolean shouldStart)
+            throws DeviceNotAvailableException {
+        int displayCount = 0;
+        String activityName = null;
 
-        AmStartLogcatVerifier(String packageName, String activityName) {
-            mPackageName = packageName;
-            mActivityName = activityName;
-        }
+        for (String line : getDeviceLogsForComponent("ActivityManager")) {
+            line = line.trim();
 
-        void verifyDashD() throws DeviceNotAvailableException {
-            boolean prevProcKilled = false;;
-            boolean waitingForDebugger = false;
-            String newProcId = null;
-            final String[] componentNames = new String[] {"ActivityManager", "ActivityThread"};
-
-            for (String line : getDeviceLogsForComponents(componentNames)) {
-                line = line.trim();
-
-                Matcher matcher = sStartProcPattern.matcher(line);
-                if (matcher.matches()) {
-                    final String activity = matcher.group(4);
-                    if (activity.contains(mActivityName)) {
-                        newProcId = matcher.group(2);
-                    }
+            Matcher matcher = sDisplayTimePattern.matcher(line);
+            if (matcher.matches()) {
+                activityName = matcher.group(2);
+                // Ignore activitiy displays from other packages, we don't
+                // want some random activity starts to ruin our test.
+                if (!activityName.startsWith("android.server.cts")) {
                     continue;
                 }
-
-                matcher = sKillingPattern.matcher(line);
-                if (matcher.matches()) {
-                    final String procId = matcher.group(2);
-                    if (procId.equals(mPrevProcId)) {
-                        prevProcKilled = true;
-                    }
-                    continue;
+                if (!shouldStart) {
+                    fail("Shouldn't display anything but displayed " + activityName);
                 }
-
-                matcher = sWaitingForDebuggerPattern.matcher(line);
-                if (matcher.matches()) {
-                    final String packageName = matcher.group(2);
-                    if (packageName.equals(mPackageName)) {
-                        waitingForDebugger = true;
-                    }
-                    continue;
-                }
+                displayCount++;
             }
-
-            assertTrue("Didn't kill exisiting proc " + mPrevProcId + ".",
-                    mPrevProcId == null || prevProcKilled);
-            assertTrue("Didn't start new proc.", newProcId != null);
-            assertTrue("Didn't wait for debugger.", waitingForDebugger);
-
-            mPrevProcId = newProcId;
         }
-
-        void verifyDashW(boolean shouldStart) throws DeviceNotAvailableException {
-            int displayCount = 0;
-            String activityName = null;
-
-            for (String line : getDeviceLogsForComponent("ActivityManager")) {
-                line = line.trim();
-
-                Matcher matcher = sDisplayTimePattern.matcher(line);
-                if (matcher.matches()) {
-                    activityName = matcher.group(2);
-                    // Ignore activitiy displays from other packages, we don't
-                    // want some random activity starts to ruin our test.
-                    if (!activityName.startsWith("android.server.cts")) {
-                        continue;
-                    }
-                    if (!shouldStart) {
-                        fail("Shouldn't display anything but displayed " + activityName);
-                    }
-                    displayCount++;
-                }
-            }
-            final String expectedActivityName = getActivityComponentName(mActivityName);
-            if (shouldStart) {
-                if (displayCount != 1) {
-                    fail("Should display exactly one activity but displayed " + displayCount);
-                } else if (!expectedActivityName.equals(activityName)) {
-                    fail("Should display " + expectedActivityName +
-                            " but displayed " + activityName);
-                }
+        final String expectedActivityName = getActivityComponentName(actualActivityName);
+        if (shouldStart) {
+            if (displayCount != 1) {
+                fail("Should display exactly one activity but displayed " + displayCount);
+            } else if (!expectedActivityName.equals(activityName)) {
+                fail("Should display " + expectedActivityName +
+                        " but displayed " + activityName);
             }
         }
     }
diff --git a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityAndWindowManagersState.java b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityAndWindowManagersState.java
index fd408b0..8d1642b 100644
--- a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityAndWindowManagersState.java
+++ b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityAndWindowManagersState.java
@@ -23,6 +23,7 @@
 import android.server.cts.ActivityManagerState.ActivityStack;
 import android.server.cts.ActivityManagerState.ActivityTask;
 import android.server.cts.WindowManagerState.WindowStack;
+import android.server.cts.WindowManagerState.WindowState;
 import android.server.cts.WindowManagerState.WindowTask;
 
 import java.awt.Rectangle;
@@ -33,6 +34,9 @@
 import static android.server.cts.ActivityManagerTestBase.FREEFORM_WORKSPACE_STACK_ID;
 import static android.server.cts.ActivityManagerTestBase.PINNED_STACK_ID;
 import static android.server.cts.StateLogger.log;
+import static android.server.cts.WindowManagerState.DUMP_MODE_APPS;
+import static android.server.cts.WindowManagerState.DUMP_MODE_VISIBLE;
+import static android.server.cts.WindowManagerState.DUMP_MODE_VISIBLE_APPS;
 
 /** Combined state of the activity manager and window manager. */
 public class ActivityAndWindowManagersState extends Assert {
@@ -107,6 +111,34 @@
     }
 
     /**
+     * Compute AM and WM state of device, wait for the activity records to be added, and
+     * wait for debugger window to show up.
+     *
+     * This should only be used when starting with -D (debugger) option, where we pop up the
+     * waiting-for-debugger window, but real activity window won't show up since we're waiting
+     * for debugger.
+     */
+    void waitForDebuggerWindowVisible(
+            ITestDevice device, String[] waitForActivityRecords) throws Exception {
+        int retriesLeft = 5;
+        do {
+            mAmState.computeState(device);
+            mWmState.computeState(device, DUMP_MODE_VISIBLE);
+            if (shouldWaitForDebuggerWindow() ||
+                    shouldWaitForActivityRecords(waitForActivityRecords)) {
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    log(e.toString());
+                    // Well I guess we are not waiting...
+                }
+            } else {
+                break;
+            }
+        } while (retriesLeft-- > 0);
+    }
+
+    /**
      * Wait for consistent state in AM and WM.
      *
      * @param device test device.
@@ -123,7 +155,8 @@
             // TODO: Get state of AM and WM at the same time to avoid mismatches caused by
             // requesting dump in some intermediate state.
             mAmState.computeState(device);
-            mWmState.computeState(device, visibleOnly);
+            mWmState.computeState(device, visibleOnly?
+                    DUMP_MODE_VISIBLE_APPS : DUMP_MODE_APPS);
             if (shouldWaitForValidStacks(compareTaskAndStackBounds)
                     || shouldWaitForActivities(waitForActivitiesVisible, stackIds)) {
                 log("***Waiting for valid stacks and activities states...");
@@ -236,6 +269,32 @@
         return !allActivityWindowsVisible || !tasksInCorrectStacks;
     }
 
+    private boolean shouldWaitForDebuggerWindow() {
+        List<WindowManagerState.WindowState> matchingWindowStates = new ArrayList<>();
+        mWmState.getMatchingWindowState("android.server.cts", matchingWindowStates);
+        for (WindowState ws : matchingWindowStates) {
+            if (ws.isDebuggerWindow()) {
+                return false;
+            }
+        }
+        log("Debugger window not available yet");
+        return true;
+    }
+
+    private boolean shouldWaitForActivityRecords(String[] waitForActivityRecords) {
+        if (waitForActivityRecords == null || waitForActivityRecords.length == 0) {
+            return false;
+        }
+        // Check if the activity records we're looking for is already added.
+        for (int i = 0; i < waitForActivityRecords.length; i++) {
+            if (!mAmState.isActivityVisible(waitForActivityRecords[i])) {
+                log("ActivityRecord " + waitForActivityRecords[i] + " not visible yet");
+                return true;
+            }
+        }
+        return false;
+    }
+
     ActivityManagerState getAmState() {
         return mAmState;
     }
diff --git a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerState.java b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerState.java
index 5066f5d2..eb2fe11 100644
--- a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerState.java
+++ b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerState.java
@@ -219,6 +219,19 @@
         return false;
     }
 
+    int getActivityProcId(String activityName) {
+        for (ActivityStack stack : mStacks) {
+            for (ActivityTask task : stack.mTasks) {
+               for (Activity activity : task.mActivities) {
+                   if (activity.name.equals(activityName)) {
+                       return activity.procId;
+                   }
+               }
+            }
+        }
+        return -1;
+    }
+
     boolean isHomeActivityVisible() {
         final Activity homeActivity = getHomeActivity();
         return homeActivity != null && homeActivity.visible;
@@ -508,10 +521,13 @@
                 + "mStartingWindowState=(\\S+)");
         private static final Pattern FRONT_OF_TASK_PATTERN = Pattern.compile("frontOfTask=(\\S+) "
                 + "task=TaskRecord\\{(\\S+) #(\\d+) A=(\\S+) U=(\\d+) StackId=(\\d+) sz=(\\d+)\\}");
+        private static final Pattern PROCESS_RECORD_PATTERN = Pattern.compile(
+                "app=ProcessRecord\\{(\\S+) (\\d+):(\\S+)/(.+)\\}");
 
         String name;
         boolean visible;
         boolean frontOfTask;
+        int procId = -1;
 
         private Activity() {
         }
@@ -550,6 +566,15 @@
                     continue;
                 }
 
+                matcher = PROCESS_RECORD_PATTERN.matcher(line);
+                if (matcher.matches()) {
+                    log(line);
+                    final String procIdString = matcher.group(2);
+                    procId = Integer.valueOf(procIdString);
+                    log(procIdString);
+                    continue;
+                }
+
                 matcher = FRONT_OF_TASK_PATTERN.matcher(line);
                 if (matcher.matches()) {
                     log(line);
diff --git a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/WindowManagerState.java b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/WindowManagerState.java
index e6fa3f2..d372435 100644
--- a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/WindowManagerState.java
+++ b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/WindowManagerState.java
@@ -35,7 +35,12 @@
 import static android.server.cts.StateLogger.logE;
 
 public class WindowManagerState {
+    public static final int DUMP_MODE_APPS = 0;
+    public static final int DUMP_MODE_VISIBLE = 1;
+    public static final int DUMP_MODE_VISIBLE_APPS = 2;
+
     private static final String DUMPSYS_WINDOWS_APPS = "dumpsys window -a apps";
+    private static final String DUMPSYS_WINDOWS_VISIBLE = "dumpsys window -a visible";
     private static final String DUMPSYS_WINDOWS_VISIBLE_APPS = "dumpsys window visible-apps";
 
     private static final Pattern sWindowPattern =
@@ -44,6 +49,8 @@
             Pattern.compile("Window #(\\d+) Window\\{([0-9a-fA-F]+) u(\\d+) Starting (.+)\\}\\:");
     private static final Pattern sExitingWindowPattern =
             Pattern.compile("Window #(\\d+) Window\\{([0-9a-fA-F]+) u(\\d+) (.+) EXITING\\}\\:");
+    private static final Pattern sDebuggerWindowPattern =
+            Pattern.compile("Window #(\\d+) Window\\{([0-9a-fA-F]+) u(\\d+) Waiting For Debugger: (.+)\\}\\:");
 
     private static final Pattern sFocusedWindowPattern = Pattern.compile(
             "mCurrentFocus=Window\\{([0-9a-fA-F]+) u(\\d+) (\\S+)\\}");
@@ -63,7 +70,7 @@
 
     private static final Pattern[] sExtractStackExitPatterns = {
             sStackIdPattern, sWindowPattern, sStartingWindowPattern, sExitingWindowPattern,
-            sFocusedWindowPattern, sAppErrorFocusedWindowPattern,
+            sDebuggerWindowPattern, sFocusedWindowPattern, sAppErrorFocusedWindowPattern,
             sWaitingForDebuggerFocusedWindowPattern,
             sFocusedAppPattern, sLastAppTransitionPattern };
 
@@ -77,7 +84,7 @@
     private String mLastTransition = null;
     private final LinkedList<String> mSysDump = new LinkedList();
 
-    void computeState(ITestDevice device, boolean visibleOnly) throws DeviceNotAvailableException {
+    void computeState(ITestDevice device, int dumpMode) throws DeviceNotAvailableException {
         // It is possible the system is in the middle of transition to the right state when we get
         // the dump. We try a few times to get the information we need before giving up.
         int retriesLeft = 3;
@@ -100,10 +107,21 @@
             }
 
             final CollectingOutputReceiver outputReceiver = new CollectingOutputReceiver();
-            final String dumpsysCmd = visibleOnly ?
-                    DUMPSYS_WINDOWS_VISIBLE_APPS : DUMPSYS_WINDOWS_APPS;
+            final String dumpsysCmd;
+            switch (dumpMode) {
+            case DUMP_MODE_APPS:
+                dumpsysCmd = DUMPSYS_WINDOWS_APPS; break;
+            case DUMP_MODE_VISIBLE:
+                dumpsysCmd = DUMPSYS_WINDOWS_VISIBLE; break;
+            case DUMP_MODE_VISIBLE_APPS:
+            default:
+                dumpsysCmd = DUMPSYS_WINDOWS_VISIBLE_APPS; break;
+            }
             device.executeShellCommand(dumpsysCmd, outputReceiver);
             dump = outputReceiver.getOutput();
+            final boolean visibleOnly =
+                    dumpMode == DUMP_MODE_VISIBLE ||
+                    dumpMode == DUMP_MODE_VISIBLE_APPS;
             parseSysDump(dump, visibleOnly);
 
             retry = mWindows.isEmpty() || mFocusedWindow == null || mFocusedApp == null;
@@ -607,6 +625,11 @@
     public static class WindowState extends WindowContainer {
         private static final String TAG = "[WindowState] ";
 
+        private static final int WINDOW_TYPE_NORMAL   = 0;
+        private static final int WINDOW_TYPE_STARTING = 1;
+        private static final int WINDOW_TYPE_EXITING  = 2;
+        private static final int WINDOW_TYPE_DEBUGGER = 3;
+
         private static final String RECT_STR = "\\[(\\d+),(\\d+)\\]\\[(\\d+),(\\d+)\\]";
         private static final Pattern sMainFramePattern = Pattern.compile("mFrame=" + RECT_STR + ".+");
         private static final Pattern sFramePattern =
@@ -624,8 +647,7 @@
 
         private final String mName;
         private final String mAppToken;
-        private final boolean mStarting;
-        private final boolean mExiting;
+        private final int mWindowType;
         private int mDisplayId;
         private int mStackId;
         private int mLayer;
@@ -636,11 +658,11 @@
         private Rectangle mSurfaceInsets = new Rectangle();
         private Rectangle mCrop = new Rectangle();
 
-        private WindowState(Matcher matcher, boolean starting, boolean exiting) {
+
+        private WindowState(Matcher matcher, int windowType) {
             mName = matcher.group(4);
             mAppToken = matcher.group(2);
-            mStarting = starting;
-            mExiting = exiting;
+            mWindowType = windowType;
         }
 
         public String getName() {
@@ -652,11 +674,15 @@
         }
 
         boolean isStartingWindow() {
-            return mStarting;
+            return mWindowType == WINDOW_TYPE_STARTING;
         }
 
         boolean isExitingWindow() {
-            return mExiting;
+            return mWindowType == WINDOW_TYPE_EXITING;
+        }
+
+        boolean isDebuggerWindow() {
+            return mWindowType == WINDOW_TYPE_DEBUGGER;
         }
 
         int getDisplayId() {
@@ -707,18 +733,18 @@
             dump.pop();
 
             final WindowState window;
-            Matcher specialMatcher = sStartingWindowPattern.matcher(line);
-            if (specialMatcher.matches()) {
+            Matcher specialMatcher;
+            if ((specialMatcher = sStartingWindowPattern.matcher(line)).matches()) {
                 log(TAG + "STARTING: " + line);
-                window = new WindowState(specialMatcher, true, false);
+                window = new WindowState(specialMatcher, WINDOW_TYPE_STARTING);
+            } else if ((specialMatcher = sExitingWindowPattern.matcher(line)).matches()) {
+                log(TAG + "EXITING: " + line);
+                window = new WindowState(specialMatcher, WINDOW_TYPE_EXITING);
+            } else if ((specialMatcher = sDebuggerWindowPattern.matcher(line)).matches()) {
+                log(TAG + "DEBUGGER: " + line);
+                window = new WindowState(specialMatcher, WINDOW_TYPE_DEBUGGER);
             } else {
-                specialMatcher = sExitingWindowPattern.matcher(line);
-                if (specialMatcher.matches()) {
-                    log(TAG + "EXITING: " + line);
-                    window = new WindowState(specialMatcher, false, true);
-                } else {
-                    window = new WindowState(matcher, false, false);
-                }
+                window = new WindowState(matcher, WINDOW_TYPE_NORMAL);
             }
 
             window.extract(dump, exitPatterns);
@@ -778,10 +804,20 @@
             }
         }
 
+        private static String getWindowTypeSuffix(int windowType) {
+            switch (windowType) {
+            case WINDOW_TYPE_STARTING: return " STARTING";
+            case WINDOW_TYPE_EXITING: return " EXITING";
+            case WINDOW_TYPE_DEBUGGER: return " DEBUGGER";
+            default: break;
+            }
+            return "";
+        }
+
         @Override
         public String toString() {
             return "WindowState: {" + mAppToken + " " + mName
-                    + (mStarting ? " STARTING" : "") + (mExiting ? " EXITING" : "") + "}"
+                    + getWindowTypeSuffix(mWindowType) + "}"
                     + " cf=" + mContainingFrame + " pf=" + mParentFrame;
         }
     }
diff --git a/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/BaseShortcutManagerHostTest.java b/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/BaseShortcutManagerHostTest.java
index 950050b..fbd344b 100644
--- a/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/BaseShortcutManagerHostTest.java
+++ b/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/BaseShortcutManagerHostTest.java
@@ -46,6 +46,7 @@
     private IBuildInfo mCtsBuild;
 
     protected boolean mIsMultiuserSupported;
+    protected boolean mIsManagedUserSupported;
 
     private ArrayList<Integer> mOriginalUsers;
 
@@ -60,6 +61,13 @@
         assertNotNull(mCtsBuild);  // ensure build has been set before test is run.
 
         mIsMultiuserSupported = getDevice().isMultiUserSupported();
+        if (!mIsMultiuserSupported) {
+            CLog.w("Multi user not supporeted");
+        }
+        mIsManagedUserSupported = getDevice().hasFeature("android.software.managed_users");
+        if (!mIsManagedUserSupported) {
+            CLog.w("Managed users not supporeted");
+        }
 
         if (mIsMultiuserSupported) {
             mOriginalUsers = new ArrayList<>(getDevice().listUsers());
diff --git a/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/ShortcutManagerMultiuserTest.java b/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/ShortcutManagerMultiuserTest.java
index 2ffbadf..a74ab45 100644
--- a/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/ShortcutManagerMultiuserTest.java
+++ b/hostsidetests/shortcuts/hostside/src/android/content/pm/cts/shortcuthost/ShortcutManagerMultiuserTest.java
@@ -33,7 +33,7 @@
     }
 
     public void testManagedUser() throws Exception {
-        if (!mIsMultiuserSupported) {
+        if (!mIsMultiuserSupported || !mIsManagedUserSupported) {
             return;
         }
         // First, create users
diff --git a/hostsidetests/sustainedperf/src/android/SustainedPerformance/cts/SustainedPerformanceHostTest.java b/hostsidetests/sustainedperf/src/android/SustainedPerformance/cts/SustainedPerformanceHostTest.java
index dcbcce1..d12f3db 100644
--- a/hostsidetests/sustainedperf/src/android/SustainedPerformance/cts/SustainedPerformanceHostTest.java
+++ b/hostsidetests/sustainedperf/src/android/SustainedPerformance/cts/SustainedPerformanceHostTest.java
@@ -60,9 +60,11 @@
     public class Dhrystone implements Runnable {
         private boolean modeEnabled;
         private long startTime;
-        private long loopCount = 3000000;
+        private long loopCount = 300000000;
+        private long cpumask = 1;
 
-        public Dhrystone(boolean enabled) {
+        public Dhrystone(boolean enabled, long cm) {
+            cpumask = cm;
             modeEnabled = enabled;
             startTime = System.currentTimeMillis();
         }
@@ -73,7 +75,8 @@
             try {
                 device.executeShellCommand("cd " + DHRYSTONE + " ; chmod 777 dhry");
                 while (true) {
-                    String result = device.executeShellCommand("echo " + loopCount + " | " + DHRYSTONE + "dhry");
+                    String result = device.executeShellCommand("echo " + loopCount
+                          + " | taskset -a " + cpumask + " " + DHRYSTONE + "dhry");
                     if (Math.abs(System.currentTimeMillis() - startTime) >= testDuration) {
                         break;
                     } else if (result.contains("Measured time too small")) {
@@ -191,7 +194,6 @@
         appResultsWithMode.clear();
         dhrystoneResultsWithoutMode.clear();
         dhrystoneResultsWithMode.clear();
-
         /*
          * Run the test without the mode.
          * Start the application and collect stats.
@@ -199,8 +201,8 @@
          */
         setUpEnvironment();
         device.executeShellCommand(START_COMMAND);
-        Thread dhrystone = new Thread(new Dhrystone(false));
-        Thread dhrystone1 = new Thread(new Dhrystone(false));
+        Thread dhrystone = new Thread(new Dhrystone(false, 1));
+        Thread dhrystone1 = new Thread(new Dhrystone(false, 2));
         dhrystone.start();
         dhrystone1.start();
         Thread.sleep(testDuration);
@@ -213,7 +215,6 @@
         dhrystoneResultsWithoutMode.add(0, dhryMin);
         dhrystoneResultsWithoutMode.add(1, dhryMax);
         dhrystoneResultsWithoutMode.add(2, diff);
-
         /*
          * Run the test with the mode.
          * Start the application and collect stats.
@@ -221,8 +222,8 @@
          */
         setUpEnvironment();
         device.executeShellCommand(START_COMMAND_MODE);
-        dhrystone = new Thread(new Dhrystone(true));
-        dhrystone1 = new Thread(new Dhrystone(true));
+        dhrystone = new Thread(new Dhrystone(true, 1));
+        dhrystone1 = new Thread(new Dhrystone(true, 2));
         dhrystone.start();
         dhrystone1.start();
         Thread.sleep(testDuration);
diff --git a/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java b/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
index ee44f8a..a41f7c5 100644
--- a/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
+++ b/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
@@ -27,6 +27,7 @@
 import android.os.Message;
 import android.os.SystemClock;
 import android.print.PrintDocumentAdapter;
+import android.support.test.rule.ActivityTestRule;
 import android.test.InstrumentationTestCase;
 import android.util.DisplayMetrics;
 import android.view.View;
@@ -88,6 +89,11 @@
     private InstrumentationTestCase mTest;
 
     /**
+     * The test rule that this class is being used in. Used for runTestOnUiThread.
+     */
+    private ActivityTestRule mActivityTestRule;
+
+    /**
      * The WebView that calls will be made on.
      */
     private WebView mWebView;
@@ -101,8 +107,10 @@
      *
      * @param test The test in which this is being run.
      * @param webView The webView that the methods should call.
-     * @see loadUrlAndWaitForCompletion
+     * @see #loadDataAndWaitForCompletion(String, String, String)
+     * @deprecated Use {@link WebViewOnUiThread#WebViewOnUiThread(ActivityTestRule, WebView)}
      */
+    @Deprecated
     public WebViewOnUiThread(InstrumentationTestCase test, WebView webView) {
         mTest = test;
         mWebView = webView;
@@ -119,6 +127,29 @@
     }
 
     /**
+     * Initializes the webView with a WebViewClient, WebChromeClient,
+     * and PictureListener to prepare for loadUrlAndWaitForCompletion.
+     *
+     * A new WebViewOnUiThread should be called during setUp so as to
+     * reinitialize between calls.
+     *
+     * @param activityTestRule The test rule in which this is being run.
+     * @param webView The webView that the methods should call.
+     * @see #loadDataAndWaitForCompletion(String, String, String)
+     */
+    public WebViewOnUiThread(ActivityTestRule activityTestRule, WebView webView) {
+        mActivityTestRule = activityTestRule;
+        mWebView = webView;
+        final WebViewClient webViewClient = new WaitForLoadedClient(this);
+        final WebChromeClient webChromeClient = new WaitForProgressClient(this);
+        runOnUiThread(() -> {
+            mWebView.setWebViewClient(webViewClient);
+            mWebView.setWebChromeClient(webChromeClient);
+            mWebView.setPictureListener(new WaitForNewPicture());
+        });
+    }
+
+    /**
      * Called after a test is complete and the WebView should be disengaged from
      * the tests.
      */
@@ -847,7 +878,8 @@
      * a test failure. If this is already the UI thread then it runs
      * the code immediately.
      *
-     * @see runTestOnUiThread
+     * @see InstrumentationTestCase#runTestOnUiThread(Runnable)
+     * @see ActivityTestRule#runOnUiThread(Runnable)
      * @param r The code to run in the UI thread
      */
     public void runOnUiThread(Runnable r) {
@@ -855,7 +887,11 @@
             if (isUiThread()) {
                 r.run();
             } else {
-                mTest.runTestOnUiThread(r);
+                if (mActivityTestRule != null) {
+                    mActivityTestRule.runOnUiThread(r);
+                } else {
+                    mTest.runTestOnUiThread(r);
+                }
             }
         } catch (Throwable t) {
             Assert.fail("Unexpected error while running on UI thread: "
diff --git a/tests/tests/graphics/AndroidManifest.xml b/tests/tests/graphics/AndroidManifest.xml
index f14506f..324c440 100644
--- a/tests/tests/graphics/AndroidManifest.xml
+++ b/tests/tests/graphics/AndroidManifest.xml
@@ -50,7 +50,8 @@
 
         <activity android:name="android.opengl.cts.OpenGlEsVersionCtsActivity"/>
 
-        <activity android:name="android.graphics.drawable.cts.DrawableStubActivity"/>
+        <activity android:name="android.graphics.drawable.cts.DrawableStubActivity"
+                  android:theme="@style/WhiteBackgroundNoWindowAnimation"/>
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/tests/graphics/res/drawable/animated_vector_favorite.xml b/tests/tests/graphics/res/drawable/animated_vector_favorite.xml
new file mode 100644
index 0000000..8f99a28
--- /dev/null
+++ b/tests/tests/graphics/res/drawable/animated_vector_favorite.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2016 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<animated-vector xmlns:aapt="http://schemas.android.com/aapt"
+                 xmlns:android="http://schemas.android.com/apk/res/android">
+    <aapt:attr name="android:drawable">
+        <vector xmlns:android="http://schemas.android.com/apk/res/android"
+                android:height="128dp"
+                android:width="128dp"
+                android:viewportHeight="480"
+                android:viewportWidth="480" >
+
+            <group
+                    android:name="root"
+                    android:translateX="240.0"
+                    android:translateY="240.0" >
+                <path
+                        android:name="favorite"
+                        android:fillColor="#ff000000"
+                        android:strokeWidth="2"
+                        android:pathData="M2.100006104,-6
+                C0.1449127197,-6,1.600006104,-5.975006104,0,-5.975006104
+                C-1.574996948,-5.975006104,0.00309753418,-6-1.949996948-6
+                C-4.492996216,-6,-5.949996948,-3.718399048,-5.949996948,-1.149993896
+                C-5.949996948,2.379302979,-5.699996948,5.100006104,0,5.100006104
+                C5.699996948,5.100006104,6,2.379302979,6,-1.149993896
+                C6,-3.718399048,4.643005371-6,2.100006104-6" />
+            </group>
+
+        </vector>
+    </aapt:attr>
+
+    <target android:name="favorite">
+        <aapt:attr name="android:animation">
+            <set>
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="pathData"
+                        android:valueFrom="@string/round_box"
+                        android:valueTo="@string/heart"
+                        android:valueType="pathType" />
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="fillAlpha"
+                        android:valueFrom="1.0"
+                        android:valueTo="0.5" />
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="strokeAlpha"
+                        android:valueFrom="1.0"
+                        android:valueTo="0.1" />
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="strokeColor"
+                        android:valueFrom="#FF0000FF"
+                        android:valueTo="#FF00FF00" />
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="fillColor"
+                        android:valueFrom="#FFFF0000"
+                        android:valueTo="#FF00FF00" />
+            </set>
+        </aapt:attr>
+    </target>
+
+    <target android:name="root">
+        <aapt:attr name="android:animation">
+            <set>
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="scaleX"
+                        android:valueFrom="5"
+                        android:valueTo="20" />
+                <objectAnimator
+                        android:duration="3000"
+                        android:propertyName="scaleY"
+                        android:valueFrom="5"
+                        android:valueTo="20" />
+            </set>
+        </aapt:attr>
+    </target>
+
+</animated-vector>
\ No newline at end of file
diff --git a/tests/tests/graphics/res/layout/fixed_sized_imageview.xml b/tests/tests/graphics/res/layout/fixed_sized_imageview.xml
new file mode 100644
index 0000000..ec1bb71
--- /dev/null
+++ b/tests/tests/graphics/res/layout/fixed_sized_imageview.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             android:layout_width="match_parent"
+             android:layout_height="match_parent">
+
+    <ImageView
+            android:id="@+id/imageview"
+            android:layout_width="@dimen/imageview_fixed_size"
+            android:layout_height="@dimen/imageview_fixed_size"
+            android:layerType="hardware"
+            android:src="@drawable/animated_vector_favorite" />
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/tests/graphics/res/values/dimens.xml b/tests/tests/graphics/res/values/dimens.xml
index bae216f..46b5a37 100755
--- a/tests/tests/graphics/res/values/dimens.xml
+++ b/tests/tests/graphics/res/values/dimens.xml
@@ -39,5 +39,9 @@
     <item name="frac25610pperc" type="dimen" format="fraction">25610%p</item>
     <item name="frac6553510pperc" type="dimen" format="fraction">6553510%p</item>
     <item name="frac6553610pperc" type="dimen" format="fraction">6553610%p</item>
+
+    <!-- Size of the image view in AVD test. Choosing a size of 90px to make sure it also works on
+    watches. -->
+    <dimen name="imageview_fixed_size">90px</dimen>
 </resources>
 
diff --git a/tests/tests/graphics/res/values/strings.xml b/tests/tests/graphics/res/values/strings.xml
index 8208b19..e599d8a 100644
--- a/tests/tests/graphics/res/values/strings.xml
+++ b/tests/tests/graphics/res/values/strings.xml
@@ -177,4 +177,8 @@
 I think so, so how about double this string, like copy and paste! </string>
     <string name="rectangle200">"M 0,0 l 200,0 l 0, 200 l -200, 0 z"</string>
     <string name="twoLinePathData">"M 0,0 v 100 M 0,0 h 100"</string>
+    <string name="round_box">"m2.10001,-6c-1.9551,0 -0.5,0.02499 -2.10001,0.02499c-1.575,0 0.0031,-0.02499 -1.95,-0.02499c-2.543,0 -4,2.2816 -4,4.85001c0,3.52929 0.25,6.25 5.95,6.25c5.7,0 6,-2.72071 6,-6.25c0,-2.56841 -1.35699,-4.85001 -3.89999,-4.85001"</string>
+    <string name="heart">"m4.5,-7c-1.95509,0 -3.83009,1.26759 -4.5,3c-0.66991,-1.73241 -2.54691,-3 -4.5,-3c-2.543,0 -4.5,1.93159 -4.5,4.5c0,3.5293 3.793,6.2578 9,11.5c5.207,-5.2422 9,-7.9707 9,-11.5c0,-2.56841 -1.957,-4.5 -4.5,-4.5"</string>
+    <string name="last_screenshot">last_screenshot</string>
+    <string name="current_screenshot">current_screenshot</string>
 </resources>
diff --git a/tests/tests/graphics/res/values/styles.xml b/tests/tests/graphics/res/values/styles.xml
index 31ed175..6991be6 100644
--- a/tests/tests/graphics/res/values/styles.xml
+++ b/tests/tests/graphics/res/values/styles.xml
@@ -166,6 +166,17 @@
         <item name="themeType">0</item>
     </style>
 
+    <style name="WhiteBackgroundNoWindowAnimation"
+           parent="@android:style/Theme.Holo.NoActionBar.Fullscreen">
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowFullscreen">true</item>
+        <item name="android:windowOverscan">true</item>
+        <item name="android:fadingEdge">none</item>
+        <item name="android:windowBackground">@android:color/white</item>
+        <item name="android:windowContentTransitions">false</item>
+        <item name="android:windowAnimationStyle">@null</item>
+    </style>
+
     <style name="Theme_NoSwipeDismiss">
         <item name="android:windowSwipeToDismiss">false</item>
     </style>
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java
new file mode 100644
index 0000000..fcd1fed
--- /dev/null
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics.drawable.cts;
+
+import android.app.Activity;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Rect;
+import android.graphics.cts.R;
+import android.graphics.drawable.AnimatedVectorDrawable;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.view.View;
+import android.widget.ImageView;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static android.graphics.drawable.cts.AnimatedVectorDrawableTest.saveVectorDrawableIntoPNG;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+@MediumTest
+@RunWith(Parameterized.class)
+public class AnimatedVectorDrawableParameterizedTest {
+    @Rule
+    public ActivityTestRule<DrawableStubActivity> mActivityRule =
+            new ActivityTestRule<>(DrawableStubActivity.class);
+
+    private static final int IMAGE_WIDTH = 64;
+    private static final int IMAGE_HEIGHT = 64;
+    private static final long MAX_TIMEOUT_MS = 1000;
+
+    private Activity mActivity = null;
+    private Resources mResources = null;
+    private final int mLayerType;
+
+    @Parameterized.Parameters
+    public static Object[] data() {
+        return new Object[] {
+                View.LAYER_TYPE_HARDWARE,
+                View.LAYER_TYPE_NONE,
+                View.LAYER_TYPE_SOFTWARE
+        };
+    }
+
+    public AnimatedVectorDrawableParameterizedTest(final int layerType) throws Throwable {
+        mLayerType = layerType;
+    }
+
+    @Before
+    public void setup() {
+        mActivity = mActivityRule.getActivity();
+        mResources = mActivity.getResources();
+    }
+
+    @Test
+    public void testAnimationOnLayer() throws Throwable {
+        final AnimatedVectorDrawableTest.MyCallback callback
+                = new AnimatedVectorDrawableTest.MyCallback();
+        final Rect imageViewRect = new Rect();
+        final int size = mResources.getDimensionPixelSize(R.dimen.imageview_fixed_size);
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(R.layout.fixed_sized_imageview);
+            final ImageView imageView = (ImageView) mActivity.findViewById(R.id.imageview);
+            imageView.setLayerType(mLayerType, null);
+            AnimatedVectorDrawable avd = (AnimatedVectorDrawable) imageView.getDrawable();
+            avd.registerAnimationCallback(callback);
+            int[] locationOnScreen = new int[2];
+            imageView.getLocationOnScreen(locationOnScreen);
+            imageViewRect.set(locationOnScreen[0], locationOnScreen[1],
+                    locationOnScreen[0] + size, locationOnScreen[1] + size);
+            avd.start();
+        });
+        callback.waitForStart();
+
+        // Wait another few frames to make sure that RT has started and rendered the animation, and
+        // the frame buffer with the started animation is being rendered on screen.
+        waitWhilePumpingFrames(5, mActivity.findViewById(R.id.imageview), 200);
+        Bitmap lastScreenShot = null;
+        int counter = 0;
+        while (!callback.endIsCalled()) {
+            // Take a screen shot every 50ms, and compare with previous screenshot for the ImageView
+            // content, to make sure the AVD is animating when set on HW layer.
+            Bitmap screenShot = InstrumentationRegistry.getInstrumentation().getUiAutomation()
+                    .takeScreenshot();
+            if (callback.endIsCalled()) {
+                // Animation already ended, the screenshot may not contain valid animation content,
+                // skip the comparison.
+                break;
+            }
+            counter++;
+            boolean isIdentical = isAlmostIdenticalInRect(screenShot, lastScreenShot, imageViewRect);
+            if (isIdentical) {
+                saveVectorDrawableIntoPNG(screenShot,
+                        mResources.getString(R.string.current_screenshot));
+                saveVectorDrawableIntoPNG(lastScreenShot,
+                        mResources.getString(R.string.last_screenshot));
+                fail("Two consecutive screenshots of AVD are identical, AVD is " +
+                        "likely not animating");
+            }
+            lastScreenShot = screenShot;
+
+            // Wait 50ms before the next screen shot. If animation ended during the wait, exit the
+            // loop.
+            if (callback.waitForEnd(50)) {
+                break;
+            }
+        }
+        // In this test, we want to make sure that we at least have 5 screenshots.
+        assertTrue(counter >= 5);
+    }
+
+    // Pump frames by repeatedly invalidating the given view. Return true if successfully pumped
+    // the given number of frames before timeout, false otherwise.
+    private boolean waitWhilePumpingFrames(int frameCount, final View view, long timeout)
+            throws Throwable {
+        final CountDownLatch frameLatch = new CountDownLatch(frameCount);
+        mActivityRule.runOnUiThread(() -> {
+            view.getViewTreeObserver().addOnPreDrawListener(() -> {
+                if (frameLatch.getCount() > 0) {
+                    frameLatch.countDown();
+                    view.postInvalidate();
+                }
+                return true;
+            });
+        });
+        return frameLatch.await(timeout, TimeUnit.MILLISECONDS);
+    }
+
+    @Test
+    public void testSingleFrameAnimation() throws Throwable {
+        int resId = R.drawable.avd_single_frame;
+        final AnimatedVectorDrawable d1 =
+                (AnimatedVectorDrawable) mResources.getDrawable(resId);
+        // The AVD has a duration as 16ms.
+        mActivityRule.runOnUiThread(() -> {
+            Bitmap bitmap =
+                    Bitmap.createBitmap(IMAGE_WIDTH, IMAGE_HEIGHT, Bitmap.Config.ARGB_8888);
+            Canvas canvas = new Canvas(bitmap);
+
+            mActivity.setContentView(R.layout.animated_vector_drawable_source);
+            ImageView imageView = (ImageView) mActivity.findViewById(R.id.avd_view);
+            imageView.setLayerType(mLayerType, null);
+            imageView.setImageDrawable(d1);
+            d1.start();
+            d1.stop();
+            d1.setBounds(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
+            bitmap.eraseColor(0);
+            d1.draw(canvas);
+            int endColor = bitmap.getPixel(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
+            assertEquals("Center point's color must be green", 0xFF00FF00, endColor);
+        });
+    }
+
+    @Test
+    public void testEmptyAnimatorSet() throws Throwable {
+        int resId = R.drawable.avd_empty_animator;
+        final AnimatedVectorDrawableTest.MyCallback callback =
+                new AnimatedVectorDrawableTest.MyCallback();
+        final AnimatedVectorDrawable d1 =
+                (AnimatedVectorDrawable) mResources.getDrawable(resId);
+        d1.registerAnimationCallback(callback);
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(R.layout.animated_vector_drawable_source);
+            ImageView imageView = (ImageView) mActivity.findViewById(R.id.avd_view);
+            imageView.setLayerType(mLayerType, null);
+            imageView.setImageDrawable(d1);
+            d1.registerAnimationCallback(callback);
+            d1.start();
+        });
+        Assert.assertTrue(callback.waitForStart());
+        AnimatedVectorDrawableTest.waitForAVDStop(callback, MAX_TIMEOUT_MS);
+        // Check that the AVD with empty AnimatorSet has finished
+        callback.assertEnded(true);
+        callback.assertAVDRuntime(0, TimeUnit.MILLISECONDS.toNanos(64)); // 4 frames
+    }
+
+    // Does a fuzzy comparison between two images in the given rect. Returns true if the rect area
+    // is within acceptable delta, false otherwise.
+    private static boolean isAlmostIdenticalInRect(Bitmap image1, Bitmap image2, Rect rangeRect) {
+        if (image1 == null || image2 == null) {
+            return false;
+        }
+        for (int x = rangeRect.left; x < rangeRect.right; x++) {
+            for (int y = rangeRect.top; y < rangeRect.bottom; y++) {
+                if (image1.getPixel(x, y) != image2.getPixel(x, y)) {
+                    return false;
+                }
+                int color1 = image1.getPixel(x, y);
+                int color2 = image2.getPixel(x, y);
+                int rDiff = Math.abs(Color.red(color1) - Color.red(color2));
+                int gDiff = Math.abs(Color.green(color1) - Color.green(color2));
+                int bDiff = Math.abs(Color.blue(color1) - Color.blue(color2));
+                if (rDiff + gDiff + bDiff > 8) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+}
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableTest.java
index 4d52d7f..22a9e3d 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableTest.java
@@ -16,6 +16,7 @@
 
 package android.graphics.drawable.cts;
 
+import android.app.Activity;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -28,14 +29,18 @@
 import android.graphics.drawable.AnimatedVectorDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Drawable.ConstantState;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.Xml;
 import android.widget.ImageView;
 
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -43,9 +48,15 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 
-import static java.lang.Thread.sleep;
+import static junit.framework.Assert.fail;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
-public class AnimatedVectorDrawableTest extends ActivityInstrumentationTestCase2<DrawableStubActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class AnimatedVectorDrawableTest {
     private static final String LOGTAG = AnimatedVectorDrawableTest.class.getSimpleName();
 
     private static final int IMAGE_WIDTH = 64;
@@ -54,28 +65,30 @@
     private static final long MAX_START_TIMEOUT_MS = 5000;
     private static final int MS_TO_NS = 1000000;
 
-    private DrawableStubActivity mActivity;
+    @Rule
+    public ActivityTestRule<DrawableStubActivity> mActivityRule =
+            new ActivityTestRule<DrawableStubActivity>(DrawableStubActivity.class);
+    private Activity mActivity;
     private Resources mResources;
     private static final boolean DBG_DUMP_PNG = false;
     private final int mResId = R.drawable.animation_vector_drawable_grouping_1;
     private final int mLayoutId = R.layout.animated_vector_drawable_source;
     private final int mImageViewId = R.id.avd_view;
 
-
-    public AnimatedVectorDrawableTest() {
-        super(DrawableStubActivity.class);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        mActivity = getActivity();
+    @Before
+    public void setup() {
+        mActivity = mActivityRule.getActivity();
         mResources = mActivity.getResources();
     }
 
     // This is only for debugging or golden image (re)generation purpose.
     private void saveVectorDrawableIntoPNG(Bitmap bitmap, int resId) throws IOException {
+        String originalFilePath = mResources.getString(resId);
+        saveVectorDrawableIntoPNG(bitmap, originalFilePath);
+    }
+
+    static void saveVectorDrawableIntoPNG(Bitmap bitmap, String filePath)
+            throws IOException {
         // Save the image to the disk.
         FileOutputStream out = null;
         try {
@@ -84,8 +97,7 @@
             if (!folder.exists()) {
                 folder.mkdir();
             }
-            String originalFilePath = mResources.getString(resId);
-            File originalFile = new File(originalFilePath);
+            File originalFile = new File(filePath);
             String fileFullName = originalFile.getName();
             String fileTitle = fileFullName.substring(0, fileFullName.lastIndexOf("."));
             String outputFilename = outputFolder + fileTitle + "_golden.png";
@@ -106,7 +118,7 @@
         }
     }
 
-    @MediumTest
+    @Test
     public void testInflate() throws Exception {
         // Setup AnimatedVectorDrawable from xml file
         XmlPullParser parser = mResources.getXml(mResId);
@@ -138,62 +150,7 @@
         }
     }
 
-    @MediumTest
-    public void testSingleFrameAnimation() throws InterruptedException {
-        int resId = R.drawable.avd_single_frame;
-        final MyCallback callback = new MyCallback();
-        final AnimatedVectorDrawable d1 =
-                (AnimatedVectorDrawable) mResources.getDrawable(resId);
-        // The AVD has a duration as 16ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                Bitmap bitmap =
-                        Bitmap.createBitmap(IMAGE_WIDTH, IMAGE_HEIGHT, Bitmap.Config.ARGB_8888);
-                Canvas canvas = new Canvas(bitmap);
-
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                imageView.setImageDrawable(d1);
-                d1.start();
-                d1.stop();
-                d1.setBounds(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
-                bitmap.eraseColor(0);
-                d1.draw(canvas);
-                int endColor = bitmap.getPixel(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
-                assertEquals("Center point's color must be green", 0xFF00FF00, endColor);
-                callback.notifyStarted();
-            }
-        });
-        callback.waitForStart();
-    }
-
-    @SmallTest
-    public void testEmptyAnimatorSet() throws InterruptedException {
-        int resId = R.drawable.avd_empty_animator;
-        final MyCallback callback = new MyCallback();
-        final AnimatedVectorDrawable d1 =
-                (AnimatedVectorDrawable) mResources.getDrawable(resId);
-        d1.registerAnimationCallback(callback);
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                imageView.setImageDrawable(d1);
-                d1.registerAnimationCallback(callback);
-                d1.start();
-                callback.notifyStarted();
-            }
-        });
-        callback.waitForStart();
-        waitForAVDStop(callback, MAX_TIMEOUT_MS);
-        // Check that the AVD with empty AnimatorSet has finished
-        callback.assertEnded(true);
-        callback.assertAVDRuntime(0, 64 * MS_TO_NS); // 4 frames
-    }
-
-    @SmallTest
+    @Test
     public void testGetChangingConfigurations() {
         AnimatedVectorDrawable avd = new AnimatedVectorDrawable();
         ConstantState constantState = avd.getConstantState();
@@ -217,7 +174,7 @@
         assertEquals(0xffff,  avd.getChangingConfigurations());
     }
 
-    @SmallTest
+    @Test
     public void testGetConstantState() {
         AnimatedVectorDrawable AnimatedVectorDrawable = new AnimatedVectorDrawable();
         ConstantState constantState = AnimatedVectorDrawable.getConstantState();
@@ -230,7 +187,7 @@
         assertEquals(1, constantState.getChangingConfigurations());
     }
 
-    @SmallTest
+    @Test
     public void testMutate() {
         AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
         AnimatedVectorDrawable d2 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
@@ -258,7 +215,7 @@
         assertEquals(originalAlpha, d3.getAlpha());
     }
 
-    @SmallTest
+    @Test
     public void testGetOpacity() {
         AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
         assertEquals("Default is translucent", PixelFormat.TRANSLUCENT, d1.getOpacity());
@@ -266,7 +223,7 @@
         assertEquals("Still translucent", PixelFormat.TRANSLUCENT, d1.getOpacity());
     }
 
-    @SmallTest
+    @Test
     public void testColorFilter() {
         PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
         AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
@@ -275,55 +232,45 @@
         assertEquals(filter, d1.getColorFilter());
     }
 
-    @MediumTest
-    public void testReset() {
+    @Test
+    public void testReset() throws Throwable {
         final MyCallback callback = new MyCallback();
         final AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                d1.registerAnimationCallback(callback);
-                d1.start();
-                d1.reset();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            d1.registerAnimationCallback(callback);
+            d1.start();
+            d1.reset();
         });
         waitForAVDStop(callback, MAX_TIMEOUT_MS);
         assertFalse(d1.isRunning());
 
     }
 
-    @MediumTest
-    public void testStop() {
+    @Test
+    public void testStop() throws Throwable {
         final MyCallback callback = new MyCallback();
         final AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) mResources.getDrawable(mResId);
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                d1.registerAnimationCallback(callback);
-                d1.start();
-                d1.stop();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            d1.registerAnimationCallback(callback);
+            d1.start();
+            d1.stop();
         });
         waitForAVDStop(callback, MAX_TIMEOUT_MS);
         assertFalse(d1.isRunning());
     }
 
-    @MediumTest
-    public void testAddCallbackBeforeStart() throws InterruptedException {
+    @Test
+    public void testAddCallbackBeforeStart() throws Throwable {
         final MyCallback callback = new MyCallback();
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
-                d1.registerAnimationCallback(callback);
-                d1.start();
-                callback.notifyStarted();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mLayoutId);
+            ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
+            AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
+            d1.registerAnimationCallback(callback);
+            d1.start();
         });
         callback.waitForStart();
         waitForAVDStop(callback, MAX_TIMEOUT_MS);
@@ -331,23 +278,19 @@
         callback.assertEnded(true);
     }
 
-    @MediumTest
-    public void testAddCallbackAfterTrigger() throws InterruptedException {
+    @Test
+    public void testAddCallbackAfterTrigger() throws Throwable {
         final MyCallback callback = new MyCallback();
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
-                // This reset call can enforce the AnimatorSet is setup properly in AVD, when
-                // running on UI thread.
-                d1.reset();
-                d1.registerAnimationCallback(callback);
-                d1.start();
-                callback.notifyStarted();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mLayoutId);
+            ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
+            AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
+            // This reset call can enforce the AnimatorSet is setup properly in AVD, when
+            // running on UI thread.
+            d1.reset();
+            d1.registerAnimationCallback(callback);
+            d1.start();
         });
         callback.waitForStart();
         waitForAVDStop(callback, MAX_TIMEOUT_MS);
@@ -356,20 +299,16 @@
         callback.assertEnded(true);
     }
 
-    @MediumTest
-    public void testAddCallbackAfterStart() throws InterruptedException {
+    @Test
+    public void testAddCallbackAfterStart() throws Throwable {
         final MyCallback callback = new MyCallback();
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
-                d1.start();
-                d1.registerAnimationCallback(callback);
-                callback.notifyStarted();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mLayoutId);
+            ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
+            AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
+            d1.start();
+            d1.registerAnimationCallback(callback);
         });
         callback.waitForStart();
 
@@ -380,21 +319,17 @@
         callback.assertAVDRuntime(0, 400 * MS_TO_NS); // 4 times of the duration of the AVD.
     }
 
-    @MediumTest
-    public void testRemoveCallback() throws InterruptedException {
+    @Test
+    public void testRemoveCallback() throws Throwable {
         final MyCallback callback = new MyCallback();
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
-                d1.registerAnimationCallback(callback);
-                assertTrue(d1.unregisterAnimationCallback(callback));
-                d1.start();
-                callback.notifyStarted();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mLayoutId);
+            ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
+            AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
+            d1.registerAnimationCallback(callback);
+            assertTrue(d1.unregisterAnimationCallback(callback));
+            d1.start();
         });
         callback.waitForStart();
 
@@ -403,22 +338,18 @@
         callback.assertEnded(false);
     }
 
-    @MediumTest
-    public void testClearCallback() throws InterruptedException {
+    @Test
+    public void testClearCallback() throws Throwable {
         final MyCallback callback = new MyCallback();
 
         // The AVD has a duration as 100ms.
-        mActivity.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mActivity.setContentView(mLayoutId);
-                ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
-                AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
-                d1.registerAnimationCallback(callback);
-                d1.clearAnimationCallbacks();
-                d1.start();
-                callback.notifyStarted();
-            }
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mLayoutId);
+            ImageView imageView = (ImageView) mActivity.findViewById(mImageViewId);
+            AnimatedVectorDrawable d1 = (AnimatedVectorDrawable) imageView.getDrawable();
+            d1.registerAnimationCallback(callback);
+            d1.clearAnimationCallbacks();
+            d1.start();
         });
         callback.waitForStart();
 
@@ -429,7 +360,7 @@
 
     // The time out is expected when the listener is removed successfully.
     // Such that we don't get the end event.
-    private void waitForAVDStop(MyCallback callback, long timeout) {
+    static void waitForAVDStop(MyCallback callback, long timeout) {
         try {
             callback.waitForEnd(timeout);
         } catch (InterruptedException e) {
@@ -440,7 +371,7 @@
 
     // Now this class can not only listen to the events, but also synchronize the key events,
     // logging the event timestamp, and centralize some assertions.
-    class MyCallback extends Animatable2.AnimationCallback {
+    static class MyCallback extends Animatable2.AnimationCallback {
         private boolean mStarted = false;
         private boolean mEnded = false;
 
@@ -455,39 +386,50 @@
         // Each sub test should have its own lock.
         private final Object mStartLock = new Object();
 
-        public void waitForEnd(long timeoutMs) throws InterruptedException {
+        public boolean waitForEnd(long timeoutMs) throws InterruptedException {
             synchronized (mEndLock) {
-                mEndLock.wait(timeoutMs);
+                if (!mEnded) {
+                    // Return immediately if the AVD has already ended.
+                    mEndLock.wait(timeoutMs);
+                }
+                return mEnded;
             }
         }
 
-        public void waitForStart() throws InterruptedException {
+        public boolean waitForStart() throws InterruptedException {
             synchronized(mStartLock) {
-                mStartLock.wait(MAX_START_TIMEOUT_MS);
-            }
-        }
-
-        public void notifyStarted() {
-            mStartNs = System.nanoTime();
-            synchronized(mStartLock) {
-                mStartLock.notify();
+                if (!mStarted) {
+                    // Return immediately if the AVD has already started.
+                    mStartLock.wait(MAX_START_TIMEOUT_MS);
+                }
+                return mStarted;
             }
         }
 
         @Override
         public void onAnimationStart(Drawable drawable) {
-            mStarted = true;
+            mStartNs = System.nanoTime();
+            synchronized(mStartLock) {
+                mStarted = true;
+                mStartLock.notify();
+            }
         }
 
         @Override
         public void onAnimationEnd(Drawable drawable) {
             mEndNs = System.nanoTime();
-            mEnded = true;
             synchronized (mEndLock) {
+                mEnded = true;
                 mEndLock.notify();
             }
         }
 
+        public boolean endIsCalled() {
+            synchronized (mEndLock) {
+                return mEnded;
+            }
+        }
+
         public void assertStarted(boolean started) {
             assertEquals(started, mStarted);
         }
diff --git a/tests/tests/print/src/android/print/cts/BasePrintTest.java b/tests/tests/print/src/android/print/cts/BasePrintTest.java
index 5f4d13d..e1640ab 100644
--- a/tests/tests/print/src/android/print/cts/BasePrintTest.java
+++ b/tests/tests/print/src/android/print/cts/BasePrintTest.java
@@ -68,6 +68,9 @@
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestRule;
+import org.junit.runners.model.Statement;
 import org.mockito.InOrder;
 import org.mockito.stubbing.Answer;
 
@@ -77,6 +80,11 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeoutException;
@@ -105,6 +113,8 @@
     private static Instrumentation sInstrumentation;
     private static UiDevice sUiDevice;
 
+    public final @Rule ShouldStartActivity mShouldStartActivityRule = new ShouldStartActivity();
+
     /**
      * Return the UI device
      *
@@ -188,19 +198,36 @@
                 .getTargetContext().getCacheDir().getPath());
 
         Log.d(LOG_TAG, "disable animations");
-        sWindowAnimationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
-                sInstrumentation, "settings get global window_animation_scale"));
-        sTransitionAnimationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
-                sInstrumentation, "settings get global transition_animation_scale"));
-        sAnimatiorDurationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
-                sInstrumentation, "settings get global animator_duration_scale"));
+        try {
+            sWindowAnimationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
+                    sInstrumentation, "settings get global window_animation_scale"));
 
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global window_animation_scale 0");
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global transition_animation_scale 0");
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global animator_duration_scale 0");
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global window_animation_scale 0");
+        } catch (NumberFormatException e) {
+            Log.e(LOG_TAG, "Could not read window_animation_scale", e);
+            sWindowAnimationScaleBefore = Float.NaN;
+        }
+        try {
+            sTransitionAnimationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
+                    sInstrumentation, "settings get global transition_animation_scale"));
+
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global transition_animation_scale 0");
+        } catch (NumberFormatException e) {
+            Log.e(LOG_TAG, "Could not read transition_animation_scale", e);
+            sTransitionAnimationScaleBefore = Float.NaN;
+        }
+        try {
+            sAnimatiorDurationScaleBefore = Float.parseFloat(SystemUtil.runShellCommand(
+                    sInstrumentation, "settings get global animator_duration_scale"));
+
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global animator_duration_scale 0");
+        } catch (NumberFormatException e) {
+            Log.e(LOG_TAG, "Could not read animator_duration_scale", e);
+            sAnimatiorDurationScaleBefore = Float.NaN;
+        }
 
         Log.d(LOG_TAG, "setUpClass() done");
     }
@@ -220,9 +247,11 @@
         mCreateSessionCallCounter = new CallCounter();
         mDestroySessionCallCounter = new CallCounter();
 
-        // Create the activity for the right locale.
-        Log.d(LOG_TAG, "createActivity()");
-        createActivity();
+        // Create the activity if needed
+        if (!mShouldStartActivityRule.noActivity) {
+            createActivity();
+        }
+
         Log.d(LOG_TAG, "setUp() done");
     }
 
@@ -231,9 +260,13 @@
         Log.d(LOG_TAG, "tearDown()");
 
         // Done with the activity.
-        Log.d(LOG_TAG, "finish activity");
-        if (!getActivity().isFinishing()) {
-            getActivity().finish();
+        if (getActivity() != null) {
+            Log.d(LOG_TAG, "finish activity");
+            if (!getActivity().isFinishing()) {
+                getActivity().finish();
+            }
+
+            sActivity = null;
         }
 
         Log.d(LOG_TAG, "tearDown() done");
@@ -251,13 +284,19 @@
         clearPrintSpoolerData();
 
         Log.d(LOG_TAG, "enable animations");
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global window_animation_scale " + sWindowAnimationScaleBefore);
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global transition_animation_scale " +
-                        sTransitionAnimationScaleBefore);
-        SystemUtil.runShellCommand(sInstrumentation,
-                "settings put global animator_duration_scale " + sAnimatiorDurationScaleBefore);
+        if (sWindowAnimationScaleBefore != Float.NaN) {
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global window_animation_scale " + sWindowAnimationScaleBefore);
+        }
+        if (sTransitionAnimationScaleBefore != Float.NaN) {
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global transition_animation_scale " +
+                            sTransitionAnimationScaleBefore);
+        }
+        if (sAnimatiorDurationScaleBefore != Float.NaN) {
+            SystemUtil.runShellCommand(sInstrumentation,
+                    "settings put global animator_duration_scale " + sAnimatiorDurationScaleBefore);
+        }
 
         Log.d(LOG_TAG, "tearDownClass() done");
     }
@@ -606,7 +645,9 @@
         return sActivity;
     }
 
-    private void createActivity() {
+    protected void createActivity() {
+        Log.d(LOG_TAG, "createActivity()");
+
         int createBefore = getActivityCreateCallbackCallCount();
 
         Intent intent = new Intent(Intent.ACTION_MAIN);
@@ -887,7 +928,6 @@
         Log.d(LOG_TAG, "getActivity().finish()");
         getActivity().finish();
 
-        Log.d(LOG_TAG, "createActivity");
         createActivity();
     }
 
@@ -962,4 +1002,30 @@
                 throw new Exception("Unknown default media size " + defaultMediaSizeName);
         }
     }
+
+    /**
+     * Annotation used to signal that a test does not need an activity.
+     */
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.METHOD)
+    @interface NoActivity { }
+
+    /**
+     * Rule that handles the {@link NoActivity} annotation.
+     */
+    private static class ShouldStartActivity implements TestRule {
+        boolean noActivity;
+
+        @Override
+        public Statement apply(Statement base, org.junit.runner.Description description) {
+            for (Annotation annotation : description.getAnnotations()) {
+                if (annotation instanceof NoActivity) {
+                    noActivity = true;
+                    break;
+                }
+            }
+
+            return base;
+        }
+    }
 }
diff --git a/tests/tests/print/src/android/print/cts/PrintJobStateTransitionsTest.java b/tests/tests/print/src/android/print/cts/PrintJobStateTransitionsTest.java
index 3311538..f0674a2 100644
--- a/tests/tests/print/src/android/print/cts/PrintJobStateTransitionsTest.java
+++ b/tests/tests/print/src/android/print/cts/PrintJobStateTransitionsTest.java
@@ -263,6 +263,8 @@
     @Before
     public void setPrinter() throws Exception {
         if (!sHasBeenSetUp) {
+            createActivity();
+
             resetCounters();
             PrinterDiscoverySessionCallbacks sessionCallbacks
                     = createFirstMockPrinterDiscoverySessionCallbacks();
@@ -295,6 +297,7 @@
      * @throws Exception If anything is unexpected.
      */
     @Test
+    @NoActivity
     public void stateTransitions() throws Exception {
         // No need to repeat what previously failed
         if(sKnownFailures[mState1][mState2] || sKnownFailures[mState2][mState3]) {
@@ -302,6 +305,9 @@
             return;
         } else {
             Log.i(LOG_TAG, "Test " + mState1 + " -> " + mState2 + " -> " + mState3);
+            if (getActivity() == null) {
+                createActivity();
+            }
         }
 
         // Create the session of the printers that we will be checking.
diff --git a/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerLauncherCallbackTest.java b/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerLauncherCallbackTest.java
index f1a6c71..758b0fd 100644
--- a/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerLauncherCallbackTest.java
+++ b/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerLauncherCallbackTest.java
@@ -33,6 +33,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Predicate;
 
 @SmallTest
@@ -111,6 +112,13 @@
         }
     }
 
+    public void testRegisterAndUnRegister() {
+        final MyCallback c = new MyCallback();
+        final Handler handler = new Handler(Looper.getMainLooper());
+        getLauncherApps().registerCallback(c, handler);
+        getLauncherApps().unregisterCallback(c);
+    }
+
     public void testCallbacks() {
         final MyCallback c = new MyCallback();
 
@@ -118,11 +126,17 @@
 
         final Handler handler = new Handler(Looper.getMainLooper());
 
+        final AtomicBoolean registered = new AtomicBoolean(false);
+
         final Runnable reset = () -> {
             runWithCaller(mLauncherContext1, () -> {
-                getLauncherApps().unregisterCallback(c);
+                if (registered.get()) {
+                    getLauncherApps().unregisterCallback(c);
+                    registered.set(false);
+                }
                 c.reset();
                 getLauncherApps().registerCallback(c, handler);
+                registered.set(true);
             });
         };
         reset.run();
@@ -299,7 +313,10 @@
 
         } finally {
             runWithCaller(mLauncherContext1, () -> {
-                getLauncherApps().unregisterCallback(c);
+                if (registered.get()) {
+                    getLauncherApps().unregisterCallback(c);
+                    registered.set(false);
+                }
             });
         }
     }
diff --git a/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerThrottlingTest.java b/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerThrottlingTest.java
index de5e346..45e0b1c 100644
--- a/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerThrottlingTest.java
+++ b/tests/tests/shortcutmanager/src/android/content/pm/cts/shortcutmanager/ShortcutManagerThrottlingTest.java
@@ -33,6 +33,7 @@
 import android.support.test.uiautomator.UiObject2;
 import android.support.test.uiautomator.Until;
 import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.Suppress;
 import android.view.KeyEvent;
 
 import java.util.concurrent.atomic.AtomicReference;
@@ -98,6 +99,8 @@
 
         resetThrottling(getInstrumentation());
 
+        UiDevice.getInstance(getInstrumentation()).pressHome();
+
         runCommandForNoOutput(getInstrumentation(), "am force-stop " + TARGET_PACKAGE);
     }
 
@@ -125,6 +128,7 @@
         callTest(Constants.TEST_FG_SERVICE_UNTHROTTLED);
     }
 
+    @Suppress
     public void testInlineReply() throws Exception {
         clearNotifications();
 
diff --git a/tests/tests/text/src/android/text/cts/AlteredCharSequenceTest.java b/tests/tests/text/src/android/text/cts/AlteredCharSequenceTest.java
index 609370f..e80d233 100644
--- a/tests/tests/text/src/android/text/cts/AlteredCharSequenceTest.java
+++ b/tests/tests/text/src/android/text/cts/AlteredCharSequenceTest.java
@@ -16,44 +16,53 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.AlteredCharSequence;
 import android.text.Spanned;
 
-public class AlteredCharSequenceTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AlteredCharSequenceTest {
     private static final String SOURCE_STR = "This is a char sequence.";
+
     private AlteredCharSequence mAlteredCharSequence;
 
+    @Test
     public void testCharAt() {
-        mAlteredCharSequence = null;
-        char[] sub = { 'i', 's' };
-        CharSequence source = "abcdefgh";
-        mAlteredCharSequence = AlteredCharSequence.make(source, sub, 0, sub.length);
+        mAlteredCharSequence = AlteredCharSequence.make("abcdefgh", new char[] {'i', 's'}, 0, 2);
         // chars in sub.
         assertEquals('i', mAlteredCharSequence.charAt(0));
         assertEquals('s', mAlteredCharSequence.charAt(1));
         // chars in source.
         assertEquals('c', mAlteredCharSequence.charAt(2));
         assertEquals('d', mAlteredCharSequence.charAt(3));
-
-        try {
-            mAlteredCharSequence.charAt(-1);
-            fail("should raise a StringIndexOutOfBoundsException.");
-        } catch (StringIndexOutOfBoundsException e) {
-            // expected.
-        }
-
-        try {
-            mAlteredCharSequence.charAt(mAlteredCharSequence.length() + 1);
-            fail("should raise a StringIndexOutOfBoundsException.");
-        } catch (StringIndexOutOfBoundsException e) {
-            // expected.
-        }
     }
 
+    @Test(expected=StringIndexOutOfBoundsException.class)
+    public void testCharAtTooLow() {
+        mAlteredCharSequence = AlteredCharSequence.make("abcdefgh", new char[] {'i', 's'}, 0, 2);
+
+        mAlteredCharSequence.charAt(-1);
+    }
+
+    @Test(expected=StringIndexOutOfBoundsException.class)
+    public void testCharAtTooHigh() {
+        mAlteredCharSequence = AlteredCharSequence.make("abcdefgh", new char[] {'i', 's'}, 0, 2);
+
+        mAlteredCharSequence.charAt(mAlteredCharSequence.length() + 1);
+    }
+
+    @Test
     public void testGetChars() {
-        mAlteredCharSequence = null;
         char[] sub = { 'i', 's' };
         int start = 0;
         int end = 2;
@@ -84,6 +93,7 @@
         }
     }
 
+    @Test
     public void testLength() {
         char[] sub = { 'i', 's' };
 
@@ -95,8 +105,8 @@
         }
     }
 
+    @Test
     public void testMake() {
-        mAlteredCharSequence = null;
         char[] sub = { 'i', 's' };
 
         CharSequence source = SOURCE_STR;
@@ -113,8 +123,8 @@
         assertFalse(0 == acsClassName.compareTo(spanClassName));
     }
 
+    @Test
     public void testSubSequence() {
-        mAlteredCharSequence = null;
         char[] sub = { 'i', 's' };
 
         CharSequence source = SOURCE_STR;
@@ -129,8 +139,8 @@
         }
     }
 
+    @Test
     public void testToString() {
-        mAlteredCharSequence = null;
         char[] sub = { 'i', 's' };
         CharSequence source = SOURCE_STR;
         mAlteredCharSequence = AlteredCharSequence.make(source, sub, 0, sub.length);
@@ -140,28 +150,35 @@
     class MockSpanned implements Spanned {
         public MockSpanned(String sequence) {
         }
+
         public int getSpanEnd(Object tag) {
             return 0;
         }
+
         public int getSpanFlags(Object tag) {
             return 0;
         }
+
         public int getSpanStart(Object tag) {
             return 0;
         }
+
         public <T> T[] getSpans(int start, int end, Class<T> type) {
             return null;
         }
-        @SuppressWarnings("unchecked")
+
         public int nextSpanTransition(int start, int limit, Class type) {
             return 0;
         }
+
         public char charAt(int index) {
             return 0;
         }
+
         public int length() {
             return 0;
         }
+
         public CharSequence subSequence(int start, int end) {
             return null;
         }
diff --git a/tests/tests/text/src/android/text/cts/AndroidCharacterTest.java b/tests/tests/text/src/android/text/cts/AndroidCharacterTest.java
index 7eaa092..16a83443 100644
--- a/tests/tests/text/src/android/text/cts/AndroidCharacterTest.java
+++ b/tests/tests/text/src/android/text/cts/AndroidCharacterTest.java
@@ -16,15 +16,27 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.AndroidCharacter;
 
-public class AndroidCharacterTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AndroidCharacterTest {
+    @Test
     public void testConstructor() {
         new AndroidCharacter();
     }
 
+    @Test
     public void testGetDirectionalities() {
         char[] src = new char[128];
         for (int i = 0; i < src.length; i++) {
@@ -45,6 +57,7 @@
         }
     }
 
+    @Test
     public void testGetEastAsianWidth() {
         // LATIN CAPITAL LETTER U WITH CARON (U+01D3)
         assertEquals(AndroidCharacter.EAST_ASIAN_WIDTH_NEUTRAL,
@@ -71,6 +84,7 @@
                 AndroidCharacter.getEastAsianWidth((char)0x319F));
     }
 
+    @Test
     public void testGetEastAsianWidths() {
         char[] src = {
                 0x01D3, 0xFFFD, 0xFF86, 0xFF41, 0x0041, 0x319f,
@@ -104,6 +118,7 @@
         }
     }
 
+    @Test
     public void testGetMirror() {
         assertEquals('A', AndroidCharacter.getMirror('A'));
         assertEquals('B', AndroidCharacter.getMirror('B'));
@@ -113,6 +128,7 @@
         assertEquals('<', AndroidCharacter.getMirror('>'));
     }
 
+    @Test
     public void testMirror() {
         char[] src = new char[64];
         for (int i = 0; i < src.length; i++) {
diff --git a/tests/tests/text/src/android/text/cts/AnnotationTest.java b/tests/tests/text/src/android/text/cts/AnnotationTest.java
index a0d597a..a74bc62 100644
--- a/tests/tests/text/src/android/text/cts/AnnotationTest.java
+++ b/tests/tests/text/src/android/text/cts/AnnotationTest.java
@@ -16,31 +16,36 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import android.os.Parcel;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Annotation;
 
-public class AnnotationTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AnnotationTest {
 
     private static final String KEY1 = "name";
     private static final String KEY2 = "family name";
     private static final String VALUE1 = "John";
     private static final String VALUE2 = "Smith";
     private static final int NOFLAG = 0;
+
     private Annotation mAnnotation;
 
-    @Override
-    protected void setUp() throws Exception {
-
-        super.setUp();
-        mAnnotation = null;
-    }
-
+    @Test
     public void testConstructor() {
         // new the Annotation instance
         new Annotation(KEY1, VALUE1);
     }
 
+    @Test
     public void testGetValue() {
         // new the Annotation instance
         mAnnotation = new Annotation(KEY1, VALUE1);
@@ -49,6 +54,7 @@
         assertEquals(VALUE2, mAnnotation.getValue());
     }
 
+    @Test
     public void testGetKey() {
         // new the Annotation instance
         mAnnotation = new Annotation(KEY1, VALUE1);
@@ -57,12 +63,14 @@
         assertEquals(KEY2, mAnnotation.getKey());
     }
 
+    @Test
     public void testGetSpanTypeId() {
         mAnnotation = new Annotation(KEY1, VALUE1);
         // Because of the return value is a hide value, we only can assert the return value isn't 0.
         assertTrue(mAnnotation.getSpanTypeId() != 0);
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel dest = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/cts/AutoTextTest.java b/tests/tests/text/src/android/text/cts/AutoTextTest.java
index 867b34e..e3d1b52 100644
--- a/tests/tests/text/src/android/text/cts/AutoTextTest.java
+++ b/tests/tests/text/src/android/text/cts/AutoTextTest.java
@@ -16,29 +16,52 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
 import android.content.res.Configuration;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.AutoText;
 import android.view.View;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 
-public class AutoTextTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AutoTextTest {
+    private Context mContext;
 
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
+
+        // set locale as English.
+        Locale.setDefault(Locale.ENGLISH);
+        Configuration config = mContext.getResources().getConfiguration();
+        if (!config.locale.equals(Locale.getDefault())) {
+            config.locale = Locale.getDefault();
+            mContext.getResources().updateConfiguration(config, null);
+        }
+    }
+
+    @UiThreadTest
+    @Test
     public void testGet() {
         // Define the necessary sources.
         CharSequence src;
         String actual;
-
-        // set local as English.
-        Locale.setDefault(Locale.ENGLISH);
-        Configuration config = getContext().getResources().getConfiguration();
-        if (!config.locale.equals(Locale.getDefault())) {
-                config.locale = Locale.getDefault();
-                getContext().getResources().updateConfiguration(config, null);
-        }
         // New a View instance.
-        View view = new View(getContext());
+        View view = new View(mContext);
 
         // Test a word key not in the autotext.xml.
         src = "can";
@@ -76,14 +99,10 @@
         assertEquals("can", actual);
     }
 
+    @UiThreadTest
+    @Test
     public void testGetSize() {
-        Locale.setDefault(Locale.ENGLISH);
-        Configuration config = getContext().getResources().getConfiguration();
-        if (!config.locale.equals(Locale.getDefault())) {
-                config.locale = Locale.getDefault();
-                getContext().getResources().updateConfiguration(config, null);
-        }
-        View view = new View(getContext());
+        View view = new View(mContext);
         // Returns the size of the auto text dictionary. Just make sure it is bigger than 0.
         assertTrue(AutoText.getSize(view) > 0);
     }
diff --git a/tests/tests/text/src/android/text/cts/BidiFormatterTest.java b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
index b7aec1b..bf0d14e 100644
--- a/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
+++ b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
@@ -16,17 +16,28 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 import android.icu.util.ULocale;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.BidiFormatter;
 import android.text.SpannableString;
 import android.text.Spanned;
 import android.text.TextDirectionHeuristics;
 import android.text.style.RelativeSizeSpan;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 
-public class BidiFormatterTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BidiFormatterTest {
 
     private static final BidiFormatter LTR_FMT = BidiFormatter.getInstance(false /* LTR context */);
     private static final BidiFormatter RTL_FMT = BidiFormatter.getInstance(true /* RTL context */);
@@ -45,6 +56,7 @@
     private static final String RLE = "\u202B";
     private static final String PDF = "\u202C";
 
+    @Test
     public void testIsRtlContext() {
         assertEquals(false, LTR_FMT.isRtlContext());
         assertEquals(true, RTL_FMT.isRtlContext());
@@ -53,6 +65,7 @@
         assertEquals(true, BidiFormatter.getInstance(true).isRtlContext());
     }
 
+    @Test
     public void testCachedInstances() {
         // Test that we get the same cached static instances for simple cases
         BidiFormatter defaultFormatterInstance = BidiFormatter.getInstance();
@@ -65,11 +78,13 @@
         assertEquals(RTL_FMT, BidiFormatter.getInstance(Locale.forLanguageTag("ar")));
     }
 
+    @Test
     public void testBuilderIsRtlContext() {
         assertEquals(false, new BidiFormatter.Builder(false).build().isRtlContext());
         assertEquals(true, new BidiFormatter.Builder(true).build().isRtlContext());
     }
 
+    @Test
     public void testIsRtl() {
         assertEquals(true, BidiFormatter.getInstance(true).isRtl(HE));
         assertEquals(true, BidiFormatter.getInstance(false).isRtl(HE));
@@ -78,6 +93,7 @@
         assertEquals(false, BidiFormatter.getInstance(false).isRtl(EN));
     }
 
+    @Test
     public void testMarkAfter() {
         assertEquals("uniform dir matches LTR context",
                 "", LTR_FMT.markAfter(EN, TextDirectionHeuristics.LTR));
@@ -100,6 +116,7 @@
                 "", RTL_FMT.markAfter(".", TextDirectionHeuristics.RTL));
     }
 
+    @Test
     public void testMarkBefore() {
         assertEquals("uniform dir matches LTR context",
                 "", LTR_FMT.markBefore(EN, TextDirectionHeuristics.LTR));
@@ -122,6 +139,7 @@
                 "", RTL_FMT.markBefore(".", TextDirectionHeuristics.RTL));
     }
 
+    @Test
     public void testUnicodeWrap() {
         // Make sure an input of null doesn't crash anything.
         assertNull(LTR_FMT.unicodeWrap(null));
@@ -238,6 +256,7 @@
                 RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
     }
 
+    @Test
     public void testGetStereoReset() {
         assertTrue(LTR_FMT.getStereoReset());
         assertTrue(RTL_FMT.getStereoReset());
@@ -245,6 +264,7 @@
         assertFalse(RTL_FMT_EXIT_RESET.getStereoReset());
     }
 
+    @Test
     public void testBuilder_construction() {
         final BidiFormatter defaultFmt = new BidiFormatter.Builder().build();
         // Test that the default locale and the BidiFormatter's locale have the same direction.
@@ -264,6 +284,7 @@
         assertTrue(arabicFmt.isRtlContext());
     }
 
+    @Test
     public void testBuilder_setTextDirectionHeuristic() {
         final BidiFormatter defaultFmt = new BidiFormatter.Builder().build();
         assertFalse(defaultFmt.isRtl(EN + HE + EN));
@@ -273,6 +294,7 @@
         assertTrue(modifiedFmt.isRtl(EN + HE + EN));
     }
 
+    @Test
     public void testCharSequenceApis() {
         final CharSequence CS_HE = new SpannableString(HE);
         assertEquals(true, BidiFormatter.getInstance(true).isRtl(CS_HE));
diff --git a/tests/tests/text/src/android/text/cts/BoringLayoutTest.java b/tests/tests/text/src/android/text/cts/BoringLayoutTest.java
index d181d01..10b494e 100644
--- a/tests/tests/text/src/android/text/cts/BoringLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/BoringLayoutTest.java
@@ -18,14 +18,26 @@
 
 import static android.cts.util.WidgetTestUtils.sameCharSequence;
 
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyFloat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.Config;
 import android.graphics.Canvas;
 import android.graphics.Paint;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.BoringLayout;
 import android.text.BoringLayout.Metrics;
 import android.text.Layout;
@@ -33,7 +45,13 @@
 import android.text.TextPaint;
 import android.text.TextUtils;
 
-public class BoringLayoutTest extends AndroidTestCase {
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BoringLayoutTest {
     private static final float SPACING_MULT_NO_SCALE = 1.0f;
     private static final float SPACING_ADD_NO_SCALE = 0.0f;
     private static final int DEFAULT_OUTER_WIDTH = 100;
@@ -57,12 +75,12 @@
 
     private BoringLayout mBoringLayout;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
         mBoringLayout = makeDefaultBoringLayout();
     }
 
+    @Test
     public void testConstructors() {
         new BoringLayout(DEFAULT_CHAR_SEQUENCE,
                 DEFAULT_PAINT,
@@ -93,6 +111,7 @@
         assertEquals(height + METRICS_TOP, boringLayout.getLineDescent(0));
     }
 
+    @Test
     public void testScale() {
         // no scale
         verifyMultAddScale(1.0f, 0.0f);
@@ -110,6 +129,7 @@
         verifyMultAddScale(1.0f, -3.0f);
     }
 
+    @Test
     public void testPreconditions() {
         assertEquals(1, mBoringLayout.getLineCount());
         assertEquals(0, mBoringLayout.getLineTop(0));
@@ -120,7 +140,7 @@
         assertEquals(DEFAULT_CHAR_SEQUENCE.length(), mBoringLayout.getLineStart(10));
         assertEquals(Layout.DIR_LEFT_TO_RIGHT, mBoringLayout.getParagraphDirection(0));
         assertFalse(mBoringLayout.getLineContainsTab(0));
-        assertEquals((float) METRICS_WIDTH, mBoringLayout.getLineMax(0));
+        assertEquals((float) METRICS_WIDTH, mBoringLayout.getLineMax(0), 0.0f);
         assertEquals(Layout.DIR_LEFT_TO_RIGHT, mBoringLayout.getParagraphDirection(0));
         assertEquals(0, mBoringLayout.getEllipsisCount(0));
         mBoringLayout.ellipsized(0, 1);
@@ -129,6 +149,7 @@
         assertEquals(1, mBoringLayout.getEllipsisStart(0));
     }
 
+    @Test
     public void testReplaceOrMake() {
         String source = "This is a SpannableString.";
         BoringLayout layout_1 = mBoringLayout.replaceOrMake(
@@ -158,28 +179,31 @@
     }
 
 
+    @Test
     public void testAlignment() {
         BoringLayout boringLayout = makeBoringLayoutAlign(Layout.Alignment.ALIGN_NORMAL);
-        assertEquals(0.0f, boringLayout.getLineLeft(0));
-        assertEquals((float) DEFAULT_METRICS.width, boringLayout.getLineRight(0));
+        assertEquals(0.0f, boringLayout.getLineLeft(0), 0.0f);
+        assertEquals((float) DEFAULT_METRICS.width, boringLayout.getLineRight(0), 0.0f);
 
         boringLayout = makeBoringLayoutAlign(Layout.Alignment.ALIGN_CENTER);
         int expectedWidth = DEFAULT_OUTER_WIDTH - METRICS_WIDTH;
-        assertEquals((float) expectedWidth / 2, boringLayout.getLineLeft(0));
+        assertEquals((float) expectedWidth / 2, boringLayout.getLineLeft(0), 0.0f);
         expectedWidth = DEFAULT_OUTER_WIDTH + METRICS_WIDTH;
-        assertEquals((float) expectedWidth / 2, boringLayout.getLineRight(0));
+        assertEquals((float) expectedWidth / 2, boringLayout.getLineRight(0), 0.0f);
 
         boringLayout = makeBoringLayoutAlign(Layout.Alignment.ALIGN_OPPOSITE);
         expectedWidth = DEFAULT_OUTER_WIDTH - METRICS_WIDTH;
-        assertEquals((float) expectedWidth, boringLayout.getLineLeft(0));
-        assertEquals((float) DEFAULT_OUTER_WIDTH, boringLayout.getLineRight(0));
+        assertEquals((float) expectedWidth, boringLayout.getLineLeft(0), 0.0f);
+        assertEquals((float) DEFAULT_OUTER_WIDTH, boringLayout.getLineRight(0), 0.0f);
     }
 
+    @Test
     public void testGetLineDescent_withIncludePadding() {
         final int height = METRICS_BOTTOM - METRICS_TOP;
         assertEquals(height + METRICS_TOP, mBoringLayout.getLineDescent(0));
     }
 
+    @Test
     public void testGetLineDescent_withoutIncludePadding() {
         BoringLayout boringLayout = new BoringLayout(
                 DEFAULT_CHAR_SEQUENCE,
@@ -195,6 +219,7 @@
         assertEquals(height + METRICS_ASCENT, boringLayout.getLineDescent(0));
     }
 
+    @Test
     public void testIncludePadding() {
         assertEquals(METRICS_TOP - METRICS_ASCENT, mBoringLayout.getTopPadding());
         assertEquals(METRICS_BOTTOM - METRICS_DESCENT, mBoringLayout.getBottomPadding());
@@ -215,6 +240,7 @@
         assertEquals(METRICS_DESCENT - METRICS_ASCENT, boringLayout.getHeight());
     }
 
+    @Test
     public void testIsBoringString() {
         TextPaint paint = new TextPaint();
         assertNotNull(BoringLayout.isBoring("hello android", paint));
@@ -231,6 +257,7 @@
         assertNull(BoringLayout.isBoring("hello android\n\n\n", paint));
     }
 
+    @Test
     public void testIsBoring_resetsFontMetrics() {
         int someInt = 100;
         String text = "some text";
@@ -256,11 +283,13 @@
         assertEquals(expectedMetrics.leading, actualMetrics.leading);
     }
 
+    @Test
     public void testGetLineDirections() {
         assertNotNull(mBoringLayout.getLineDirections(0));
         assertNotNull(mBoringLayout.getLineDirections(2));
     }
 
+    @Test
     public void testMake() {
         BoringLayout boringLayout = BoringLayout.make(DEFAULT_CHAR_SEQUENCE,
                 DEFAULT_PAINT,
@@ -272,7 +301,6 @@
                 true);
         assertNotNull(boringLayout);
 
-        boringLayout = null;
         boringLayout = BoringLayout.make(DEFAULT_CHAR_SEQUENCE,
                 DEFAULT_PAINT,
                 DEFAULT_OUTER_WIDTH,
@@ -286,6 +314,7 @@
         assertNotNull(boringLayout);
     }
 
+    @Test
     public void testDraw() {
         BoringLayout boringLayout = BoringLayout.make(DEFAULT_CHAR_SEQUENCE,
                 DEFAULT_PAINT,
@@ -336,7 +365,7 @@
         return metrics;
     }
 
-    private BoringLayout makeDefaultBoringLayout(){
+    private static BoringLayout makeDefaultBoringLayout() {
         return new BoringLayout(DEFAULT_CHAR_SEQUENCE,
                                 DEFAULT_PAINT,
                                 DEFAULT_OUTER_WIDTH,
@@ -347,7 +376,7 @@
                                 true);
     }
 
-    private BoringLayout makeBoringLayout(float spacingMult,float spacingAdd){
+    private static BoringLayout makeBoringLayout(float spacingMult,float spacingAdd) {
         return new BoringLayout(DEFAULT_CHAR_SEQUENCE,
                                 DEFAULT_PAINT,
                                 DEFAULT_OUTER_WIDTH,
@@ -358,7 +387,7 @@
                                 true);
     }
 
-    private BoringLayout makeBoringLayoutAlign(Alignment align){
+    private static BoringLayout makeBoringLayoutAlign(Alignment align) {
         return new BoringLayout(DEFAULT_CHAR_SEQUENCE,
                                 DEFAULT_PAINT,
                                 DEFAULT_OUTER_WIDTH,
diff --git a/tests/tests/text/src/android/text/cts/BoringLayout_MetricsTest.java b/tests/tests/text/src/android/text/cts/BoringLayout_MetricsTest.java
index 141ff023..3dc4b73 100644
--- a/tests/tests/text/src/android/text/cts/BoringLayout_MetricsTest.java
+++ b/tests/tests/text/src/android/text/cts/BoringLayout_MetricsTest.java
@@ -16,11 +16,19 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertNotNull;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.BoringLayout;
 
-public class BoringLayout_MetricsTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BoringLayout_MetricsTest {
+    @Test
     public void testMetrics() {
         BoringLayout.Metrics bm = new BoringLayout.Metrics();
         assertNotNull(bm.toString());
diff --git a/tests/tests/text/src/android/text/cts/ClipboardManagerTest.java b/tests/tests/text/src/android/text/cts/ClipboardManagerTest.java
index f0fc0fa..0073c42 100644
--- a/tests/tests/text/src/android/text/cts/ClipboardManagerTest.java
+++ b/tests/tests/text/src/android/text/cts/ClipboardManagerTest.java
@@ -16,47 +16,55 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.content.Context;
-import android.test.InstrumentationTestCase;
-import android.test.UiThreadTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.ClipboardManager;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link ClipboardManager}.
  */
-public class ClipboardManagerTest extends InstrumentationTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ClipboardManagerTest {
+    private ClipboardManager mClipboardManager;
 
-    private Context mContext;
-
-    @Override
-    public void setUp() {
-        mContext = getInstrumentation().getContext();
+    @UiThreadTest
+    @Before
+    public void setup() {
+        final Context context = InstrumentationRegistry.getTargetContext();
+        mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
     }
 
     @UiThreadTest
+    @Test
     public void testAccessText() {
-        ClipboardManager clipboardManager =
-                (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
-
         // set the expected value
         CharSequence expected = "test";
-        clipboardManager.setText(expected);
-        assertEquals(expected, clipboardManager.getText());
+        mClipboardManager.setText(expected);
+        assertEquals(expected, mClipboardManager.getText());
     }
 
     @UiThreadTest
+    @Test
     public void testHasText() {
-        ClipboardManager clipboardManager =
-                (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
+        mClipboardManager.setText("");
+        assertFalse(mClipboardManager.hasText());
 
-        clipboardManager.setText("");
-        assertFalse(clipboardManager.hasText());
+        mClipboardManager.setText("test");
+        assertTrue(mClipboardManager.hasText());
 
-        clipboardManager.setText("test");
-        assertTrue(clipboardManager.hasText());
-
-        clipboardManager.setText(null);
-        assertFalse(clipboardManager.hasText());
+        mClipboardManager.setText(null);
+        assertFalse(mClipboardManager.hasText());
     }
 }
diff --git a/tests/tests/text/src/android/text/cts/DynamicLayoutTest.java b/tests/tests/text/src/android/text/cts/DynamicLayoutTest.java
index 6ef1299..426200b 100644
--- a/tests/tests/text/src/android/text/cts/DynamicLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/DynamicLayoutTest.java
@@ -16,23 +16,36 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.graphics.Paint.FontMetricsInt;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.DynamicLayout;
 import android.text.Layout;
 import android.text.TextPaint;
 import android.text.TextUtils;
 
-public class DynamicLayoutTest extends AndroidTestCase {
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-    protected static final float SPACING_MULT_NO_SCALE = 1.0f;
-    protected static final float SPACING_ADD_NO_SCALE = 0.0f;
-    protected static final int DEFAULT_OUTER_WIDTH = 150;
-    protected static final CharSequence SINGLELINE_CHAR_SEQUENCE = "......";
-    protected static final String[] TEXT = {"CharSequence\n", "Char\tSequence\n", "CharSequence"};
-    protected static final CharSequence MULTLINE_CHAR_SEQUENCE = TEXT[0] + TEXT[1] + TEXT[2];
-    protected static final Layout.Alignment DEFAULT_ALIGN = Layout.Alignment.ALIGN_CENTER;
-    protected TextPaint mDefaultPaint;
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class DynamicLayoutTest {
+
+    private static final float SPACING_MULT_NO_SCALE = 1.0f;
+    private static final float SPACING_ADD_NO_SCALE = 0.0f;
+    private static final int DEFAULT_OUTER_WIDTH = 150;
+    private static final CharSequence SINGLELINE_CHAR_SEQUENCE = "......";
+    private static final String[] TEXT = {"CharSequence\n", "Char\tSequence\n", "CharSequence"};
+    private static final CharSequence MULTLINE_CHAR_SEQUENCE = TEXT[0] + TEXT[1] + TEXT[2];
+    private static final Layout.Alignment DEFAULT_ALIGN = Layout.Alignment.ALIGN_CENTER;
+    private TextPaint mDefaultPaint;
 
     private static final int LINE0 = 0;
     private static final int LINE0_TOP = 0;
@@ -44,9 +57,8 @@
 
     private DynamicLayout mDynamicLayout;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
         mDefaultPaint = new TextPaint();
         mDynamicLayout = new DynamicLayout(MULTLINE_CHAR_SEQUENCE,
                 mDefaultPaint,
@@ -57,6 +69,7 @@
                 true);
     }
 
+    @Test
     public void testConstructors() {
         new DynamicLayout(SINGLELINE_CHAR_SEQUENCE,
                 MULTLINE_CHAR_SEQUENCE,
@@ -85,6 +98,7 @@
                 true);
     }
 
+    @Test
     public void testEllipsis() {
         final DynamicLayout dynamicLayout = new DynamicLayout(SINGLELINE_CHAR_SEQUENCE,
                 MULTLINE_CHAR_SEQUENCE,
@@ -106,6 +120,7 @@
      * 1. Include padding while calculate the layout.
      * 2. Don't include padding while calculate the layout.
      */
+    @Test
     public void testIncludePadding() {
         final FontMetricsInt fontMetricsInt = mDefaultPaint.getFontMetricsInt();
 
@@ -137,6 +152,7 @@
      * Test the line top
      * 1. the Y-coordinate of line top.2. the Y-coordinate of baseline.
      */
+    @Test
     public void testLineLayout() {
         assertEquals(TEXT.length, mDynamicLayout.getLineCount());
         assertFalse(mDynamicLayout.getLineContainsTab(LINE0));
diff --git a/tests/tests/text/src/android/text/cts/Editable_FactoryTest.java b/tests/tests/text/src/android/text/cts/Editable_FactoryTest.java
index 815f5eb..aa42505 100644
--- a/tests/tests/text/src/android/text/cts/Editable_FactoryTest.java
+++ b/tests/tests/text/src/android/text/cts/Editable_FactoryTest.java
@@ -16,31 +16,37 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.Editable.Factory;
 import android.text.SpannableStringBuilder;
 
-public class Editable_FactoryTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-    Factory mFactory;
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class Editable_FactoryTest {
+    private Factory mFactory;
 
+    @Test
     public void testNewEditable() {
-
         CharSequence source = "abc";
         // set the expected value
         Editable expected = new SpannableStringBuilder(source);
 
-        // new the Factory instance
         mFactory = new Editable.Factory();
         Editable actual = mFactory.newEditable(source);
         assertEquals(expected.toString(), actual.toString());
 
     }
 
+    @Test
     public void testGetInstance() {
-
-        // new the Factory instance
         mFactory = Factory.getInstance();
         assertTrue(mFactory instanceof Editable.Factory);
     }
diff --git a/tests/tests/text/src/android/text/cts/EmojiTest.java b/tests/tests/text/src/android/text/cts/EmojiTest.java
index b67f8c9..591c613 100644
--- a/tests/tests/text/src/android/text/cts/EmojiTest.java
+++ b/tests/tests/text/src/android/text/cts/EmojiTest.java
@@ -16,13 +16,22 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import android.content.Context;
 import android.cts.util.NullWebViewUtils;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Picture;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.LargeTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.util.TypedValue;
 import android.view.KeyEvent;
 import android.view.View;
@@ -30,23 +39,30 @@
 import android.widget.EditText;
 import android.widget.TextView;
 
-public class EmojiTest extends ActivityInstrumentationTestCase2<EmojiCtsActivity> {
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-    public EmojiTest() {
-        super("android.text.cts", EmojiCtsActivity.class);
-    }
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class EmojiTest {
+    private Context mContext;
+    private EditText mEditText;
 
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
+    @Rule
+    public ActivityTestRule<EmojiCtsActivity> mActivityRule =
+            new ActivityTestRule<>(EmojiCtsActivity.class);
 
-    protected void tearDown() throws Exception {
-        super.tearDown();
+    @Before
+    public void setup() {
+        mContext = mActivityRule.getActivity();
     }
 
     /**
      * Tests all Emoji are defined in Character class
      */
+    @Test
     public void testEmojiCodePoints() {
         for (int i = 0; i < EmojiConstants.emojiCodePoints.length; i++) {
             assertTrue(Character.isDefined(EmojiConstants.emojiCodePoints[i]));
@@ -77,8 +93,10 @@
      * Tests Emoji has different glyph for different meaning characters.
      * Test on Canvas, TextView, EditText and WebView
      */
+    @UiThreadTest
+    @Test
     public void testEmojiGlyph() {
-        CaptureCanvas ccanvas = new CaptureCanvas(getInstrumentation().getContext());
+        CaptureCanvas ccanvas = new CaptureCanvas(mContext);
 
         Bitmap mBitmapA, mBitmapB;  // Emoji displayed Bitmaps to compare
 
@@ -102,17 +120,17 @@
             assertFalse(baseMessage + bmpDiffMessage, mBitmapA.sameAs(mBitmapB));
 
             // cannot reuse CaptureTextView as 2nd setText call throws NullPointerException
-            CaptureTextView cviewA = new CaptureTextView(getInstrumentation().getContext());
+            CaptureTextView cviewA = new CaptureTextView(mContext);
             mBitmapA = cviewA.capture(Character.toChars(comparedCodePoints[i][0]));
-            CaptureTextView cviewB = new CaptureTextView(getInstrumentation().getContext());
+            CaptureTextView cviewB = new CaptureTextView(mContext);
             mBitmapB = cviewB.capture(Character.toChars(comparedCodePoints[i][1]));
 
             bmpDiffMessage = describeBitmap(mBitmapA) + "vs" + describeBitmap(mBitmapB);
             assertFalse(baseMessage + bmpDiffMessage, mBitmapA.sameAs(mBitmapB));
 
-            CaptureEditText cedittextA = new CaptureEditText(getInstrumentation().getContext());
+            CaptureEditText cedittextA = new CaptureEditText(mContext);
             mBitmapA = cedittextA.capture(Character.toChars(comparedCodePoints[i][0]));
-            CaptureEditText cedittextB = new CaptureEditText(getInstrumentation().getContext());
+            CaptureEditText cedittextB = new CaptureEditText(mContext);
             mBitmapB = cedittextB.capture(Character.toChars(comparedCodePoints[i][1]));
 
             bmpDiffMessage = describeBitmap(mBitmapA) + "vs" + describeBitmap(mBitmapB);
@@ -120,9 +138,8 @@
 
             // Trigger activity bringup so we can determine if a WebView is available on this
             // device.
-            EmojiCtsActivity activity = getActivity();
             if (NullWebViewUtils.isWebViewAvailable()) {
-                CaptureWebView cwebview = new CaptureWebView(getInstrumentation().getContext());
+                CaptureWebView cwebview = new CaptureWebView();
                 mBitmapA = cwebview.capture(Character.toChars(comparedCodePoints[i][0]));
                 mBitmapB = cwebview.capture(Character.toChars(comparedCodePoints[i][1]));
                 bmpDiffMessage = describeBitmap(mBitmapA) + "vs" + describeBitmap(mBitmapB);
@@ -134,6 +151,8 @@
     /**
      * Tests EditText handles Emoji
      */
+    @LargeTest
+    @Test
     public void testEmojiEditable() throws Throwable {
         int testedCodePoints[] = {
             0xAE,    // registered mark
@@ -147,19 +166,19 @@
         for (int i = 0; i < testedCodePoints.length; i++) {
             origStr = "Test character  ";
             // cannot reuse CaptureTextView as 2nd setText call throws NullPointerException
-            final EditText editText = new EditText(getInstrumentation().getContext());
-            editText.setText(origStr + String.valueOf(Character.toChars(testedCodePoints[i])));
+            mActivityRule.runOnUiThread(() -> mEditText = new EditText(mContext));
+            mEditText.setText(origStr + String.valueOf(Character.toChars(testedCodePoints[i])));
 
             // confirm the emoji is added.
-            newStr = editText.getText().toString();
+            newStr = mEditText.getText().toString();
             assertEquals(newStr.codePointCount(0, newStr.length()), origStr.length() + 1);
 
             // Delete added character by sending KEYCODE_DEL event
-            runTestOnUiThread(() -> editText.dispatchKeyEvent(
+            mActivityRule.runOnUiThread(() -> mEditText.dispatchKeyEvent(
                     new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)));
-            getInstrumentation().waitForIdleSync();
+            InstrumentationRegistry.getInstrumentation().waitForIdleSync();
 
-            newStr = editText.getText().toString();
+            newStr = mEditText.getText().toString();
             assertEquals(newStr.codePointCount(0, newStr.length()), origStr.length() + 1);
         }
     }
@@ -249,13 +268,15 @@
 
         WebViewOnUiThread webViewOnUiThread;
         Bitmap bitmap;
-        CaptureWebView(Context context) {
-            webViewOnUiThread = new WebViewOnUiThread(EmojiTest.this, getActivity().getWebView());
+        CaptureWebView() {
+            webViewOnUiThread = new WebViewOnUiThread(mActivityRule,
+                    mActivityRule.getActivity().getWebView());
         }
 
         Bitmap capture(char c[]) {
 
-            webViewOnUiThread.loadDataAndWaitForCompletion("<html><body>" + String.valueOf(c) + "</body></html>",
+            webViewOnUiThread.loadDataAndWaitForCompletion(
+                    "<html><body>" + String.valueOf(c) + "</body></html>",
                     "text/html; charset=utf-8", "utf-8");
             // The Chromium-powered WebView renders asynchronously and there's nothing reliable
             // we can easily wait for to be sure that capturePicture will return a fresh frame.
diff --git a/tests/tests/text/src/android/text/cts/GetCharsTest.java b/tests/tests/text/src/android/text/cts/GetCharsTest.java
index 41e7ccc..8faf638 100644
--- a/tests/tests/text/src/android/text/cts/GetCharsTest.java
+++ b/tests/tests/text/src/android/text/cts/GetCharsTest.java
@@ -16,14 +16,22 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.GetChars;
 import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
 import android.text.SpannedString;
 
-public class GetCharsTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class GetCharsTest {
 
     // Returns an array of three GetChars objects, of three different classes:
     // SpannableString, SpannableStringBuilder, and SpannedString.
@@ -34,7 +42,7 @@
                 new SpannedString(s)};
     }
 
-    @SmallTest
+    @Test
     public void testGetChars() {
         final GetChars[] getCharsCases = makeGetChars("\uD83D\uDE00");  // U+1F600 GRINNING FACE
         for (GetChars getChars : getCharsCases) {
diff --git a/tests/tests/text/src/android/text/cts/HtmlTest.java b/tests/tests/text/src/android/text/cts/HtmlTest.java
index 076d0a4..3b8557b 100644
--- a/tests/tests/text/src/android/text/cts/HtmlTest.java
+++ b/tests/tests/text/src/android/text/cts/HtmlTest.java
@@ -16,10 +16,14 @@
 
 package android.text.cts;
 
+import static android.text.Spanned.SPAN_EXCLUSIVE_INCLUSIVE;
+
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 
 import android.graphics.Typeface;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Html;
 import android.text.Layout;
 import android.text.Spannable;
@@ -40,20 +44,23 @@
 
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class HtmlTest extends AndroidTestCase {
-    private final static int SPAN_EXCLUSIVE_INCLUSIVE = Spannable.SPAN_EXCLUSIVE_INCLUSIVE;
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class HtmlTest {
+    @Test
     public void testSingleTagOnWhileString() {
         final String source = "<b>hello</b>";
 
         Spanned spanned = Html.fromHtml(source);
-        assertSingleTagOnWhileString(spanned);
+        verifySingleTagOnWhileString(spanned);
         spanned = Html.fromHtml(source, null, null);
-        assertSingleTagOnWhileString(spanned);
+        verifySingleTagOnWhileString(spanned);
     }
 
-    private void assertSingleTagOnWhileString(Spanned spanned) {
+    private void verifySingleTagOnWhileString(Spanned spanned) {
         final int expectStart = 0;
         final int expectEnd = 5;
         final int expectLen = 1;
@@ -66,16 +73,17 @@
         assertEquals(expectEnd, spanned.getSpanEnd(spans[0]));
     }
 
+    @Test
     public void testBadHtml() {
         final String source = "Hello <b>b<i>bi</b>i</i>";
 
         Spanned spanned = Html.fromHtml(source);
-        assertBadHtml(spanned);
+        verifyBadHtml(spanned);
         spanned = Html.fromHtml(source, null, null);
-        assertBadHtml(spanned);
+        verifyBadHtml(spanned);
     }
 
-    private void assertBadHtml(Spanned spanned) {
+    private void verifyBadHtml(Spanned spanned) {
         final int start = 0;
         final int end = 100;
         final int spansLen = 3;
@@ -84,6 +92,7 @@
         assertEquals(spansLen, spans.length);
     }
 
+    @Test
     public void testSymbols() {
         final String source = "&copy; &gt; &lt";
         final String expected = "\u00a9 > <";
@@ -94,7 +103,8 @@
         assertEquals(expected, spanned);
     }
 
-    public void testColor() throws Exception {
+    @Test
+    public void testColor() {
         final Class<ForegroundColorSpan> type = ForegroundColorSpan.class;
 
         Spanned s = Html.fromHtml("<font color=\"#00FF00\">something</font>");
@@ -139,7 +149,8 @@
         assertEquals(0xFF444444, colors[0].getForegroundColor());
     }
 
-    public void testUseCssColor() throws Exception {
+    @Test
+    public void testUseCssColor() {
         final Class<ForegroundColorSpan> type = ForegroundColorSpan.class;
         final int flags = Html.FROM_HTML_OPTION_USE_CSS_COLORS;
 
@@ -172,6 +183,7 @@
         assertEquals(0xFFA9A9A9, colors[0].getForegroundColor());
     }
 
+    @Test
     public void testStylesFromHtml() {
         Spanned s = Html.fromHtml("<span style=\"color:#FF0000; background-color:#00FF00; "
                 + "text-decoration:line-through;\">style</span>");
@@ -188,7 +200,8 @@
         assertEquals(1, strike.length);
     }
 
-    public void testParagraphs() throws Exception {
+    @Test
+    public void testParagraphs() {
         SpannableString s = new SpannableString("Hello world");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace(
                 "<p dir=\"ltr\">Hello world</p>"));
@@ -216,7 +229,8 @@
                 + "<p dir=\"ltr\" style=\"margin-top:0; margin-bottom:0;\">or something</p>"));
     }
 
-    public void testParagraphStyles() throws Exception {
+    @Test
+    public void testParagraphStyles() {
         SpannableString s = new SpannableString("Hello world");
         s.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER),
                 0, s.length(), Spanned.SPAN_PARAGRAPH);
@@ -243,7 +257,8 @@
                 + "Hello world</p>"));
     }
 
-    public void testBulletSpan() throws Exception {
+    @Test
+    public void testBulletSpan() {
         SpannableString s = new SpannableString("Bullet1\nBullet2\nNormal paragraph");
         s.setSpan(new BulletSpan(), 0, 8, Spanned.SPAN_PARAGRAPH);
         s.setSpan(new BulletSpan(), 8, 16, Spanned.SPAN_PARAGRAPH);
@@ -256,7 +271,8 @@
                 + "<p dir=\"ltr\" style=\"margin-top:0; margin-bottom:0;\">Normal paragraph</p>"));
     }
 
-    public void testBlockquote() throws Exception {
+    @Test
+    public void testBlockquote() {
         final int start = 0;
 
         SpannableString s = new SpannableString("Hello world");
@@ -272,7 +288,8 @@
                 "<blockquote><p dir=\"ltr\">Hello</p>\n</blockquote>\n<p dir=\"ltr\">world</p>"));
     }
 
-    public void testEntities() throws Exception {
+    @Test
+    public void testEntities() {
         SpannableString s = new SpannableString("Hello <&> world");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace(
                 "<p dir=\"ltr\">Hello &lt;&amp;&gt; world</p>"));
@@ -286,7 +303,8 @@
                 "<p dir=\"ltr\">Hello&nbsp; world</p>"));
     }
 
-    public void testMarkup() throws Exception {
+    @Test
+    public void testMarkup() {
         final int start = 6;
 
         SpannableString s = new SpannableString("Hello bold world");
@@ -350,7 +368,8 @@
                 + "<span style=\"background-color:#00FF00;\">background</span> world</p>"));
     }
 
-    public void testMarkupFromHtml() throws Exception {
+    @Test
+    public void testMarkupFromHtml() {
         final int expectedStart = 6;
         final int expectedEnd = expectedStart + 6;
 
@@ -371,7 +390,8 @@
      * {@link AlignmentSpan}s. Note that the span will also cover the first newline character after
      * the text.
      */
-    public void testTextAlignCssFromHtml() throws Exception {
+    @Test
+    public void testTextAlignCssFromHtml() {
         String tags[] = {"p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "blockquote"};
 
         for (String tag : tags) {
@@ -416,7 +436,8 @@
         }
     }
 
-    public void testBlockLevelElementsFromHtml() throws Exception {
+    @Test
+    public void testBlockLevelElementsFromHtml() {
         String source = "<blockquote>BLOCKQUOTE</blockquote>"
                 + "<div>DIV</div>"
                 + "<p>P</p>"
@@ -438,7 +459,8 @@
                 Html.fromHtml(source, flags, null, null).toString());
     }
 
-    public void testListFromHtml() throws Exception {
+    @Test
+    public void testListFromHtml() {
         String source = "CITRUS FRUITS:<ul><li>LEMON</li><li>LIME</li><li>ORANGE</li></ul>";
         assertEquals("CITRUS FRUITS:\n\nLEMON\n\nLIME\n\nORANGE\n\n",
                 Html.fromHtml(source).toString());
@@ -458,7 +480,8 @@
                 Html.fromHtml(source, flags, null, null).toString());
     }
 
-    public void testParagraphFromHtml() throws Exception {
+    @Test
+    public void testParagraphFromHtml() {
         final int flags = Html.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH;
 
         String source = "<p>Line 1</p><p>Line 2</p>";
@@ -486,7 +509,8 @@
                 Html.fromHtml(source).toString());
     }
 
-    public void testHeadingFromHtml() throws Exception {
+    @Test
+    public void testHeadingFromHtml() {
         final int flags = Html.FROM_HTML_SEPARATOR_LINE_BREAK_HEADING;
 
         String source = "<h1>Heading 1</h1><h1>Heading 2</h1>";
@@ -508,25 +532,29 @@
                 Html.fromHtml(source).toString());
     }
 
-    public void testImg() throws Exception {
+    @Test
+    public void testImg() {
         Spanned s = Html.fromHtml("yes<img src=\"http://example.com/foo.gif\">no");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace(
                 "<p dir=\"ltr\">yes<img src=\"http://example.com/foo.gif\">no</p>"));
     }
 
-    public void testUtf8() throws Exception {
+    @Test
+    public void testUtf8() {
         Spanned s = Html.fromHtml("<p>\u0124\u00eb\u0142\u0142o, world!</p>");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace(
                 "<p dir=\"ltr\">&#292;&#235;&#322;&#322;o, world!</p>"));
     }
 
-    public void testSurrogates() throws Exception {
+    @Test
+    public void testSurrogates() {
         Spanned s = Html.fromHtml("\ud83d\udc31");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace(
                 "<p dir=\"ltr\">&#128049;</p>"));
     }
 
-    public void testBadSurrogates() throws Exception {
+    @Test
+    public void testBadSurrogates() {
         Spanned s = Html.fromHtml("\udc31\ud83d");
         assertThat(Html.toHtml(s), matchesIgnoringTrailingWhitespace("<p dir=\"ltr\"></p>"));
     }
diff --git a/tests/tests/text/src/android/text/cts/InputFilter_AllCapsTest.java b/tests/tests/text/src/android/text/cts/InputFilter_AllCapsTest.java
index 93ee064..9e5d293 100644
--- a/tests/tests/text/src/android/text/cts/InputFilter_AllCapsTest.java
+++ b/tests/tests/text/src/android/text/cts/InputFilter_AllCapsTest.java
@@ -16,15 +16,22 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputFilter;
 import android.text.InputFilter.AllCaps;
 import android.text.SpannableStringBuilder;
 
-public class InputFilter_AllCapsTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class InputFilter_AllCapsTest {
+    @Test
     public void testFilter() {
-
         // Implicitly invoked
         CharSequence source = "Caps";
         SpannableStringBuilder dest = new SpannableStringBuilder("AllTest");
diff --git a/tests/tests/text/src/android/text/cts/InputFilter_LengthFilterTest.java b/tests/tests/text/src/android/text/cts/InputFilter_LengthFilterTest.java
index 49006df..722ad19 100644
--- a/tests/tests/text/src/android/text/cts/InputFilter_LengthFilterTest.java
+++ b/tests/tests/text/src/android/text/cts/InputFilter_LengthFilterTest.java
@@ -16,13 +16,21 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputFilter;
 import android.text.InputFilter.LengthFilter;
 import android.text.SpannableStringBuilder;
 
-public class InputFilter_LengthFilterTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class InputFilter_LengthFilterTest {
+    @Test
     public void testFilter() {
         // Define the variables
         CharSequence source;
diff --git a/tests/tests/text/src/android/text/cts/LayoutTest.java b/tests/tests/text/src/android/text/cts/LayoutTest.java
index b8e4bd1..d94fb23 100644
--- a/tests/tests/text/src/android/text/cts/LayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/LayoutTest.java
@@ -16,6 +16,12 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -24,7 +30,7 @@
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout;
 import android.text.Layout.Alignment;
 import android.text.Spannable;
@@ -32,10 +38,16 @@
 import android.text.TextPaint;
 import android.text.style.StrikethroughSpan;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.ArrayList;
 import java.util.List;
 
-public class LayoutTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LayoutTest {
     private final static int LINE_COUNT = 5;
     private final static int LINE_HEIGHT = 12;
     private final static int LINE_DESCENT = 4;
@@ -43,75 +55,79 @@
 
     private int mWidth;
     private Layout.Alignment mAlign;
-    private float mSpacingmult;
-    private float mSpacingadd;
+    private float mSpacingMult;
+    private float mSpacingAdd;
     private SpannableString mSpannedText;
 
     private TextPaint mTextPaint;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
         mTextPaint = new TextPaint();
         mSpannedText = new SpannableString(LAYOUT_TEXT);
         mSpannedText.setSpan(new StrikethroughSpan(), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
         mWidth = 11;
         mAlign = Alignment.ALIGN_CENTER;
-        mSpacingmult = 1;
-        mSpacingadd = 2;
+        mSpacingMult = 1;
+        mSpacingAdd = 2;
     }
 
+    @Test
     public void testConstructor() {
-        new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingmult, mSpacingadd);
-
-        try {
-            new MockLayout(null, null, -1, null, 0, 0);
-            fail("should throw IllegalArgumentException here");
-        } catch (IllegalArgumentException e) {
-        }
+        new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, mSpacingAdd);
     }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testConstructorNull() {
+        new MockLayout(null, null, -1, null, 0, 0);
+    }
+
+    @Test
     public void testGetText() {
         CharSequence text = "test case 1";
         Layout layout = new MockLayout(text, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(text, layout.getText());
 
-        layout = new MockLayout(null, mTextPaint, mWidth, mAlign, mSpacingmult, mSpacingadd);
+        layout = new MockLayout(null, mTextPaint, mWidth, mAlign, mSpacingMult, mSpacingAdd);
         assertNull(layout.getText());
     }
 
+    @Test
     public void testGetPaint() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
 
         assertSame(mTextPaint, layout.getPaint());
 
-        layout = new MockLayout(LAYOUT_TEXT, null, mWidth, mAlign, mSpacingmult, mSpacingadd);
+        layout = new MockLayout(LAYOUT_TEXT, null, mWidth, mAlign, mSpacingMult, mSpacingAdd);
         assertNull(layout.getPaint());
     }
 
+    @Test
     public void testGetWidth() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 10,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(10,  layout.getWidth());
 
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingmult, mSpacingadd);
+        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(0,  layout.getWidth());
     }
 
+    @Test
     public void testGetEllipsizedWidth() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 15,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(15, layout.getEllipsizedWidth());
 
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingmult, mSpacingadd);
+        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(0,  layout.getEllipsizedWidth());
     }
 
+    @Test
     public void testIncreaseWidthTo() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         int oldWidth = layout.getWidth();
 
         layout.increaseWidthTo(oldWidth);
@@ -127,40 +143,45 @@
         assertEquals(oldWidth + 1, layout.getWidth());
     }
 
+    @Test
     public void testGetHeight() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(60, layout.getHeight());
     }
 
+    @Test
     public void testGetAlignment() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertSame(mAlign, layout.getAlignment());
 
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, null, mSpacingmult, mSpacingadd);
+        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, null, mSpacingMult, mSpacingAdd);
         assertNull(layout.getAlignment());
     }
 
+    @Test
     public void testGetSpacingMultiplier() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, -1, mSpacingadd);
-        assertEquals(-1.0f, layout.getSpacingMultiplier());
+        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, -1, mSpacingAdd);
+        assertEquals(-1.0f, layout.getSpacingMultiplier(), 0.0f);
 
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, 5, mSpacingadd);
-        assertEquals(5.0f, layout.getSpacingMultiplier());
+        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, 5, mSpacingAdd);
+        assertEquals(5.0f, layout.getSpacingMultiplier(), 0.0f);
     }
 
+    @Test
     public void testGetSpacingAdd() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingmult, -1);
-        assertEquals(-1.0f, layout.getSpacingAdd());
+        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, -1);
+        assertEquals(-1.0f, layout.getSpacingAdd(), 0.0f);
 
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingmult, 20);
-        assertEquals(20.0f, layout.getSpacingAdd());
+        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, 20);
+        assertEquals(20.0f, layout.getSpacingAdd(), 0.0f);
     }
 
+    @Test
     public void testGetLineBounds() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         Rect bounds = new Rect();
 
         assertEquals(32, layout.getLineBounds(2, bounds));
@@ -170,33 +191,37 @@
         assertEquals(36, bounds.bottom);
     }
 
+    @Test
     public void testGetLineForVertical() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(0, layout.getLineForVertical(-1));
         assertEquals(0, layout.getLineForVertical(0));
         assertEquals(0, layout.getLineForVertical(LINE_COUNT));
         assertEquals(LINE_COUNT - 1, layout.getLineForVertical(1000));
     }
 
+    @Test
     public void testGetLineForOffset() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(0, layout.getLineForOffset(-1));
         assertEquals(1, layout.getLineForOffset(1));
         assertEquals(LINE_COUNT - 1, layout.getLineForOffset(LINE_COUNT - 1));
         assertEquals(LINE_COUNT - 1, layout.getLineForOffset(1000));
     }
 
+    @Test
     public void testGetLineEnd() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(2, layout.getLineEnd(1));
     }
 
+    @Test
     public void testGetLineVisibleEnd() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
 
         assertEquals(2, layout.getLineVisibleEnd(1));
         assertEquals(LINE_COUNT, layout.getLineVisibleEnd(LINE_COUNT - 1));
@@ -208,59 +233,67 @@
         }
     }
 
+    @Test
     public void testGetLineBottom() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(LINE_HEIGHT, layout.getLineBottom(0));
     }
 
+    @Test
     public void testGetLineBaseline() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(8, layout.getLineBaseline(0));
     }
 
+    @Test
     public void testGetLineAscent() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(-8, layout.getLineAscent(0));
     }
 
+    @Test
     public void testGetParagraphAlignment() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertSame(mAlign, layout.getParagraphAlignment(0));
 
         layout = new MockLayout(mSpannedText, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertSame(mAlign, layout.getParagraphAlignment(0));
         assertSame(mAlign, layout.getParagraphAlignment(1));
     }
 
+    @Test
     public void testGetParagraphLeft() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(0, layout.getParagraphLeft(0));
     }
 
+    @Test
     public void testGetParagraphRight() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertEquals(mWidth, layout.getParagraphRight(0));
     }
 
+    @Test
     public void testIsSpanned() {
         MockLayout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         // default is not spanned text
         assertFalse(layout.mockIsSpanned());
 
         // try to create a spanned text
         layout = new MockLayout(mSpannedText, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         assertTrue(layout.mockIsSpanned());
     }
 
+    @Test
     public void testGetDesiredWidthRange() {
         CharSequence textShort = "test";
         CharSequence textLonger = "test\ngetDesiredWidth";
@@ -273,10 +306,11 @@
         float widthZero = Layout.getDesiredWidth(textLonger, 5, textShort.length() - 3, paint);
         assertTrue(widthLonger > widthShort);
         assertTrue(widthLongest > widthLonger);
-        assertEquals(0f, widthZero);
+        assertEquals(0f, widthZero, 0.0f);
         assertTrue(widthShort > widthPartShort);
     }
 
+    @Test
     public void testGetDesiredWidth() {
         CharSequence textShort = "test";
         CharSequence textLonger = "test\ngetDesiredWidth";
@@ -361,10 +395,10 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testGetLineWidth() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         for (int i = 0; i < LINE_COUNT; i++) {
             int start = layout.getLineStart(i);
             int end = layout.getLineEnd(i);
@@ -373,10 +407,10 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testGetCursorPath() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         Path path = new Path();
         final float epsilon = 1.0f;
         for (int i = 0; i < LINE_COUNT; i++) {
@@ -388,10 +422,10 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDraw() {
         Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingmult, mSpacingadd);
+                mAlign, mSpacingMult, mSpacingAdd);
         final int width = 256;
         final int height = 256;
         MockCanvas c = new MockCanvas(width, height);
@@ -404,7 +438,7 @@
             int end = layout.getLineEnd(i);
             assertEquals(LAYOUT_TEXT.toString().substring(start, end), drawCommand.text);
             float expected_y = (i + 1) * LINE_HEIGHT - LINE_DESCENT;
-            assertEquals(expected_y, drawCommand.y);
+            assertEquals(expected_y, drawCommand.y, 0.0f);
         }
     }
 
diff --git a/tests/tests/text/src/android/text/cts/LoginFilterTest.java b/tests/tests/text/src/android/text/cts/LoginFilterTest.java
index c968bfa..9ebc7ec 100644
--- a/tests/tests/text/src/android/text/cts/LoginFilterTest.java
+++ b/tests/tests/text/src/android/text/cts/LoginFilterTest.java
@@ -16,9 +16,19 @@
 
 package android.text.cts;
 
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyChar;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.LoginFilter;
 import android.text.LoginFilter.UsernameFilterGeneric;
 import android.text.SpannableString;
@@ -27,13 +37,13 @@
 
 import junit.framework.TestCase;
 
-public class LoginFilterTest extends TestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LoginFilterTest {
+    @Test
     public void testFilter() {
         CharSequence result;
         LoginFilter loginFilter = spy(new UsernameFilterGeneric());
@@ -121,6 +131,7 @@
 
     // This method does nothing. we only test onInvalidCharacter function here,
     // the callback should be tested in testFilter()
+    @Test
     public void testOnInvalidCharacter() {
         LoginFilter loginFilter = new UsernameFilterGeneric();
         loginFilter.onInvalidCharacter('a');
@@ -128,6 +139,7 @@
 
     // This method does nothing. we only test onStop function here,
     // the callback should be tested in testFilter()
+    @Test
     public void testOnStop() {
         LoginFilter loginFilter = new UsernameFilterGeneric();
         loginFilter.onStop();
@@ -135,6 +147,7 @@
 
     // This method does nothing. we only test onStart function here,
     // the callback should be tested in testFilter()
+    @Test
     public void testOnStart() {
         LoginFilter loginFilter = new UsernameFilterGeneric();
         loginFilter.onStart();
diff --git a/tests/tests/text/src/android/text/cts/LoginFilter_PasswordFilterGMailTest.java b/tests/tests/text/src/android/text/cts/LoginFilter_PasswordFilterGMailTest.java
index ec567c3..1f02481 100644
--- a/tests/tests/text/src/android/text/cts/LoginFilter_PasswordFilterGMailTest.java
+++ b/tests/tests/text/src/android/text/cts/LoginFilter_PasswordFilterGMailTest.java
@@ -16,19 +16,27 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.LoginFilter.PasswordFilterGMail;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class LoginFilter_PasswordFilterGMailTest extends TestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LoginFilter_PasswordFilterGMailTest {
+    @Test
     public void testConstructor() {
         new PasswordFilterGMail();
         new PasswordFilterGMail(true);
         new PasswordFilterGMail(false);
     }
 
+    @Test
     public void testIsAllowed() {
         PasswordFilterGMail passwordFilterGMail = new PasswordFilterGMail();
 
diff --git a/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGMailTest.java b/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGMailTest.java
index 90cc097..fd196b8 100644
--- a/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGMailTest.java
+++ b/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGMailTest.java
@@ -16,18 +16,27 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.LoginFilter.UsernameFilterGMail;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class LoginFilter_UsernameFilterGMailTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LoginFilter_UsernameFilterGMailTest {
+    @Test
     public void testConstructor() {
         new UsernameFilterGMail();
         new UsernameFilterGMail(true);
         new UsernameFilterGMail(false);
     }
 
+    @Test
     public void testIsAllowed() {
         UsernameFilterGMail usernameFilterGMail = new UsernameFilterGMail();
 
diff --git a/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGenericTest.java b/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGenericTest.java
index f9043ee..68cc840 100644
--- a/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGenericTest.java
+++ b/tests/tests/text/src/android/text/cts/LoginFilter_UsernameFilterGenericTest.java
@@ -16,19 +16,27 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.LoginFilter.UsernameFilterGeneric;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class LoginFilter_UsernameFilterGenericTest extends TestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LoginFilter_UsernameFilterGenericTest {
+    @Test
     public void testConstructor() {
         new UsernameFilterGeneric();
         new UsernameFilterGeneric(true);
         new UsernameFilterGeneric(false);
     }
 
+    @Test
     public void testIsAllowed() {
         UsernameFilterGeneric usernameFilterGeneric = new UsernameFilterGeneric();
 
diff --git a/tests/tests/text/src/android/text/cts/MyanmarTest.java b/tests/tests/text/src/android/text/cts/MyanmarTest.java
index 9988ab9..5ded363 100644
--- a/tests/tests/text/src/android/text/cts/MyanmarTest.java
+++ b/tests/tests/text/src/android/text/cts/MyanmarTest.java
@@ -16,41 +16,40 @@
 
 package android.text.cts;
 
-import android.app.Activity;
+import static org.junit.Assert.assertTrue;
+
 import android.content.Context;
 import android.graphics.Bitmap;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.widget.TextView;
 
-public class MyanmarTest extends ActivityInstrumentationTestCase2<Activity> {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-    public MyanmarTest() {
-        super("android.text.cts", Activity.class);
-    }
-
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class MyanmarTest {
     /**
      * Tests Unicode composition semantics.
      */
+    @UiThreadTest
+    @Test
     public void testCompositionSemantics() {
+        Context context = InstrumentationRegistry.getTargetContext();
         String textA = "\u1019\u102d\u102f";
         String textB = "\u1019\u102f\u102d"; // wrong order for Unicode
 
-        CaptureTextView cviewA = new CaptureTextView(getInstrumentation().getContext());
+        CaptureTextView cviewA = new CaptureTextView(context);
         Bitmap bitmapA = cviewA.capture(textA);
-        CaptureTextView cviewB = new CaptureTextView(getInstrumentation().getContext());
+        CaptureTextView cviewB = new CaptureTextView(context);
         Bitmap bitmapB = cviewB.capture(textB);
         if (bitmapA.sameAs(bitmapB)) {
             // if textA and textB render identically, test against replacement characters
             String textC = "\ufffd\ufffd\ufffd"; // replacement characters are acceptable
-            CaptureTextView cviewC = new CaptureTextView(getInstrumentation().getContext());
+            CaptureTextView cviewC = new CaptureTextView(context);
             Bitmap bitmapC = cviewC.capture(textC);
             if (!bitmapA.sameAs(bitmapC)) {
                 // ...or against blank/empty glyphs
diff --git a/tests/tests/text/src/android/text/cts/SelectionTest.java b/tests/tests/text/src/android/text/cts/SelectionTest.java
index 4946a50..f920bda 100644
--- a/tests/tests/text/src/android/text/cts/SelectionTest.java
+++ b/tests/tests/text/src/android/text/cts/SelectionTest.java
@@ -16,14 +16,25 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Selection;
 import android.text.SpannableStringBuilder;
 import android.text.StaticLayout;
 import android.text.TextPaint;
 
-public class SelectionTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SelectionTest {
+    @Test
     public void testGetSelectionStart() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -41,6 +52,7 @@
         assertEquals(-1, Selection.getSelectionStart(null));
     }
 
+    @Test
     public void testGetSelectionEnd() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -58,6 +70,7 @@
         assertEquals(-1, Selection.getSelectionStart(null));
     }
 
+    @Test
     public void testSetSelection1() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -87,6 +100,7 @@
         }
     }
 
+    @Test
     public void testSetSelection2() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         assertEquals(-1, Selection.getSelectionStart(builder));
@@ -113,6 +127,7 @@
         }
     }
 
+    @Test
     public void testRemoveSelection() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -132,6 +147,7 @@
         assertEquals(-1, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testSelectAll() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -158,6 +174,7 @@
         assertEquals(0, Selection.getSelectionEnd(empty));
     }
 
+    @Test
     public void testMoveLeft() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -185,6 +202,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testMoveRight() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -216,6 +234,7 @@
         assertEquals(text.length(), Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testMoveUp() {
         CharSequence text = "Google\nhello,world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -255,6 +274,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testMoveDown() {
         CharSequence text = "hello,world\nGoogle";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -292,6 +312,7 @@
         assertEquals(18, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendSelection() {
         CharSequence text = "hello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -338,6 +359,7 @@
         }
     }
 
+    @Test
     public void testExtendLeft() {
         CharSequence text = "Google\nhello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -364,6 +386,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendRight() {
         CharSequence text = "Google\nhello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -386,6 +409,7 @@
         assertEquals(text.length(), Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendUp() {
         CharSequence text = "Google\nhello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -416,6 +440,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendDown() {
         CharSequence text = "Google\nhello, world";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -437,6 +462,7 @@
         assertEquals(text.length(), Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendToLeftEdge() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -472,6 +498,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testExtendToRightEdge() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -498,6 +525,7 @@
         assertEquals(text.length(), Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testMoveToLeftEdge() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -529,6 +557,7 @@
         assertEquals(0, Selection.getSelectionEnd(builder));
     }
 
+    @Test
     public void testMoveToRightEdge() {
         CharSequence text = "hello\nworld";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
diff --git a/tests/tests/text/src/android/text/cts/SpannableStringBuilderSpanTest.java b/tests/tests/text/src/android/text/cts/SpannableStringBuilderSpanTest.java
index a57dbab..f693038 100644
--- a/tests/tests/text/src/android/text/cts/SpannableStringBuilderSpanTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannableStringBuilderSpanTest.java
@@ -16,8 +16,12 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Html;
 import android.text.SpanWatcher;
 import android.text.Spannable;
@@ -27,19 +31,24 @@
 import android.text.style.ParagraphStyle;
 import android.text.style.QuoteSpan;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.ArrayList;
 
 /**
  * Test {@link SpannableStringBuilder}.
  */
-public class SpannableStringBuilderSpanTest extends AndroidTestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SpannableStringBuilderSpanTest {
     private static final boolean DEBUG = false;
 
     private SpanSet mSpanSet = new SpanSet();
     private SpanSet mReplacementSpanSet = new SpanSet();
     private int testCounter;
 
+    @Test
     public void testReplaceWithSpans() {
         testCounter = 0;
         String originals[] = { "", "A", "here", "Well, hello there" };
@@ -116,13 +125,13 @@
 
         assertEquals(expected, originalSpannable.toString());
 
-        checkSpanPositions(originalSpannable, replaceStart, replaceEnd, subReplacement.length(),
+        verifySpanPositions(originalSpannable, replaceStart, replaceEnd, subReplacement.length(),
                 flag);
-        checkReplacementSpanPositions(originalSpannable, replaceStart, replacementSpannable,
+        verifyReplacementSpanPositions(originalSpannable, replaceStart, replacementSpannable,
                 replacementStart, replacementEnd, flag);
     }
 
-    private void checkSpanPositions(Spannable spannable, int replaceStart, int replaceEnd,
+    private void verifySpanPositions(Spannable spannable, int replaceStart, int replaceEnd,
             int replacementLength, int flag) {
         int count = 0;
         int replacedLength = replaceEnd - replaceStart;
@@ -154,7 +163,7 @@
                     // 0-length spans should have been removed
                     assertEquals(-1, start);
                     assertEquals(-1, end);
-                    mSpanSet.mRecorder.assertRemoved(span, originalStart, originalEnd);
+                    mSpanSet.mRecorder.verifyRemoved(span, originalStart, originalEnd);
                     continue;
                 }
 
@@ -227,15 +236,15 @@
                 }
 
                 if (start != originalStart || end != originalEnd) {
-                    mSpanSet.mRecorder.assertChanged(span, originalStart, originalEnd, start, end);
+                    mSpanSet.mRecorder.verifyChanged(span, originalStart, originalEnd, start, end);
                 } else {
-                    mSpanSet.mRecorder.assertUnmodified(span);
+                    mSpanSet.mRecorder.verifyUnmodified(span);
                 }
             }
         }
     }
 
-    private void checkReplacementSpanPositions(Spannable originalSpannable, int replaceStart,
+    private void verifyReplacementSpanPositions(Spannable originalSpannable, int replaceStart,
             Spannable replacementSpannable, int replStart, int replEnd, int flag) {
 
         // Get all spans overlapping the replacement substring region
@@ -257,7 +266,7 @@
                         " -> " + start + "," + end);
 
                 // There should be no change reported to the replacement string spanWatcher
-                mReplacementSpanSet.mRecorder.assertUnmodified(span);
+                mReplacementSpanSet.mRecorder.verifyUnmodified(span);
 
                 boolean shouldBeAdded = false;
                 for (int i = 0; i < addedSpans.length; i++) {
@@ -273,12 +282,12 @@
                     if (isValidSpan(newStart, newEnd, flag)) {
                         assertEquals(start, newStart);
                         assertEquals(end, newEnd);
-                        mSpanSet.mRecorder.assertAdded(span, start, end);
+                        mSpanSet.mRecorder.verifyAdded(span, start, end);
                         continue;
                     }
                 }
 
-                mSpanSet.mRecorder.assertUnmodified(span);
+                mSpanSet.mRecorder.verifyUnmodified(span);
             }
         }
     }
@@ -443,7 +452,7 @@
             if (text == mSpannable) mChanged.add(new Changed(span, ostart, oend, nstart, nend));
         }
 
-        public void assertUnmodified(Object span) {
+        public void verifyUnmodified(Object span) {
             for (AddedRemoved added: mAdded) {
                 if (added.span == span)
                     fail("Span " + span + " was added and not unmodified");
@@ -458,7 +467,7 @@
             }
         }
 
-        public void assertChanged(Object span, int oldStart, int oldEnd, int newStart, int newEnd) {
+        public void verifyChanged(Object span, int oldStart, int oldEnd, int newStart, int newEnd) {
             for (Changed changed : mChanged) {
                 if (changed.span == span) {
                     assertEquals(changed.newStart, newStart);
@@ -473,7 +482,7 @@
             fail("Span " + span + " was not changed");
         }
 
-        public void assertAdded(Object span, int start, int end) {
+        public void verifyAdded(Object span, int start, int end) {
             for (AddedRemoved added : mAdded) {
                 if (added.span == span) {
                     assertEquals(added.start, start);
@@ -484,7 +493,7 @@
             fail("Span " + span + " was not added");
         }
 
-        public void assertRemoved(Object span, int start, int end) {
+        public void verifyRemoved(Object span, int start, int end) {
             for (AddedRemoved removed : mRemoved) {
                 if (removed.span == span) {
                     assertEquals(removed.start, start);
@@ -499,10 +508,8 @@
     // TODO Thoroughly test the SPAN_PARAGRAPH span flag.
 
 
-    @SmallTest
-    public void
-    testReplace_discardsParagraphSpanInSourceIfThereIsNoNewLineBefore()
-            throws Exception {
+    @Test
+    public void testReplace_discardsParagraphSpanInSourceIfThereIsNoNewLineBefore() {
         SpannableStringBuilder spannable = new SpannableStringBuilder("1 selection_to_replace");
         Spanned newText = Html.fromHtml("<blockquote>new text</blockquote>");
         assertEquals(1, newText.getSpans(0, newText.length(), ParagraphStyle.class).length);
@@ -514,9 +521,8 @@
         assertEquals(0, paragraphSpans.length);
     }
 
-    @SmallTest
-    public void testReplace_retainsParagraphSpanInSourceIfThereIsNewLineBefore()
-            throws Exception {
+    @Test
+    public void testReplace_retainsParagraphSpanInSourceIfThereIsNewLineBefore() {
         SpannableStringBuilder spannable = new SpannableStringBuilder("1\nselection_to_replace");
         Spanned newText = Html.fromHtml("<blockquote>new text</blockquote>");
         assertTrue(newText.getSpans(0, newText.length(), ParagraphStyle.class).length > 0);
@@ -528,9 +534,8 @@
         assertEquals(1, paragraphSpans.length);
     }
 
-    @SmallTest
-    public void testReplace_retainsParagraphSpanInSourceIfStartIsZero()
-            throws Exception {
+    @Test
+    public void testReplace_retainsParagraphSpanInSourceIfStartIsZero() {
         // copy the paragraph span even if there is no previous character - start is equal to 0
 
         SpannableStringBuilder spannable = new SpannableStringBuilder("selection_to_replace");
@@ -544,9 +549,8 @@
         assertEquals(1, paragraphSpans.length);
     }
 
-    @SmallTest
-    public void testReplace_retainsParagraphSpanInSourceIfEndIsEqualToLengthOfString()
-            throws Exception {
+    @Test
+    public void testReplace_retainsParagraphSpanInSourceIfEndIsEqualToLengthOfString() {
         // copy the paragraph span even if the final char is not next line, and if the end is
         // equal to the string length
 
@@ -564,9 +568,8 @@
         assertEquals(1, paragraphSpans.length);
     }
 
-    @SmallTest
-    public void testReplace_discardsParagraphSpanInSourceIfThereIsNoNewLineAfter()
-            throws Exception {
+    @Test
+    public void testReplace_discardsParagraphSpanInSourceIfThereIsNoNewLineAfter() {
         SpannableStringBuilder spannable = new SpannableStringBuilder("r remaining\n");
         // create a spannable that does not have \n at the end. Html.fromHtml adds \n to the end of
         // the text
@@ -580,5 +583,4 @@
                 ParagraphStyle.class);
         assertEquals(0, paragraphSpans.length);
     }
-
 }
diff --git a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
index 426e831..70a68ea 100644
--- a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
@@ -17,8 +17,14 @@
 package android.text.cts;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.InputFilter;
 import android.text.Selection;
@@ -33,63 +39,60 @@
 import android.text.style.TabStopSpan;
 import android.text.style.UnderlineSpan;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Arrays;
 
 /**
  * Test {@link SpannableStringBuilder}.
  */
-public class SpannableStringBuilderTest extends AndroidTestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SpannableStringBuilderTest {
     private StrikethroughSpan mStrikethroughSpan;
     private UnderlineSpan mUnderlineSpan;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
         mUnderlineSpan = new UnderlineSpan();
         mStrikethroughSpan = new StrikethroughSpan();
     }
 
-    public void testConstructor1() {
-        @SuppressWarnings("unused")
-        SpannableStringBuilder dummy = new SpannableStringBuilder();
-        dummy = new SpannableStringBuilder("test");
-
-        try {
-            dummy = new SpannableStringBuilder(null);
-            fail("should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected exception
-        }
+    @Test
+    public void testConstructor() {
+        new SpannableStringBuilder();
+        new SpannableStringBuilder("test");
     }
 
-    public void testConstructor2() {
-        @SuppressWarnings("unused")
-        SpannableStringBuilder dummy = new SpannableStringBuilder("Text", 0, "Text".length());
-        dummy = new SpannableStringBuilder(new SpannableString("test"), 0, "Text".length());
-
-        try {
-            dummy = new SpannableStringBuilder("Text", 0, 10);
-            fail("should throw StringIndexOutOfBoundsException");
-        } catch (StringIndexOutOfBoundsException e) {
-            // expected exception
-        }
-
-        try {
-            dummy = new SpannableStringBuilder("Text", -3, 3);
-            fail("should throw StringIndexOutOfBoundsException");
-        } catch (StringIndexOutOfBoundsException e) {
-            // expected exception
-        }
-
-        try {
-            dummy = new SpannableStringBuilder("Text", 3, 0);
-            fail("should throw StringIndexOutOfBoundsException");
-        } catch (StringIndexOutOfBoundsException e) {
-            // expected exception
-        }
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNullString() {
+         new SpannableStringBuilder(null);
     }
 
+    @Test
+    public void testConstructorStartEnd() {
+        new SpannableStringBuilder("Text", 0, "Text".length());
+        new SpannableStringBuilder(new SpannableString("test"), 0, "Text".length());
+    }
+
+    @Test(expected=StringIndexOutOfBoundsException.class)
+    public void testConstructorStartEndEndTooLarge() {
+        new SpannableStringBuilder("Text", 0, 10);
+    }
+
+    @Test(expected=StringIndexOutOfBoundsException.class)
+    public void testConstructorStartEndStartTooLow() {
+        new SpannableStringBuilder("Text", -3, 3);
+    }
+
+    @Test(expected=StringIndexOutOfBoundsException.class)
+    public void testConstructorStartEndEndTooLow() {
+        new SpannableStringBuilder("Text", 3, 0);
+    }
+
+    @Test
     public void testGetSpanFlags() {
         SpannableStringBuilder builder = new SpannableStringBuilder("spannable string");
         assertEquals(0, builder.getSpanFlags(mUnderlineSpan));
@@ -103,6 +106,7 @@
         assertEquals(0, builder.getSpanFlags(new Object()));
     }
 
+    @Test
     public void testNextSpanTransition() {
         SpannableStringBuilder builder = new SpannableStringBuilder("spannable string");
 
@@ -118,6 +122,7 @@
         assertEquals(1, builder.nextSpanTransition(3, 1, UnderlineSpan.class));
     }
 
+    @Test
     public void testSetSpan() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         try {
@@ -145,27 +150,25 @@
         assertEquals(Spanned.SPAN_EXCLUSIVE_EXCLUSIVE, builder.getSpanFlags(mUnderlineSpan));
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testValueOfNull() {
+        SpannableStringBuilder.valueOf(null);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testValueOfNullBuilder() {
+        SpannableStringBuilder.valueOf((SpannableStringBuilder) null);
+    }
+
+    @Test
     public void testValueOf() {
-        try {
-            SpannableStringBuilder.valueOf(null);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-            // expected exception
-        }
-
-        try {
-            SpannableStringBuilder.valueOf((SpannableStringBuilder) null);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-            // expected exception
-        }
-
         assertNotNull(SpannableStringBuilder.valueOf("hello, string"));
 
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         assertSame(builder, SpannableStringBuilder.valueOf(builder));
     }
 
+    @Test
     public void testReplace1() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world!");
         CharSequence text = "hi";
@@ -198,6 +201,7 @@
         }
     }
 
+    @Test
     public void testReplace2() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         CharSequence text = "ahiabc";
@@ -273,6 +277,7 @@
         }
     }
 
+    @Test
     public void testSubSequence() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         CharSequence text = builder.subSequence(0, 2);
@@ -287,6 +292,7 @@
         }
     }
 
+    @Test
     public void testGetChars() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         char[] buf = new char[4];
@@ -320,6 +326,7 @@
         }
     }
 
+    @Test
     public void testAppend1() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.append(",world");
@@ -332,6 +339,7 @@
         }
     }
 
+    @Test
     public void testAppend2() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.append(",world", 1, 3);
@@ -363,6 +371,7 @@
         }
     }
 
+    @Test
     public void testAppend3() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.append('a');
@@ -378,7 +387,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testAppend_textWithSpan() {
         final QuoteSpan span = new QuoteSpan();
         final SpannableStringBuilder builder = new SpannableStringBuilder("hello ");
@@ -400,6 +409,7 @@
                 spanEnd, builder.getSpanEnd(spans[0]));
     }
 
+    @Test
     public void testClearSpans() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
 
@@ -414,6 +424,7 @@
         assertEquals(0, builder.getSpanFlags(mUnderlineSpan));
     }
 
+    @Test
     public void testGetSpanStart() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.setSpan(mUnderlineSpan, 1, 3, 0);
@@ -422,6 +433,7 @@
         assertEquals(-1, builder.getSpanStart(null));
     }
 
+    @Test
     public void testAccessFilters() {
         InputFilter[] filters = new InputFilter[100];
         SpannableStringBuilder builder = new SpannableStringBuilder();
@@ -436,6 +448,7 @@
         }
     }
 
+    @Test
     public void testRemoveSpan() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
 
@@ -458,6 +471,7 @@
         builder.removeSpan(null);
     }
 
+    @Test
     public void testToString() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         assertEquals("hello", builder.toString());
@@ -466,6 +480,7 @@
         assertEquals("", builder.toString());
     }
 
+    @Test
     public void testGetSpanEnd() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.setSpan(mUnderlineSpan, 1, 3, 0);
@@ -474,6 +489,7 @@
         assertEquals(-1, builder.getSpanEnd(null));
     }
 
+    @Test
     public void testCharAt() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         assertEquals('h', builder.charAt(0));
@@ -493,6 +509,7 @@
         }
     }
 
+    @Test
     public void testInsert1() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.insert(1, "abcd", 1, 3);
@@ -538,6 +555,7 @@
         }
     }
 
+    @Test
     public void testInsert2() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.insert(1, "abcd");
@@ -569,6 +587,7 @@
         }
     }
 
+    @Test
     public void testClear() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         assertEquals("hello", builder.toString());
@@ -576,6 +595,7 @@
         assertEquals("", builder.toString());
     }
 
+    @Test
     public void testGetSpans() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello, world");
         UnderlineSpan span1 = new UnderlineSpan();
@@ -600,7 +620,7 @@
         builder.getSpans(4, 1, UnderlineSpan.class);
     }
 
-    @SmallTest
+    @Test
     public void testGetSpans_returnsEmptyIfSetSpanIsNotCalled() {
         String text = "p_in_s";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -608,7 +628,7 @@
         assertEquals(0, spans.length);
     }
 
-    @SmallTest
+    @Test
     public void testGetSpans_returnsSpansInInsertionOrderWhenTheLaterCoversTheFirst() {
         String text = "p_in_s";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -626,7 +646,7 @@
         assertEquals(second, spans[1]);
     }
 
-    @SmallTest
+    @Test
     public void testGetSpans_returnsSpansSortedFirstByPriorityThenByInsertionOrder() {
         String text = "p_in_s";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -653,7 +673,7 @@
         assertEquals(third, spans[3]);
     }
 
-    @SmallTest
+    @Test
     public void testGetSpans_returnsSpansInInsertionOrderAfterRemoveSpanCalls() {
         String text = "p_in_s";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -678,7 +698,7 @@
         assertEquals(fourth, spans[1]);
     }
 
-    @SmallTest
+    @Test
     public void testGetSpans_sortsByPriorityEvenWhenSortParamIsFalse() {
         String text = "p_in_s";
         SpannableStringBuilder builder = new SpannableStringBuilder(text);
@@ -704,6 +724,7 @@
         assertEquals(first, spans[3]);
     }
 
+    @Test
     public void testLength() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         assertEquals(5, builder.length());
@@ -711,6 +732,7 @@
         assertEquals(0, builder.length());
     }
 
+    @Test
     public void testReplace_shouldNotThrowIndexOutOfBoundsExceptionForLongText() {
         final char[] charArray = new char[75000];
         Arrays.fill(charArray, 'a');
@@ -724,6 +746,7 @@
         assertEquals(copiedText.length(), spannable.length());
     }
 
+    @Test
     public void testDelete() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello,world");
         assertEquals("hello,world", builder.toString());
@@ -782,6 +805,7 @@
         }
     }
 
+    @Test
     public void testGetTextWatcherDepth() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         builder.setSpan(new MockTextWatcher(), 0, builder.length(), 0);
diff --git a/tests/tests/text/src/android/text/cts/Spannable_FactoryTest.java b/tests/tests/text/src/android/text/cts/Spannable_FactoryTest.java
index e3ad7ca..4969e67 100644
--- a/tests/tests/text/src/android/text/cts/Spannable_FactoryTest.java
+++ b/tests/tests/text/src/android/text/cts/Spannable_FactoryTest.java
@@ -16,13 +16,24 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Spannable;
 import android.text.Spannable.Factory;
 import android.text.SpannableString;
 
-public class Spannable_FactoryTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class Spannable_FactoryTest {
+    @Test
     public void testNewSpannable() {
         final String text = "test newSpannable";
         Factory factory = Spannable.Factory.getInstance();
@@ -31,14 +42,15 @@
         assertNotNull(spannable);
         assertTrue(spannable instanceof SpannableString);
         assertEquals(text, spannable.toString());
-
-        try {
-            factory.newSpannable(null);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testNewSpannableNull() {
+        Factory factory = Spannable.Factory.getInstance();
+        factory.newSpannable(null);
+    }
+
+    @Test
     public void testGetInstance() {
         Spannable.Factory factory = Spannable.Factory.getInstance();
         assertNotNull(factory);
diff --git a/tests/tests/text/src/android/text/cts/SpannedStringTest.java b/tests/tests/text/src/android/text/cts/SpannedStringTest.java
index 3c9b41b..ccdb119 100644
--- a/tests/tests/text/src/android/text/cts/SpannedStringTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannedStringTest.java
@@ -16,20 +16,32 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.SpannedString;
 
-public class SpannedStringTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SpannedStringTest {
+    @Test
     public void testConstructor() {
         new SpannedString("test");
-
-        try {
-            new SpannedString(null);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNull() {
+        new SpannedString(null);
+    }
+
+    @Test
     public void testValueOf() {
         String text = "test valueOf";
         SpannedString spanned = SpannedString.valueOf(text);
@@ -37,14 +49,14 @@
 
         spanned = new SpannedString(text);
         assertSame(spanned, SpannedString.valueOf(spanned));
-
-        try {
-            SpannedString.valueOf(null);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testValueOfNull() {
+        SpannedString.valueOf(null);
+    }
+
+    @Test
     public void testSubSequence() {
         String text = "hello, world";
         SpannedString spanned = new SpannedString(text);
diff --git a/tests/tests/text/src/android/text/cts/SpannedTest.java b/tests/tests/text/src/android/text/cts/SpannedTest.java
index 949ddb5..12ebfed 100644
--- a/tests/tests/text/src/android/text/cts/SpannedTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannedTest.java
@@ -16,8 +16,11 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
@@ -27,10 +30,14 @@
 import android.text.style.QuoteSpan;
 import android.text.style.UnderlineSpan;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 
-public class SpannedTest extends AndroidTestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SpannedTest {
     // Returns an array of three Spanned objects, of three different classes:
     // SpannableString, SpannableStringBuilder, and SpannedString.
     private static Spanned[] makeSpanned(CharSequence s) {
@@ -40,7 +47,7 @@
                 new SpannedString(s)};
     }
 
-    @SmallTest
+    @Test
     public void testCharAt() {
         final Spanned[] spannedCases = makeSpanned("\uD83D\uDE00");  // U+1F600 GRINNING FACE
         for (Spanned spanned : spannedCases) {
@@ -61,7 +68,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testNextSpanTransition() {
         final int flags = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
         final SpannableString text = new SpannableString("0123 5678");
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java
index d990ffb..5055972 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java
@@ -16,7 +16,11 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout.Alignment;
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
@@ -26,7 +30,12 @@
 import android.text.style.MetricAffectingSpan;
 import android.util.Log;
 
-public class StaticLayoutLineBreakingTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class StaticLayoutLineBreakingTest {
     // Span test are currently not supported because text measurement uses the MeasuredText
     // internal mWorkPaint instead of the provided MockTestPaint.
     private static final boolean SPAN_TESTS_SUPPORTED = false;
@@ -37,8 +46,8 @@
     private static final int WIDTH = 100;
     private static final Alignment ALIGN = Alignment.ALIGN_LEFT;
 
-    final static char SURR_FIRST = '\uD800';
-    final static char SURR_SECOND = '\uDF31';
+    private static final char SURR_FIRST = '\uD800';
+    private static final char SURR_SECOND = '\uDF31';
 
     private static final int[] NO_BREAK = new int[] {};
 
@@ -116,12 +125,12 @@
     private static void debugLayout(CharSequence source, StaticLayout staticLayout) {
         if (DEBUG) {
             int count = staticLayout.getLineCount();
-            Log.i("StaticLayoutLineBreakingTest", "\"" + source.toString() + "\": " +
+            Log.i("SLLBTest", "\"" + source.toString() + "\": " +
                     count + " lines");
             for (int line = 0; line < count; line++) {
                 int lineStart = staticLayout.getLineStart(line);
                 int lineEnd = staticLayout.getLineEnd(line);
-                Log.i("StaticLayoutLineBreakingTest", "Line " + line + " [" + lineStart + ".." +
+                Log.i("SLLBTest", "Line " + line + " [" + lineStart + ".." +
                         lineEnd + "]\t" + source.subSequence(lineStart, lineEnd));
             }
         }
@@ -185,9 +194,9 @@
         }
     }
 
-    final static int MAX_SPAN_COUNT = 10;
-    final static int[] spanStarts = new int[MAX_SPAN_COUNT];
-    final static int[] spanEnds = new int[MAX_SPAN_COUNT];
+    private final static int MAX_SPAN_COUNT = 10;
+    private final static int[] spanStarts = new int[MAX_SPAN_COUNT];
+    private final static int[] spanEnds = new int[MAX_SPAN_COUNT];
 
     private static MetricAffectingSpan getMetricAffectingSpan() {
         return new MetricAffectingSpan() {
@@ -231,6 +240,7 @@
         return result;
     }
 
+    @Test
     public void testNoLineBreak() {
         // Width lower than WIDTH
         layout("", NO_BREAK);
@@ -262,6 +272,7 @@
         //      01234567890
     }
 
+    @Test
     public void testOneLineBreak() {
         //      01234567890
         layout("XX XXX XXXX", new int[] {7});
@@ -281,6 +292,7 @@
         layout("CC", new int[] {1});
     }
 
+    @Test
     public void testSpaceAtBreak() {
         //      0123456789012
         layout("XXXX XXXXX X", new int[] {11});
@@ -289,6 +301,7 @@
         layout("C X", new int[] {2});
     }
 
+    @Test
     public void testMultipleSpacesAtBreak() {
         //      0123456789012
         layout("LXX XXXX", new int[] {4});
@@ -298,6 +311,7 @@
         layout("LXX     XXXX", new int[] {8});
     }
 
+    @Test
     public void testZeroWidthCharacters() {
         //      0123456789012345678901234
         layout("X_X_X_X_X_X_X_X_X_X", NO_BREAK);
@@ -312,6 +326,7 @@
      * To be able to use the fake mTextPaint and make this test pass, use mPaint instead of
      * mWorkPaint in MeasuredText#addStyleRun
      */
+    @Test
     public void testWithSpans() {
         if (!SPAN_TESTS_SUPPORTED) return;
 
@@ -332,6 +347,7 @@
     /*
      * Adding a span to the string should not change the layout, since the metrics are unchanged.
      */
+    @Test
     public void testWithOneSpan() {
         if (!SPAN_TESTS_SUPPORTED) return;
 
@@ -356,6 +372,7 @@
         }
     }
 
+    @Test
     public void testWithTwoSpans() {
         if (!SPAN_TESTS_SUPPORTED) return;
 
@@ -392,18 +409,7 @@
         return string.replaceAll(String.valueOf(c), String.valueOf(r));
     }
 
-    public void testReplacementSpan() {
-        // Add ReplacementSpan to the string
-    }
-
-    public void testParagraphs() {
-        // Add \n to the text
-    }
-
-    public void testWithEmoji() {
-        // Surrogate emoji characters get replaced by a bitmap
-    }
-
+    @Test
     public void testWithSurrogate() {
         layout("LX" + SURR_FIRST + SURR_SECOND, NO_BREAK);
         layout("LXXXX" + SURR_FIRST + SURR_SECOND, NO_BREAK);
@@ -418,6 +424,7 @@
         layout("C" + SURR_FIRST + SURR_SECOND, new int[] {1});
     }
 
+    @Test
     public void testNarrowWidth() {
         int[] widths = new int[] { 0, 4, 10 };
         String[] texts = new String[] { "", "X", " ", "XX", " X", "XXX" };
@@ -433,6 +440,7 @@
         }
     }
 
+    @Test
     public void testNarrowWidthZeroWidth() {
         int[] widths = new int[] { 1, 4 };
         for (int width: widths) {
@@ -449,6 +457,7 @@
         }
     }
 
+    @Test
     public void testMaxLines() {
         layoutMaxLines("C", NO_BREAK, 1);
         layoutMaxLines("C C", new int[] {2}, 1);
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
index f66f4c0..0199011 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
@@ -16,8 +16,15 @@
 
 package android.text.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.graphics.Typeface;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.Layout;
 import android.text.Layout.Alignment;
@@ -33,12 +40,18 @@
 import android.text.method.cts.EditorState;
 import android.text.style.StyleSpan;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.text.Normalizer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
-public class StaticLayoutTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class StaticLayoutTest {
     private static final float SPACE_MULTI = 1.0f;
     private static final float SPACE_ADD = 0.0f;
     private static final int DEFAULT_OUTER_WIDTH = 150;
@@ -67,15 +80,10 @@
         // need to have a subclass to insure measurement happens in Java and not C++
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        if (mDefaultPaint == null) {
-            mDefaultPaint = new TextPaint();
-        }
-        if (mDefaultLayout == null) {
-            mDefaultLayout = createDefaultStaticLayout();
-        }
+    @Before
+    public void setup() {
+        mDefaultPaint = new TextPaint();
+        mDefaultLayout = createDefaultStaticLayout();
     }
 
     private StaticLayout createDefaultStaticLayout() {
@@ -103,6 +111,7 @@
     /**
      * Constructor test
      */
+    @Test
     public void testConstructor() {
         new StaticLayout(LAYOUT_TEXT, mDefaultPaint, DEFAULT_OUTER_WIDTH,
                 DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, true);
@@ -112,14 +121,14 @@
 
         new StaticLayout(LAYOUT_TEXT, 0, LAYOUT_TEXT.length(), mDefaultPaint,
                 DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, false, null, 0);
-
-        try {
-            new StaticLayout(null, null, -1, null, 0, 0, true);
-            fail("should throw NullPointerException here");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNull() {
+        new StaticLayout(null, null, -1, null, 0, 0, true);
+    }
+
+    @Test
     public void testBuilder() {
         {
             // Obtain.
@@ -134,8 +143,8 @@
             assertEquals(TextDirectionHeuristics.FIRSTSTRONG_LTR,
                     layout.getTextDirectionHeuristic());
             assertEquals(Alignment.ALIGN_NORMAL, layout.getAlignment());
-            assertEquals(0.0f, layout.getSpacingAdd());
-            assertEquals(1.0f, layout.getSpacingMultiplier());
+            assertEquals(0.0f, layout.getSpacingAdd(), 0.0f);
+            assertEquals(1.0f, layout.getSpacingMultiplier(), 0.0f);
             assertEquals(DEFAULT_OUTER_WIDTH, layout.getEllipsizedWidth());
         }
         {
@@ -179,8 +188,8 @@
                     LAYOUT_TEXT.length(), mDefaultPaint, DEFAULT_OUTER_WIDTH);
             builder.setLineSpacing(1.0f, 2.0f);
             StaticLayout layout = builder.build();
-            assertEquals(1.0f, layout.getSpacingAdd());
-            assertEquals(2.0f, layout.getSpacingMultiplier());
+            assertEquals(1.0f, layout.getSpacingAdd(), 0.0f);
+            assertEquals(2.0f, layout.getSpacingMultiplier(), 0.0f);
         }
         {
             // setEllipsizedWidth and setEllipsize.
@@ -225,6 +234,7 @@
      *  if you ask for a position below the bottom of the text, you get the last line.
      *  Test 4 values containing -1, 0, normal number and > count
      */
+    @Test
     public void testGetLineForVertical() {
         assertEquals(0, mDefaultLayout.getLineForVertical(-1));
         assertEquals(0, mDefaultLayout.getLineForVertical(0));
@@ -235,6 +245,7 @@
     /**
      * Return the number of lines of text in this layout.
      */
+    @Test
     public void testGetLineCount() {
         assertEquals(LINE_COUNT, mDefaultLayout.getLineCount());
     }
@@ -245,21 +256,20 @@
      * A line of text contains top and bottom in height. this method just get the top of a line
      * Test 4 values containing -1, 0, normal number and > count
      */
+    @Test
     public void testGetLineTop() {
         assertTrue(mDefaultLayout.getLineTop(0) >= 0);
         assertTrue(mDefaultLayout.getLineTop(1) > mDefaultLayout.getLineTop(0));
+    }
 
-        try {
-            mDefaultLayout.getLineTop(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineTopBeforeFirst() {
+        mDefaultLayout.getLineTop(-1);
+    }
 
-        try {
-            mDefaultLayout.getLineTop(LARGER_THAN_LINE_COUNT );
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineTopAfterLast() {
+        mDefaultLayout.getLineTop(LARGER_THAN_LINE_COUNT );
     }
 
     /**
@@ -267,41 +277,40 @@
      * This method just like getLineTop, descent means the bottom pixel of the line
      * Test 4 values containing -1, 0, normal number and > count
      */
+    @Test
     public void testGetLineDescent() {
         assertTrue(mDefaultLayout.getLineDescent(0) > 0);
         assertTrue(mDefaultLayout.getLineDescent(1) > 0);
+    }
 
-        try {
-            mDefaultLayout.getLineDescent(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineDescentBeforeFirst() {
+        mDefaultLayout.getLineDescent(-1);
+    }
 
-        try {
-            mDefaultLayout.getLineDescent(LARGER_THAN_LINE_COUNT );
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineDescentAfterLast() {
+        mDefaultLayout.getLineDescent(LARGER_THAN_LINE_COUNT );
     }
 
     /**
      * Returns the primary directionality of the paragraph containing the specified line.
      * By default, each line should be same
      */
+    @Test
     public void testGetParagraphDirection() {
         assertEquals(mDefaultLayout.getParagraphDirection(0),
                 mDefaultLayout.getParagraphDirection(1));
-        try {
-            mDefaultLayout.getParagraphDirection(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    }
 
-        try {
-            mDefaultLayout.getParagraphDirection(LARGER_THAN_LINE_COUNT);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetParagraphDirectionBeforeFirst() {
+        mDefaultLayout.getParagraphDirection(-1);
+    }
+
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetParagraphDirectionAfterLast() {
+        mDefaultLayout.getParagraphDirection(LARGER_THAN_LINE_COUNT );
     }
 
     /**
@@ -310,41 +319,39 @@
      * Test 4 values containing -1, 0, normal number and > count
      * Each line's offset must >= 0
      */
+    @Test
     public void testGetLineStart() {
         assertTrue(mDefaultLayout.getLineStart(0) >= 0);
         assertTrue(mDefaultLayout.getLineStart(1) >= 0);
+    }
 
-        try {
-            mDefaultLayout.getLineStart(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineStartBeforeFirst() {
+        mDefaultLayout.getLineStart(-1);
+    }
 
-        try {
-            mDefaultLayout.getLineStart(LARGER_THAN_LINE_COUNT);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetLineStartAfterLast() {
+        mDefaultLayout.getLineStart(LARGER_THAN_LINE_COUNT );
     }
 
     /*
      * Returns whether the specified line contains one or more tabs.
      */
+    @Test
     public void testGetContainsTab() {
         assertTrue(mDefaultLayout.getLineContainsTab(0));
         assertFalse(mDefaultLayout.getLineContainsTab(1));
+    }
 
-        try {
-            mDefaultLayout.getLineContainsTab(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetContainsTabBeforeFirst() {
+        mDefaultLayout.getLineContainsTab(-1);
+    }
 
-        try {
-            mDefaultLayout.getLineContainsTab(LARGER_THAN_LINE_COUNT );
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetContainsTabAfterLast() {
+        mDefaultLayout.getLineContainsTab(LARGER_THAN_LINE_COUNT );
     }
 
     /**
@@ -354,27 +361,27 @@
      * We can not check the return value, for Directions's field is package private
      * So only check it not null
      */
-    public void testGetLineDirections() {
+    @Test
+    public void testGetLineDirections(){
         assertNotNull(mDefaultLayout.getLineDirections(0));
         assertNotNull(mDefaultLayout.getLineDirections(1));
+    }
 
-        try {
-            mDefaultLayout.getLineDirections(-1);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected = ArrayIndexOutOfBoundsException.class)
+    public void testGetLineDirectionsBeforeFirst() {
+        mDefaultLayout.getLineDirections(-1);
+    }
 
-        try {
-            mDefaultLayout.getLineDirections(LARGER_THAN_LINE_COUNT);
-            fail("should throw ArrayIndexOutOfBoundsException");
-        } catch (ArrayIndexOutOfBoundsException e) {
-        }
+    @Test(expected = ArrayIndexOutOfBoundsException.class)
+    public void testGetLineDirectionsAfterLast() {
+        mDefaultLayout.getLineDirections(LARGER_THAN_LINE_COUNT);
     }
 
     /**
      * Returns the (negative) number of extra pixels of ascent padding
      * in the top line of the Layout.
      */
+    @Test
     public void testGetTopPadding() {
         assertTrue(mDefaultLayout.getTopPadding() < 0);
     }
@@ -382,6 +389,7 @@
     /**
      * Returns the number of extra pixels of descent padding in the bottom line of the Layout.
      */
+    @Test
     public void testGetBottomPadding() {
         assertTrue(mDefaultLayout.getBottomPadding() > 0);
     }
@@ -390,6 +398,7 @@
      * Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
      * So each line must >= 0
      */
+    @Test
     public void testGetEllipsisCount() {
         // Multilines (6 lines) and TruncateAt.START so no ellipsis at all
         mDefaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT,
@@ -457,6 +466,7 @@
      * relative to the start of the line.
      * (So 0 if the beginning of the line is ellipsized, not getLineStart().)
      */
+    @Test
     public void testGetEllipsisStart() {
         mDefaultLayout = createEllipsizeStaticLayout();
         assertTrue(mDefaultLayout.getEllipsisStart(0) >= 0);
@@ -482,6 +492,7 @@
      * ellipsizedWidth if argument is not null
      * outerWidth if argument is null
      */
+    @Test
     public void testGetEllipsizedWidth() {
         int ellipsizedWidth = 60;
         int outerWidth = 100;
@@ -496,6 +507,7 @@
         assertEquals(outerWidth, layout.getEllipsizedWidth());
     }
 
+    @Test
     public void testEllipsis_singleLine() {
         {
             // Single line case and TruncateAt.END so that we have some ellipsis
@@ -577,6 +589,7 @@
      * 2. change the text
      * 3. Check the text won't change to the StaticLayout
     */
+    @Test
     public void testImmutableStaticLayout() {
         Editable editable =  Editable.Factory.getInstance().newEditable("123\t\n555");
         StaticLayout layout = new StaticLayout(editable, mDefaultPaint,
@@ -623,9 +636,9 @@
     };
 
     private List<CharSequence> buildTestCharSequences(String testString, Normalizer.Form[] forms) {
-        List<CharSequence> result = new ArrayList<CharSequence>();
+        List<CharSequence> result = new ArrayList<>();
 
-        List<String> normalizedStrings = new ArrayList<String>();
+        List<String> normalizedStrings = new ArrayList<>();
         for (Normalizer.Form form: forms) {
             normalizedStrings.add(Normalizer.normalize(testString, form));
         }
@@ -664,6 +677,7 @@
                 ", Normalization: " + normalized;
     }
 
+    @Test
     public void testGetOffset_ASCII() {
         String testStrings[] = { "abcde", "ab\ncd", "ab\tcd", "ab\n\nc", "ab\n\tc" };
 
@@ -715,6 +729,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE() {
         String testStrings[] = new String[] {
               // Cyrillic alphabets.
@@ -747,6 +762,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_Normalization() {
         // "A" with acute, circumflex, tilde, diaeresis, ring above.
         String testString = "\u00C1\u00C2\u00C3\u00C4\u00C5";
@@ -805,6 +821,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_SurrogatePairs() {
         // Emoticons for surrogate pairs tests.
         String testString =
@@ -841,6 +858,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_Thai() {
         // Thai Characters. The expected cursorable boundary is
         // | \u0E02 | \u0E2D | \u0E1A | \u0E04\u0E38 | \u0E13 |
@@ -869,6 +887,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_Hebrew() {
         String testString = "\u05DE\u05E1\u05E2\u05D3\u05D4"; // Hebrew Characters
         for (CharSequence seq: buildTestCharSequences(testString, Normalizer.Form.values())) {
@@ -894,6 +913,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_Arabic() {
         // Arabic Characters. The expected cursorable boundary is
         // | \u0623 \u064F | \u0633 \u0652 | \u0631 \u064E | \u0629 \u064C |";
@@ -928,6 +948,7 @@
         }
     }
 
+    @Test
     public void testGetOffset_UNICODE_Bidi() {
         // String having RTL characters and LTR characters
 
@@ -1014,6 +1035,7 @@
         state.mSelectionStart = state.mSelectionEnd = newOffset;
     }
 
+    @Test
     public void testGetOffset_Emoji() {
         EditorState state = new EditorState();
 
@@ -1138,6 +1160,7 @@
         state.assertEquals("| U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8");
     }
 
+    @Test
     public void testGetOffsetForHorizontal_Multilines() {
         // Emoticons for surrogate pairs tests.
         String testString = "\uD83D\uDE00\uD83D\uDE01\uD83D\uDE02\uD83D\uDE03\uD83D\uDE04";
@@ -1159,6 +1182,7 @@
         assertEquals(testString.length(), layout.getOffsetForHorizontal(lineCount - 1, width * 2));
     }
 
+    @Test
     public void testIsRtlCharAt() {
         {
             String testString = "ab(\u0623\u0624)c\u0625";
@@ -1191,21 +1215,23 @@
         }
     }
 
+    @Test
     public void testGetHorizontal() {
         String testString = "abc\u0623\u0624\u0625def";
         StaticLayout layout = new StaticLayout(testString, mDefaultPaint,
                 DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, true);
 
-        assertEquals(layout.getPrimaryHorizontal(0), layout.getSecondaryHorizontal(0));
+        assertEquals(layout.getPrimaryHorizontal(0), layout.getSecondaryHorizontal(0), 0.0f);
         assertTrue(layout.getPrimaryHorizontal(0) < layout.getPrimaryHorizontal(3));
         assertTrue(layout.getPrimaryHorizontal(3) < layout.getSecondaryHorizontal(3));
         assertTrue(layout.getPrimaryHorizontal(4) < layout.getSecondaryHorizontal(3));
-        assertEquals(layout.getPrimaryHorizontal(4), layout.getSecondaryHorizontal(4));
-        assertEquals(layout.getPrimaryHorizontal(3), layout.getSecondaryHorizontal(6));
-        assertEquals(layout.getPrimaryHorizontal(6), layout.getSecondaryHorizontal(3));
-        assertEquals(layout.getPrimaryHorizontal(7), layout.getSecondaryHorizontal(7));
+        assertEquals(layout.getPrimaryHorizontal(4), layout.getSecondaryHorizontal(4), 0.0f);
+        assertEquals(layout.getPrimaryHorizontal(3), layout.getSecondaryHorizontal(6), 0.0f);
+        assertEquals(layout.getPrimaryHorizontal(6), layout.getSecondaryHorizontal(3), 0.0f);
+        assertEquals(layout.getPrimaryHorizontal(7), layout.getSecondaryHorizontal(7), 0.0f);
     }
 
+    @Test
     public void testVeryLargeString() {
         final int MAX_COUNT = 1 << 21;
         final int WORD_SIZE = 32;
@@ -1220,7 +1246,8 @@
         assertNotNull(layout);
     }
 
-    public void testDoesntCrashWhenWordStyleOverlap() {
+    @Test
+    public void testNoCrashWhenWordStyleOverlap() {
        // test case where word boundary overlaps multiple style spans
        SpannableStringBuilder text = new SpannableStringBuilder("word boundaries, overlap style");
        // span covers "boundaries"
diff --git a/tests/tests/text/src/android/text/cts/TextUtilsTest.java b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
index 77aa845..e1d6238 100644
--- a/tests/tests/text/src/android/text/cts/TextUtilsTest.java
+++ b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
@@ -19,8 +19,16 @@
 import static android.view.View.LAYOUT_DIRECTION_LTR;
 import static android.view.View.LAYOUT_DIRECTION_RTL;
 
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import android.content.Context;
 import android.content.res.ColorStateList;
@@ -31,7 +39,9 @@
 import android.os.LocaleList;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.GetChars;
 import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
@@ -46,6 +56,10 @@
 import android.text.style.URLSpan;
 import android.util.StringBuilderPrinter;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -55,14 +69,17 @@
 /**
  * Test {@link TextUtils}.
  */
-public class TextUtilsTest extends AndroidTestCase {
-    private static String mEllipsis;
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TextUtilsTest  {
+    private Context mContext;
+    private String mEllipsis;
     private int mStart;
     private int mEnd;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
         mEllipsis = getEllipsis();
         resetRange();
     }
@@ -76,7 +93,7 @@
      * Get the ellipsis from system.
      * @return the string of ellipsis.
      */
-    private String getEllipsis() {
+    private static String getEllipsis() {
         String text = "xxxxx";
         TextPaint p = new TextPaint();
         float width = p.measureText(text.substring(1));
@@ -87,7 +104,7 @@
     /**
      * @return the number of times the code unit appears in the CharSequence.
      */
-    private int countChars(CharSequence s, char c) {
+    private static int countChars(CharSequence s, char c) {
         int count = 0;
         for (int i = 0; i < s.length(); i++) {
             if (s.charAt(i) == c) {
@@ -97,8 +114,8 @@
         return count;
     }
 
+    @Test
     public void testListEllipsize() {
-        final Context context = getContext();
         final TextPaint paint = new TextPaint();
         final int moreId = R.plurals.list_ellipsize_test;  // "one more" for 1, "%d more" for other
 
@@ -107,11 +124,11 @@
         final String fullString = TextUtils.join(separator, fullList);
         final float fullWidth = paint.measureText(fullString);
         assertEquals("",
-            TextUtils.listEllipsize(context, null, separator, paint, fullWidth, moreId));
+            TextUtils.listEllipsize(mContext, null, separator, paint, fullWidth, moreId));
 
-        final List<CharSequence> emptyList = new ArrayList<CharSequence>();
+        final List<CharSequence> emptyList = new ArrayList<>();
         assertEquals("",
-            TextUtils.listEllipsize(context, emptyList, separator, paint, fullWidth, moreId));
+            TextUtils.listEllipsize(mContext, emptyList, separator, paint, fullWidth, moreId));
 
         // Null context should cause ellipsis to be used at the end.
         final String ellipsizedWithNull = TextUtils.listEllipsize(
@@ -120,20 +137,20 @@
 
         // Test that the empty string gets returned if there's no space.
         assertEquals("",
-                TextUtils.listEllipsize(context, fullList, separator, paint, 1.0f, moreId));
+                TextUtils.listEllipsize(mContext, fullList, separator, paint, 1.0f, moreId));
 
         // Test that the full string itself can get returned if there's enough space.
         assertEquals(fullString,
-                TextUtils.listEllipsize(context, fullList, separator, paint, fullWidth, moreId)
+                TextUtils.listEllipsize(mContext, fullList, separator, paint, fullWidth, moreId)
                         .toString());
         assertEquals(fullString,
-                TextUtils.listEllipsize(context, fullList, separator, paint, fullWidth * 2,
+                TextUtils.listEllipsize(mContext, fullList, separator, paint, fullWidth * 2,
                         moreId).toString());
 
         final float epsilon = fullWidth / 20;
         for (float width = epsilon; width < fullWidth - epsilon / 2; width += epsilon) {
             final String ellipsized = TextUtils.listEllipsize(
-                    context, fullList, separator, paint, width, moreId).toString();
+                    mContext, fullList, separator, paint, width, moreId).toString();
             // Since we don't have the full space, test that we are not getting the full string.
             assertFalse(fullString.equals(ellipsized));
 
@@ -154,9 +171,9 @@
         }
 }
 
+    @Test
     public void testListEllipsize_rtl() {
-        final Context context = getContext();
-        final Resources res = context.getResources();
+        final Resources res = mContext.getResources();
         final Configuration newConfig = new Configuration(res.getConfiguration());
 
         // save the locales and set them to just Arabic
@@ -178,7 +195,7 @@
             final float enoughWidth = paint.measureText(expectedString);
 
             assertEquals(expectedString,
-                    TextUtils.listEllipsize(context, fullList, separator, paint, enoughWidth,
+                    TextUtils.listEllipsize(mContext, fullList, separator, paint, enoughWidth,
                                             moreId).toString());
         } finally {
             // Restore the original locales
@@ -187,6 +204,7 @@
         }
     }
 
+    @Test
     public void testCommaEllipsize() {
         TextPaint p = new TextPaint();
         String text = "long, string, to, truncate";
@@ -239,6 +257,7 @@
         }
     }
 
+    @Test
     public void testConcat() {
         // issue 1695243
         // the javadoc for concat() doesn't describe the expected result when parameter is empty.
@@ -275,15 +294,14 @@
         // issue 1695243, the javadoc for concat() doesn't describe
         // the expected result when parameters are null.
         assertEquals(null, TextUtils.concat((CharSequence) null));
-
-        try {
-            TextUtils.concat((CharSequence[]) null);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testConcatNullArray() {
+        TextUtils.concat((CharSequence[]) null);
+    }
+
+    @Test
     public void testCopySpansFrom() {
         Object[] spans;
         String text = "content";
@@ -426,6 +444,7 @@
         }
     }
 
+    @Test
     public void testEllipsize() {
         TextPaint p = new TextPaint();
 
@@ -478,6 +497,7 @@
         }
     }
 
+    @Test
     public void testEllipsizeCallback() {
         TextPaint p = new TextPaint();
 
@@ -613,7 +633,7 @@
      * @param len - int length of string.
      * @return a blank string which is filled up by '\uFEFF'.
      */
-    private String getBlankString(boolean isNeedStart, int len) {
+    private static String getBlankString(boolean isNeedStart, int len) {
         StringBuilder buf = new StringBuilder();
 
         int i = 0;
@@ -628,6 +648,7 @@
         return buf.toString();
     }
 
+    @Test
     public void testEquals() {
         // compare with itself.
         // String is a subclass of CharSequence and overrides equals().
@@ -667,6 +688,7 @@
         assertFalse(TextUtils.equals(null, string));
     }
 
+    @Test
     public void testExpandTemplate() {
         // ^1 at the start of template string.
         assertEquals("value1 template to be expanded",
@@ -717,66 +739,55 @@
         } catch (IllegalArgumentException e) {
             // expect
         }
+    }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testExpandTemplateCaret0WithValue() {
         // template string is ^0
-        try {
-            TextUtils.expandTemplate("template ^0 to be expanded", "value1");
-        } catch (IllegalArgumentException e) {
-            // issue 1695243, doesn't discuss the case that ^0 in template string.
-        }
+        TextUtils.expandTemplate("template ^0 to be expanded", "value1");
+    }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testExpandTemplateCaret0NoValues() {
         // template string is ^0
-        try {
-            TextUtils.expandTemplate("template ^0 to be expanded");
-        } catch (IllegalArgumentException e) {
-            // issue 1695243, doesn't discuss the case that ^0 in template string.
-        }
+        TextUtils.expandTemplate("template ^0 to be expanded");
+    }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testExpandTemplateNotEnoughValues() {
         // the template requests 2 values but only 1 is provided
-        try {
-            TextUtils.expandTemplate("template ^2 to be expanded", "value1");
-            fail("Should throw IllegalArgumentException!");
-        } catch (IllegalArgumentException e) {
-            // expect
-        }
+        TextUtils.expandTemplate("template ^2 to be expanded", "value1");
+    }
 
+    @Test(expected=NullPointerException.class)
+    public void testExpandTemplateNullValues() {
         // values is null
-        try {
-            TextUtils.expandTemplate("template ^2 to be expanded", (CharSequence[]) null);
-        } catch (NullPointerException e) {
-            // expected
-        }
+        TextUtils.expandTemplate("template ^2 to be expanded", (CharSequence[]) null);
+    }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testExpandTemplateNotEnoughValuesAndFirstIsNull() {
         // the template requests 2 values but only one null value is provided
-        try {
-            TextUtils.expandTemplate("template ^2 to be expanded", (CharSequence) null);
-            fail("Should throw IllegalArgumentException!");
-        } catch (IllegalArgumentException e) {
-            // expect
-        }
+        TextUtils.expandTemplate("template ^2 to be expanded", (CharSequence) null);
+    }
 
+    @Test(expected=NullPointerException.class)
+    public void testExpandTemplateAllValuesAreNull() {
         // the template requests 2 values and 2 values is provided, but all values are null.
-        try {
-            TextUtils.expandTemplate("template ^2 to be expanded",
-                    (CharSequence) null, (CharSequence) null);
-        } catch (NullPointerException e) {
-            // expected
-        }
+        TextUtils.expandTemplate("template ^2 to be expanded",
+                (CharSequence) null, (CharSequence) null);
+    }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testExpandTemplateNoValues() {
         // the template requests 2 values but no value is provided.
-        try {
-            TextUtils.expandTemplate("template ^2 to be expanded");
-            fail("Should throw IllegalArgumentException!");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
+        TextUtils.expandTemplate("template ^2 to be expanded");
+    }
 
+    @Test(expected=NullPointerException.class)
+    public void testExpandTemplateNullTemplate() {
         // template is null
-        try {
-            TextUtils.expandTemplate(null, "value1");
-        } catch (NullPointerException e) {
-            // expected
-        }
+        TextUtils.expandTemplate(null, "value1");
     }
 
     /**
@@ -785,7 +796,7 @@
      * @return The char sequence array with the specified length.
      * The value of each item is "value[index+1]"
      */
-    private CharSequence[] createCharSequenceArray(int len) {
+    private static CharSequence[] createCharSequenceArray(int len) {
         CharSequence array[] = new CharSequence[len];
 
         for (int i = 0; i < len; i++) {
@@ -795,6 +806,7 @@
         return array;
     }
 
+    @Test
     public void testGetChars() {
         char[] destOriginal = "destination".toCharArray();
         char[] destResult = destOriginal.clone();
@@ -1014,6 +1026,7 @@
         }
     }
 
+    @Test
     public void testGetOffsetAfter() {
         // the first '\uD800' is index 9, the second 'uD800' is index 16
         // the '\uDBFF' is index 26
@@ -1061,6 +1074,7 @@
         }
     }
 
+    @Test
     public void testGetOffsetBefore() {
         // the first '\uDC00' is index 10, the second 'uDC00' is index 17
         // the '\uDFFF' is index 27
@@ -1108,6 +1122,7 @@
         }
     }
 
+    @Test
     public void testGetReverse() {
         String source = "string to be reversed";
         assertEquals("gnirts", TextUtils.getReverse(source, 0, "string".length()).toString());
@@ -1162,6 +1177,7 @@
         }
     }
 
+    @Test
     public void testGetTrimmedLength() {
         assertEquals("normalstring".length(), TextUtils.getTrimmedLength("normalstring"));
         assertEquals("normal string".length(), TextUtils.getTrimmedLength("normal string"));
@@ -1169,33 +1185,31 @@
         assertEquals("blank after".length(), TextUtils.getTrimmedLength("blank after   \n    "));
         assertEquals("blank both".length(), TextUtils.getTrimmedLength(" \t   blank both  \n "));
 
-        char[] allTrimmedChars = new char[] {
+        char[] allTrimmedChars = new char[]{
                 '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
                 '\u0008', '\u0009', '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015',
                 '\u0016', '\u0017', '\u0018', '\u0019', '\u0020'
         };
         assertEquals(0, TextUtils.getTrimmedLength(String.valueOf(allTrimmedChars)));
-
-        try {
-            TextUtils.getTrimmedLength(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testGetTrimmedLengthNull() {
+        TextUtils.getTrimmedLength(null);
+    }
+
+    @Test
     public void testHtmlEncode() {
         assertEquals("&lt;_html_&gt;\\ &amp;&quot;&#39;string&#39;&quot;",
                 TextUtils.htmlEncode("<_html_>\\ &\"'string'\""));
-
-         try {
-             TextUtils.htmlEncode(null);
-             fail("Should throw NullPointerException!");
-         } catch (NullPointerException e) {
-             // expected
-         }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testHtmlEncodeNull() {
+         TextUtils.htmlEncode(null);
+    }
+
+    @Test
     public void testIndexOf1() {
         String searchString = "string to be searched";
         final int INDEX_OF_FIRST_R = 2;     // first occurrence of 'r'
@@ -1222,6 +1236,7 @@
         assertEquals(INDEX_OF_FIRST_R, TextUtils.indexOf(mockCharSequence, 'r'));
     }
 
+    @Test
     public void testIndexOf2() {
         String searchString = "string to be searched";
         final int INDEX_OF_FIRST_R = 2;
@@ -1256,6 +1271,7 @@
                 INDEX_OF_FIRST_R + 1));
     }
 
+    @Test
     public void testIndexOf3() {
         String searchString = "string to be searched";
         final int INDEX_OF_FIRST_R = 2;
@@ -1301,6 +1317,7 @@
                 INDEX_OF_FIRST_R + 1, searchString.length()));
     }
 
+    @Test
     public void testIndexOf4() {
         String searchString = "string to be searched by string";
         final int SEARCH_INDEX = 13;
@@ -1324,6 +1341,7 @@
         assertEquals(SEARCH_INDEX, TextUtils.indexOf(mockCharSequence, "search"));
     }
 
+    @Test
     public void testIndexOf5() {
         String searchString = "string to be searched by string";
         final int INDEX_OF_FIRST_STRING = 0;
@@ -1368,6 +1386,7 @@
                 INDEX_OF_FIRST_STRING + 1));
     }
 
+    @Test
     public void testIndexOf6() {
         String searchString = "string to be searched by string";
         final int INDEX_OF_FIRST_STRING = 0;
@@ -1419,6 +1438,7 @@
                 INDEX_OF_FIRST_STRING + 1, searchString.length()));
     }
 
+    @Test
     public void testIsDigitsOnly() {
         assertTrue(TextUtils.isDigitsOnly(""));
         assertFalse(TextUtils.isDigitsOnly("no digit"));
@@ -1433,15 +1453,14 @@
 
         assertFalse(TextUtils.isDigitsOnly("\uD801")); // lonely lead surrogate
         assertFalse(TextUtils.isDigitsOnly("\uDCA0")); // lonely trailing surrogate
-
-        try {
-            TextUtils.isDigitsOnly(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed result if the CharSequence is null.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testIsDigitsOnlyNull() {
+        TextUtils.isDigitsOnly(null);
+    }
+
+    @Test
     public void testIsEmpty() {
         assertFalse(TextUtils.isEmpty("not empty"));
         assertFalse(TextUtils.isEmpty("    "));
@@ -1449,6 +1468,7 @@
         assertTrue(TextUtils.isEmpty(null));
     }
 
+    @Test
     public void testIsGraphicChar() {
         assertTrue(TextUtils.isGraphic('a'));
         assertTrue(TextUtils.isGraphic('\uBA00'));
@@ -1470,15 +1490,14 @@
 
         // SPACE_SEPARATOR
         assertFalse(TextUtils.isGraphic('\u0020'));
-
-        try {
-            assertFalse(TextUtils.isGraphic((Character) null));
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testIsGraphicCharNull() {
+        assertFalse(TextUtils.isGraphic((Character) null));
+    }
+
+    @Test
     public void testIsGraphicCharSequence() {
         assertTrue(TextUtils.isGraphic("printable characters"));
 
@@ -1490,18 +1509,16 @@
         assertFalse(TextUtils.isGraphic("\uDB40\uDC01")); // U+E0000 (unassigned)
         assertFalse(TextUtils.isGraphic("\uDB3D")); // unpaired high surrogate
         assertFalse(TextUtils.isGraphic("\uDC0C")); // unpaired low surrogate
-
-        try {
-            TextUtils.isGraphic(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
-    @SuppressWarnings("unchecked")
-    public void testJoin1() {
-        ArrayList<CharSequence> charTokens = new ArrayList<CharSequence>();
+    @Test(expected=NullPointerException.class)
+    public void testIsGraphicCharSequenceNull() {
+        TextUtils.isGraphic(null);
+    }
+
+    @Test
+    public void testJoinIterable() {
+        ArrayList<CharSequence> charTokens = new ArrayList<>();
         charTokens.add("string1");
         charTokens.add("string2");
         charTokens.add("string3");
@@ -1511,12 +1528,6 @@
 
         // issue 1695243, not clear what is supposed result if the delimiter or tokens are null.
         assertEquals("string1nullstring2nullstring3", TextUtils.join(null, charTokens));
-        try {
-            TextUtils.join("|", (Iterable) null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
 
         ArrayList<SpannableString> spannableStringTokens = new ArrayList<SpannableString>();
         spannableStringTokens.add(new SpannableString("span 1"));
@@ -1525,7 +1536,13 @@
         assertEquals("span 1;span 2;span 3", TextUtils.join(";", spannableStringTokens));
     }
 
-    public void testJoin2() {
+    @Test(expected=NullPointerException.class)
+    public void testJoinIterableNull() {
+        TextUtils.join("|", (Iterable) null);
+    }
+
+    @Test
+    public void testJoinArray() {
         CharSequence[] charTokens = new CharSequence[] { "string1", "string2", "string3" };
         assertEquals("string1|string2|string3", TextUtils.join("|", charTokens));
         assertEquals("string1; string2; string3", TextUtils.join("; ", charTokens));
@@ -1533,12 +1550,6 @@
 
         // issue 1695243, not clear what is supposed result if the delimiter or tokens are null.
         assertEquals("string1nullstring2nullstring3", TextUtils.join(null, charTokens));
-        try {
-            TextUtils.join("|", (Object[]) null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
 
         SpannableString[] spannableStringTokens = new SpannableString[] {
                 new SpannableString("span 1"),
@@ -1547,6 +1558,12 @@
         assertEquals("span 1;span 2;span 3", TextUtils.join(";", spannableStringTokens));
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testJoinArrayNull() {
+        TextUtils.join("|", (Object[]) null);
+    }
+
+    @Test
     public void testLastIndexOf1() {
         String searchString = "string to be searched";
         final int INDEX_OF_LAST_R = 16;
@@ -1572,6 +1589,7 @@
         assertEquals(INDEX_OF_LAST_R, TextUtils.lastIndexOf(mockCharSequence, 'r'));
     }
 
+    @Test
     public void testLastIndexOf2() {
         String searchString = "string to be searched";
         final int INDEX_OF_FIRST_R = 2;
@@ -1606,6 +1624,7 @@
                 TextUtils.lastIndexOf(mockCharSequence, 'r', INDEX_OF_FIRST_R));
     }
 
+    @Test
     public void testLastIndexOf3() {
         String searchString = "string to be searched";
         final int INDEX_OF_FIRST_R = 2;
@@ -1646,6 +1665,7 @@
                 INDEX_OF_SECOND_R - 1));
     }
 
+    @Test
     public void testRegionMatches() {
         assertFalse(TextUtils.regionMatches("one", 0, "two", 0, "one".length()));
         assertTrue(TextUtils.regionMatches("one", 0, "one", 0, "one".length()));
@@ -1716,6 +1736,7 @@
         }
     }
 
+    @Test
     public void testReplace() {
         String template = "this is a string to be as the template for replacement";
 
@@ -1766,6 +1787,7 @@
         }
     }
 
+    @Test
     public void testSplitPattern() {
         String testString = "abccbadecdebz";
         assertEquals(calculateCharsCount(testString, "c") + 1,
@@ -1784,25 +1806,22 @@
         // issue 1695243, not clear what is supposed result if the pattern string is empty.
         assertEquals(testString.length() + 2,
                 TextUtils.split(testString, Pattern.compile("")).length);
+    }
 
-        try {
-            TextUtils.split(null, Pattern.compile("a"));
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-        try {
+    @Test(expected=NullPointerException.class)
+    public void testSplitPatternNullText() {
+        TextUtils.split(null, Pattern.compile("a"));
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testSplitPatternNullPattern() {
             TextUtils.split("abccbadecdebz", (Pattern) null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
     }
 
     /*
      * return the appearance count of searched chars in text.
      */
-    private int calculateCharsCount(CharSequence text, CharSequence searches) {
+    private static int calculateCharsCount(CharSequence text, CharSequence searches) {
         int count = 0;
         int start = TextUtils.indexOf(text, searches, 0);
 
@@ -1813,6 +1832,7 @@
         return count;
     }
 
+    @Test
     public void testSplitString() {
         String testString = "abccbadecdebz";
         assertEquals(calculateCharsCount(testString, "c") + 1,
@@ -1827,21 +1847,19 @@
         // issue 1695243, not clear what is supposed result if the pattern string is empty.
         assertEquals(testString.length() + 2,
                 TextUtils.split("abccbadecdebz", "").length);
-
-        try {
-            TextUtils.split(null, "a");
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-        try {
-            TextUtils.split("abccbadecdebz", (String) null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testSplitStringNullText() {
+        TextUtils.split(null, "a");
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testSplitStringNullPattern() {
+        TextUtils.split("abccbadecdebz", (String) null);
+    }
+
+    @Test
     public void testStringOrSpannedString() {
         assertNull(TextUtils.stringOrSpannedString(null));
 
@@ -1861,6 +1879,7 @@
                 TextUtils.stringOrSpannedString(stringBuffer).getClass());
     }
 
+    @Test
     public void testSubString() {
         String string = "String";
         assertSame(string, TextUtils.substring(string, 0, string.length()));
@@ -1918,6 +1937,7 @@
         assertTrue(mockGetChars.hasCalledGetChars());
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcelable.Creator<CharSequence> creator = TextUtils.CHAR_SEQUENCE_CREATOR;
         String string = "String";
@@ -2005,6 +2025,7 @@
         }
     }
 
+    @Test
     public void testGetCapsMode() {
         final int CAP_MODE_ALL = TextUtils.CAP_MODE_CHARACTERS
                 | TextUtils.CAP_MODE_WORDS | TextUtils.CAP_MODE_SENTENCES;
@@ -2089,6 +2110,7 @@
                 TextUtils.getCapsMode(testString, offset, CAP_MODE_ALL));
     }
 
+    @Test
     public void testGetCapsModeException() {
         String testString = "Start. Sentence word!No space before\n\t" +
                 "Paragraph? (\"\'skip begin\'\"). skip end";
@@ -2115,6 +2137,7 @@
         }
     }
 
+    @Test
     public void testDumpSpans() {
         StringBuilder builder = new StringBuilder();
         StringBuilderPrinter printer = new StringBuilderPrinter(builder);
@@ -2134,6 +2157,7 @@
         assertTrue(builder.length() > 0);
     }
 
+    @Test
     public void testGetLayoutDirectionFromLocale() {
         assertEquals(LAYOUT_DIRECTION_LTR,
                 TextUtils.getLayoutDirectionFromLocale(null));
diff --git a/tests/tests/text/src/android/text/cts/TextUtils_SimpleStringSplitterTest.java b/tests/tests/text/src/android/text/cts/TextUtils_SimpleStringSplitterTest.java
index fb58c3c..7993f58 100644
--- a/tests/tests/text/src/android/text/cts/TextUtils_SimpleStringSplitterTest.java
+++ b/tests/tests/text/src/android/text/cts/TextUtils_SimpleStringSplitterTest.java
@@ -16,15 +16,28 @@
 
 package android.text.cts;
 
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextUtils.SimpleStringSplitter;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Iterator;
 
 /**
  * Test {@link SimpleStringSplitter}.
  */
-public class TextUtils_SimpleStringSplitterTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TextUtils_SimpleStringSplitterTest {
+    @Test
     public void testConstructor() {
         new SimpleStringSplitter('|');
 
@@ -33,6 +46,7 @@
         new SimpleStringSplitter(Character.MIN_VALUE);
     }
 
+    @Test
     public void testHasNext() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter('|');
         assertFalse(simpleStringSplitter.hasNext());
@@ -50,6 +64,7 @@
         assertFalse(simpleStringSplitter.hasNext());
     }
 
+    @Test
     public void testIterator() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter('|');
 
@@ -67,6 +82,7 @@
         assertFalse(iterator.hasNext());
     }
 
+    @Test
     public void testNext1() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter(',');
 
@@ -80,6 +96,7 @@
         }
     }
 
+    @Test
     public void testNext2() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter(',');
 
@@ -96,6 +113,7 @@
         assertEquals("", simpleStringSplitter.next());
     }
 
+    @Test
     public void testRemove() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter(',');
 
@@ -106,6 +124,7 @@
         }
     }
 
+    @Test
     public void testSetString() {
         SimpleStringSplitter simpleStringSplitter = new SimpleStringSplitter(',');
 
diff --git a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
index 50039ef..525bf50 100644
--- a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
@@ -16,15 +16,28 @@
 
 package android.text.format.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
+import android.app.UiAutomation;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.cts.util.SystemUtil;
 import android.os.ParcelFileDescriptor;
 import android.provider.Settings;
-import android.test.InstrumentationTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.format.DateFormat;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -38,13 +51,12 @@
 import java.util.Scanner;
 import java.util.TimeZone;
 
-public class DateFormatTest extends InstrumentationTestCase {
+@LargeTest
+@RunWith(AndroidJUnit4.class)
+public class DateFormatTest {
     private static final String TIME_FORMAT_12 = "12";
     private static final String TIME_FORMAT_24 = "24";
 
-    private Context mContext;
-    private ContentResolver mContentResolver;
-
     // Date: 2008-12-18 05:30
     private static final int YEAR_FROM_1900 = 108;
     private static final int YEAR = 2008;
@@ -53,36 +65,48 @@
     private static final int HOUR = 5;
     private static final int MINUTE = 30;
 
+    private Context mContext;
+
     private boolean mIs24HourFormat;
     private Locale mDefaultLocale;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        enableAppOps();
-        mContext = getInstrumentation().getContext();
-        mContentResolver = mContext.getContentResolver();
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
         mIs24HourFormat = DateFormat.is24HourFormat(mContext);
         mDefaultLocale = Locale.getDefault();
+
+        enableAppOps();
+    }
+
+    @After
+    public void teardown() throws Exception {
+        if (!mIs24HourFormat) {
+            setTimeFormat(TIME_FORMAT_12);
+        }
+        if ((mDefaultLocale != null) && !Locale.getDefault().equals(mDefaultLocale)) {
+            Locale.setDefault(mDefaultLocale);
+        }
     }
 
     private void enableAppOps() {
+        UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
+
         StringBuilder cmd = new StringBuilder();
         cmd.append("appops set ");
-        cmd.append(getInstrumentation().getContext().getPackageName());
+        cmd.append(mContext.getPackageName());
         cmd.append(" android:write_settings allow");
-        getInstrumentation().getUiAutomation().executeShellCommand(cmd.toString());
+        uiAutomation.executeShellCommand(cmd.toString());
 
         StringBuilder query = new StringBuilder();
         query.append("appops get ");
-        query.append(getInstrumentation().getContext().getPackageName());
+        query.append(mContext.getPackageName());
         query.append(" android:write_settings");
         String queryStr = query.toString();
 
         String result = "No operations.";
         while (result.contains("No operations")) {
-            ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation().executeShellCommand(
-                                        queryStr);
+            ParcelFileDescriptor pfd = uiAutomation.executeShellCommand(queryStr);
             InputStream inputStream = new FileInputStream(pfd.getFileDescriptor());
             result = convertStreamToString(inputStream);
         }
@@ -94,18 +118,7 @@
         }
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        if (!mIs24HourFormat) {
-            setTimeFormat(TIME_FORMAT_12);
-        }
-        if (!Locale.getDefault().equals(mDefaultLocale)) {
-            Locale.setDefault(mDefaultLocale);
-        }
-
-        super.tearDown();
-    }
-
+    @Test
     public void test_is24HourFormat() throws Exception {
         setTimeFormat(TIME_FORMAT_24);
         assertTrue(DateFormat.is24HourFormat(mContext));
@@ -113,6 +126,7 @@
         assertFalse(DateFormat.is24HourFormat(mContext));
     }
 
+    @Test
     public void test_format_M() {
         Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
         assertEquals("D", DateFormat.format("MMMMM", c));
@@ -122,6 +136,7 @@
         assertEquals("12", DateFormat.format("M", c));
     }
 
+    @Test
     public void test_format_L() {
         // TODO: we can't test other locales with this API so we can't test 'L' properly!
         Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
@@ -132,6 +147,7 @@
         assertEquals("12", DateFormat.format("L", c));
     }
 
+    @Test
     public void test_format_E() {
         Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
         assertEquals("T", DateFormat.format("EEEEE", c));
@@ -141,6 +157,7 @@
         assertEquals("Thu", DateFormat.format("E", c));
     }
 
+    @Test
     public void test_format_c() {
         // TODO: we can't test other locales with this API, so we can't test 'c' properly!
         Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
@@ -152,6 +169,7 @@
     }
 
     @SuppressWarnings("deprecation")
+    @Test
     public void testFormatMethods() throws ParseException {
         if (!mDefaultLocale.equals(Locale.US)) {
             Locale.setDefault(Locale.US);
@@ -192,6 +210,7 @@
         assertEquals(expectedString, actual.toString());
     }
 
+    @Test
     public void test2038() {
         Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+00:00"));
 
@@ -235,6 +254,7 @@
         assertEquals(expected, sdf.format(c.getTime()));
     }
 
+    @Test
     public void test_bug_8359981() {
         checkFormat("24", "k", 00);
         checkFormat( "0", "K", 00);
@@ -262,6 +282,7 @@
         checkFormat( "0", "H", 24);
     }
 
+    @Test
     public void test_bug_82144() {
         for (Locale locale : Locale.getAvailableLocales()) {
             Locale.setDefault(locale);
@@ -291,7 +312,7 @@
     }
 
     private void setTimeFormat(String timeFormat) throws IOException {
-        SystemUtil.runShellCommand(getInstrumentation(), "settings put system "
-                + Settings.System.TIME_12_24 + " " + timeFormat);
+        SystemUtil.runShellCommand(InstrumentationRegistry.getInstrumentation(),
+                "settings put system " + Settings.System.TIME_12_24 + " " + timeFormat);
     }
 }
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index ad601e5..6e21976 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -16,28 +16,40 @@
 
 package android.text.format.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import android.content.Context;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.format.DateUtils;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 
-public class DateUtilsTest extends AndroidTestCase {
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class DateUtilsTest {
     private long mBaseTime;
     private Context mContext;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mContext = getContext();
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
         TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
         mBaseTime = System.currentTimeMillis();
     }
 
+    @Test
     public void testGetDayOfWeekString() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -58,6 +70,7 @@
                 DateUtils.getDayOfWeekString(Calendar.SUNDAY, 60));
     }
 
+    @Test
     public void testGetMonthString() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -74,6 +87,7 @@
         assertEquals("Jan", DateUtils.getMonthString(Calendar.JANUARY, 60));
     }
 
+    @Test
     public void testGetAMPMString() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -85,6 +99,7 @@
     // This is to test the mapping between DateUtils' public API and
     // libcore/icu4c's implementation. More tests, in different locales, are
     // in libcore's CTS tests.
+    @Test
     public void test_getRelativeTimeSpanString() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -114,12 +129,14 @@
     // test the mapping between DateUtils's public API and libcore/icu4c's
     // implementation. More tests, in different locales, are in libcore's
     // CTS tests.
+    @Test
     public void test_getRelativeDateTimeString() {
         final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
         assertNotNull(DateUtils.getRelativeDateTimeString(mContext, mBaseTime - DAY_DURATION,
                 DateUtils.MINUTE_IN_MILLIS, DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_NUMERIC_DATE));
     }
 
+    @Test
     public void test_formatElapsedTime() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -127,19 +144,20 @@
 
         long MINUTES = 60;
         long HOURS = 60 * MINUTES;
-        test_formatElapsedTime("02:01", 2 * MINUTES + 1);
-        test_formatElapsedTime("3:02:01", 3 * HOURS + 2 * MINUTES + 1);
+        verifyFormatElapsedTime("02:01", 2 * MINUTES + 1);
+        verifyFormatElapsedTime("3:02:01", 3 * HOURS + 2 * MINUTES + 1);
         // http://code.google.com/p/android/issues/detail?id=41401
-        test_formatElapsedTime("123:02:01", 123 * HOURS + 2 * MINUTES + 1);
+        verifyFormatElapsedTime("123:02:01", 123 * HOURS + 2 * MINUTES + 1);
     }
 
-    private void test_formatElapsedTime(String expected, long elapsedTime) {
+    private void verifyFormatElapsedTime(String expected, long elapsedTime) {
         assertEquals(expected, DateUtils.formatElapsedTime(elapsedTime));
         StringBuilder sb = new StringBuilder();
         assertEquals(expected, DateUtils.formatElapsedTime(sb, elapsedTime));
         assertEquals(expected, sb.toString());
     }
 
+    @Test
     public void testFormatSameDayTime() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -150,7 +168,6 @@
 
         int currentYear = Calendar.getInstance().get(Calendar.YEAR);
         Date dateWithCurrentYear = new Date(currentYear - 1900, 0, 19, 3, 30, 15);
-        long timeWithCurrentYear = dateWithCurrentYear.getTime();
 
         final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
         assertEquals("Saturday, January 24, 2009", DateUtils.formatSameDayTime(
@@ -180,6 +197,7 @@
 
     // This is just to exercise the wrapper that calls the libcore/icu4c implementation.
     // Full testing, in multiple locales, is in libcore's CTS tests.
+    @Test
     public void testFormatDateRange() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
@@ -192,12 +210,14 @@
                 fixedTime + HOUR_DURATION, DateUtils.FORMAT_SHOW_WEEKDAY));
     }
 
+    @Test
     public void testIsToday() {
         final long ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
         assertTrue(DateUtils.isToday(mBaseTime));
         assertFalse(DateUtils.isToday(mBaseTime - ONE_DAY_IN_MS));
     }
 
+    @Test
     public void test_bug_7548161() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
diff --git a/tests/tests/text/src/android/text/format/cts/FormatterTest.java b/tests/tests/text/src/android/text/format/cts/FormatterTest.java
index 85221d6..fa11023 100644
--- a/tests/tests/text/src/android/text/format/cts/FormatterTest.java
+++ b/tests/tests/text/src/android/text/format/cts/FormatterTest.java
@@ -16,50 +16,59 @@
 
 package android.text.format.cts;
 
+import static org.junit.Assert.assertEquals;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.format.Formatter;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.math.BigDecimal;
 import java.math.MathContext;
 
-public class FormatterTest extends AndroidTestCase {
-
-    @SmallTest
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class FormatterTest {
+    @Test
     public void testFormatFileSize() {
         // test null Context
         assertEquals("", Formatter.formatFileSize(null, 0));
 
         MathContext mc = MathContext.DECIMAL64;
         BigDecimal bd = new BigDecimal((long) 1000, mc);
+        Context context = InstrumentationRegistry.getTargetContext();
 
         // test different long values with various length
-        assertEquals("0 B", Formatter.formatFileSize(mContext, 0));
-        assertEquals("1 B", Formatter.formatFileSize(mContext, 1));
-        assertEquals("9 B", Formatter.formatFileSize(mContext, 9));
-        assertEquals("10 B", Formatter.formatFileSize(mContext, 10));
-        assertEquals("99 B", Formatter.formatFileSize(mContext, 99));
-        assertEquals("100 B", Formatter.formatFileSize(mContext, 100));
-        assertEquals("900 B", Formatter.formatFileSize(mContext, 900));
-        assertEquals("0.90 kB", Formatter.formatFileSize(mContext, 901));
+        assertEquals("0 B", Formatter.formatFileSize(context, 0));
+        assertEquals("1 B", Formatter.formatFileSize(context, 1));
+        assertEquals("9 B", Formatter.formatFileSize(context, 9));
+        assertEquals("10 B", Formatter.formatFileSize(context, 10));
+        assertEquals("99 B", Formatter.formatFileSize(context, 99));
+        assertEquals("100 B", Formatter.formatFileSize(context, 100));
+        assertEquals("900 B", Formatter.formatFileSize(context, 900));
+        assertEquals("0.90 kB", Formatter.formatFileSize(context, 901));
 
-        assertEquals("1.00 kB", Formatter.formatFileSize(mContext, bd.pow(1).longValue()));
+        assertEquals("1.00 kB", Formatter.formatFileSize(context, bd.pow(1).longValue()));
 
-        assertEquals("1.00 MB", Formatter.formatFileSize(mContext, bd.pow(2).longValue()));
+        assertEquals("1.00 MB", Formatter.formatFileSize(context, bd.pow(2).longValue()));
 
-        assertEquals("1.00 GB", Formatter.formatFileSize(mContext, bd.pow(3).longValue()));
+        assertEquals("1.00 GB", Formatter.formatFileSize(context, bd.pow(3).longValue()));
 
-        assertEquals("1.00 TB", Formatter.formatFileSize(mContext, bd.pow(4).longValue()));
+        assertEquals("1.00 TB", Formatter.formatFileSize(context, bd.pow(4).longValue()));
 
-        assertEquals("1.00 PB", Formatter.formatFileSize(mContext, bd.pow(5).longValue()));
+        assertEquals("1.00 PB", Formatter.formatFileSize(context, bd.pow(5).longValue()));
 
-        assertEquals("1000 PB", Formatter.formatFileSize(mContext, bd.pow(6).longValue()));
+        assertEquals("1000 PB", Formatter.formatFileSize(context, bd.pow(6).longValue()));
 
         // test Negative value
-        assertEquals("-1 B", Formatter.formatFileSize(mContext, -1));
+        assertEquals("-1 B", Formatter.formatFileSize(context, -1));
     }
 
-    @SmallTest
+    @Test
     public void testFormatIpAddress() {
         assertEquals("1.0.168.192", Formatter.formatIpAddress(0xC0A80001));
         assertEquals("1.0.0.127", Formatter.formatIpAddress(0x7F000001));
diff --git a/tests/tests/text/src/android/text/format/cts/TimeTest.java b/tests/tests/text/src/android/text/format/cts/TimeTest.java
index cc73272..7c44c77 100644
--- a/tests/tests/text/src/android/text/format/cts/TimeTest.java
+++ b/tests/tests/text/src/android/text/format/cts/TimeTest.java
@@ -16,13 +16,24 @@
 
 package android.text.format.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.content.res.Configuration;
 import android.content.res.Resources;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.format.Time;
 import android.util.Log;
 import android.util.TimeFormatException;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -31,36 +42,37 @@
 import java.util.Objects;
 import java.util.TimeZone;
 
-public class TimeTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TimeTest {
     private static final String TAG = "TimeTest";
+    private static List<Locale> sSystemLocales;
 
     private Locale originalLocale;
 
-    private static List<Locale> sSystemLocales;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() {
         originalLocale = Locale.getDefault();
 
         maybeInitializeSystemLocales();
     }
 
-    @Override
-    public void tearDown() throws Exception {
+    @After
+    public void teardown() {
         // The Locale may be changed by tests. Revert to the original.
         changeJavaAndAndroidLocale(originalLocale, true /* force */);
-        super.tearDown();
     }
 
+    @Test
     public void testConstructor() {
         Time time = new Time();
         new Time(Time.getCurrentTimezone());
         time.set(System.currentTimeMillis());
         Time anotherTime = new Time(time);
-        assertTime(time, anotherTime);
+        verifyTime(time, anotherTime);
     }
 
+    @Test
     public void testNormalize() {
         final int expectedMonth = 3;
         final int expectedDate = 1;
@@ -86,6 +98,7 @@
         assertEquals(expectedDate, time.monthDay);
     }
 
+    @Test
     public void testSwitchTimezone() {
         String timeZone = "US/Pacific";
         String anotherTimeZone = "Asia/Chongqing";
@@ -95,6 +108,7 @@
         assertEquals(anotherTimeZone, time.timezone);
     }
 
+    @Test
     public void testSet() {
         final int year = 2008;
         final int month = 5;
@@ -107,10 +121,10 @@
 
         Time anotherTime = new Time();
         anotherTime.set(time);
-        assertTime(time, anotherTime);
+        verifyTime(time, anotherTime);
     }
 
-    private void assertTime(Time time, Time anotherTime) {
+    private void verifyTime(Time time, Time anotherTime) {
         assertEquals(time.timezone, anotherTime.timezone);
         assertEquals(time.allDay, anotherTime.allDay);
         assertEquals(time.second, anotherTime.second);
@@ -125,6 +139,7 @@
         assertEquals(time.gmtoff, anotherTime.gmtoff);
     }
 
+    @Test
     public void testGetWeekNumber() {
         Time time = new Time();
         time.normalize(false);
@@ -151,24 +166,22 @@
         }
     }
 
+    @Test(expected=NullPointerException.class)
     public void testParseNull() {
         Time t = new Time();
-        try {
-            t.parse(null);
-            fail();
-        } catch (NullPointerException expected) {
-        }
+        t.parse(null);
+    }
 
-        try {
-            t.parse3339(null);
-            fail();
-        } catch (NullPointerException expected) {
-        }
+    @Test(expected=NullPointerException.class)
+    public void testParse3339Null() {
+        Time t = new Time();
+        t.parse3339(null);
     }
 
     // http://code.google.com/p/android/issues/detail?id=16002
     // We'd leak one JNI global reference each time parsing failed.
     // This would cause a crash when we filled the global reference table.
+    @Test
     public void testBug16002() {
         Time t = new Time();
         for (int i = 0; i < 8192; ++i) {
@@ -183,6 +196,7 @@
     // http://code.google.com/p/android/issues/detail?id=22225
     // We'd leak one JNI global reference each time parsing failed.
     // This would cause a crash when we filled the global reference table.
+    @Test
     public void testBug22225() {
         Time t = new Time();
         for (int i = 0; i < 8192; ++i) {
@@ -194,6 +208,7 @@
         }
     }
 
+    @Test
     public void testIsEpoch() {
         Time time = new Time();
         assertTrue(Time.isEpoch(time));
@@ -202,6 +217,7 @@
         assertFalse(Time.isEpoch(time));
     }
 
+    @Test
     public void testAfterBefore() {
         Time a = new Time(Time.TIMEZONE_UTC);
         Time b = new Time("America/Los_Angeles");
@@ -347,7 +363,8 @@
             new DateTest(2007, 10, 5, 2, 0, 60, 2007, 10, 5, 3, 0),
     };
 
-    public void testNormalize1() throws Exception {
+    @Test
+    public void testNormalize1() {
         String tz = "America/Los_Angeles";
         Time local = new Time(tz);
 
@@ -363,7 +380,7 @@
             Time expected = new Time(tz);
             Fields.setDateTime(expected, test.year2, test.month2, test.day2, test.hour2,
                     test.minute2, 0);
-            Fields.assertTimeEquals("day test index " + index + ", normalize():",
+            Fields.verifyTimeEquals("day test index " + index + ", normalize():",
                     Fields.MAIN_DATE_TIME, expected, local);
 
             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
@@ -376,7 +393,7 @@
             expected = new Time(tz);
             Fields.setDateTime(expected, test.year2, test.month2, test.day2, test.hour2,
                     test.minute2, 0);
-            Fields.assertTimeEquals("day test index " + index + ", toMillis():",
+            Fields.verifyTimeEquals("day test index " + index + ", toMillis():",
                     Fields.MAIN_DATE_TIME, expected, local);
         }
 
@@ -395,7 +412,7 @@
             Fields.setDateTime(expected, test.year2, test.month2, test.day2, test.hour2,
                     test.minute2, 0);
             Fields.setDst(expected, test.dst2 /* isDst */, PstPdt.getUtcOffsetSeconds(test.dst2));
-            Fields.assertTimeEquals("minute test index " + index + ", normalize():",
+            Fields.verifyTimeEquals("minute test index " + index + ", normalize():",
                     Fields.MAIN_DATE_TIME | Fields.DST_FIELDS, expected, local);
 
             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
@@ -411,12 +428,13 @@
             Fields.setDateTime(expected, test.year2, test.month2, test.day2, test.hour2,
                     test.minute2, 0);
             Fields.setDst(expected, test.dst2 /* isDst */, PstPdt.getUtcOffsetSeconds(test.dst2));
-            Fields.assertTimeEquals("minute test index " + index + ", toMillis():",
+            Fields.verifyTimeEquals("minute test index " + index + ", toMillis():",
                     Fields.MAIN_DATE_TIME | Fields.DST_FIELDS, expected, local);
         }
     }
 
-    public void testSwitchTimezone_simpleUtc() throws Exception {
+    @Test
+    public void testSwitchTimezone_simpleUtc() {
         String originalTz = Time.TIMEZONE_UTC;
         Time t = new Time(originalTz);
         Fields.set(t, 2006, 9, 5, 12, 0, 0, -1 /* isDst */, 0, 0, 0);
@@ -426,16 +444,17 @@
 
         Time expected1 = new Time(newTz);
         Fields.set(expected1, 2006, 9, 5, 5, 0, 0, 1 /* isDst */, -25200, 277, 4);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
 
         t.switchTimezone(originalTz);
 
         Time expected2 = new Time(originalTz);
         Fields.set(expected2, 2006, 9, 5, 12, 0, 0, 0 /* isDst */, 0, 277, 4);
-        Fields.assertTimeEquals(expected2, t);
+        Fields.verifyTimeEquals(expected2, t);
     }
 
-    public void testSwitchTimezone_standardToStandardTime() throws Exception {
+    @Test
+    public void testSwitchTimezone_standardToStandardTime() {
         String zone1 = "Europe/London";
         String zone2 = "America/Los_Angeles";
 
@@ -447,16 +466,17 @@
 
         Time expected1 = new Time(zone2);
         Fields.set(expected1, 2007, 2, 10, 4, 0, 0, 0 /* isDst */, -28800, 68, 6);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
 
         t.switchTimezone(zone1);
 
         Time expected2 = new Time(zone1);
         Fields.set(expected2, 2007, 2, 10, 12, 0, 0, 0 /* isDst */, 0, 68, 6);
-        Fields.assertTimeEquals(expected2, t);
+        Fields.verifyTimeEquals(expected2, t);
     }
 
-    public void testSwitchTimezone_dstToDstTime() throws Exception {
+    @Test
+    public void testSwitchTimezone_dstToDstTime() {
         String zone1 = "Europe/London";
         String zone2 = "America/Los_Angeles";
 
@@ -468,16 +488,17 @@
 
         Time expected1 = new Time(zone2);
         Fields.set(expected1, 2007, 2, 26, 4, 0, 0, 1 /* isDst */, -25200, 84, 1);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
 
         t.switchTimezone(zone1);
 
         Time expected2 = new Time(zone1);
         Fields.set(expected2, 2007, 2, 26, 12, 0, 0, 1 /* isDst */, 3600, 84, 1);
-        Fields.assertTimeEquals(expected2, t);
+        Fields.verifyTimeEquals(expected2, t);
     }
 
-    public void testSwitchTimezone_standardToDstTime() throws Exception {
+    @Test
+    public void testSwitchTimezone_standardToDstTime() {
         String zone1 = "Europe/London";
         String zone2 = "America/Los_Angeles";
 
@@ -489,16 +510,17 @@
 
         Time expected1 = new Time(zone2);
         Fields.set(expected1, 2007, 2, 24, 5, 0, 0, 1 /* isDst */, -25200, 82, 6);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
 
         t.switchTimezone(zone1);
 
         Time expected2 = new Time(zone1);
         Fields.set(expected2, 2007, 2, 24, 12, 0, 0, 0 /* isDst */, 0, 82, 6);
-        Fields.assertTimeEquals(expected2, t);
+        Fields.verifyTimeEquals(expected2, t);
     }
 
-    public void testSwitchTimezone_sourceDateInvalid() throws Exception {
+    @Test
+    public void testSwitchTimezone_sourceDateInvalid() {
         String zone1 = "Europe/London";
         String zone2 = "America/Los_Angeles";
 
@@ -513,10 +535,11 @@
         // This illustrates why using -1 to indicate a problem, when -1 is in range, is a poor idea.
         Time expected1 = new Time(zone2);
         Fields.set(expected1, 1969, 11, 31, 15, 59, 59, 0 /* isDst */, -28800, 364, 3);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
     }
 
-    public void testSwitchTimezone_dstToStandardTime() throws Exception {
+    @Test
+    public void testSwitchTimezone_dstToStandardTime() {
         String zone1 = "America/Los_Angeles";
         String zone2 = "Europe/London";
 
@@ -528,26 +551,28 @@
 
         Time expected1 = new Time(zone2);
         Fields.set(expected1, 2007, 2, 12, 19, 0, 0, 0 /* isDst */, 0, 70, 1);
-        Fields.assertTimeEquals(expected1, t);
+        Fields.verifyTimeEquals(expected1, t);
 
         t.switchTimezone(zone1);
 
         Time expected2 = new Time(zone1);
         Fields.set(expected2, 2007, 2, 12, 12, 0, 0, 1 /* isDst */, -25200, 70, 1);
-        Fields.assertTimeEquals(expected2, t);
+        Fields.verifyTimeEquals(expected2, t);
     }
 
-    public void testCtor() throws Exception {
+    @Test
+    public void testCtor() {
         String tz = Time.TIMEZONE_UTC;
         Time t = new Time(tz);
         assertEquals(tz, t.timezone);
 
         Time expected = new Time(tz);
         Fields.set(expected, 1970, 0, 1, 0, 0, 0, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testGetActualMaximum() throws Exception {
+    @Test
+    public void testGetActualMaximum() {
         Time t = new Time(Time.TIMEZONE_UTC);
         assertEquals(59, t.getActualMaximum(Time.SECOND));
         assertEquals(59, t.getActualMaximum(Time.MINUTE));
@@ -576,21 +601,22 @@
         final int[] DAYS_PER_MONTH = {
                 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
         };
-        assertMonth(t, DAYS_PER_MONTH);
+        verifyMonth(t, DAYS_PER_MONTH);
 
         t.year = 2000;
         DAYS_PER_MONTH[1] = 29;
-        assertMonth(t, DAYS_PER_MONTH);
+        verifyMonth(t, DAYS_PER_MONTH);
     }
 
-    private void assertMonth(Time t, final int[] DAYS_PER_MONTH) {
+    private void verifyMonth(Time t, final int[] DAYS_PER_MONTH) {
         for (int i = 0; i < t.getActualMaximum(Time.MONTH); i++) {
             t.month = i;
             assertEquals(DAYS_PER_MONTH[i], t.getActualMaximum(Time.MONTH_DAY));
         }
     }
 
-    public void testClear0() throws Exception {
+    @Test
+    public void testClear0() {
         Time t = new Time(Time.getCurrentTimezone());
         t.clear(Time.TIMEZONE_UTC);
         assertEquals(Time.TIMEZONE_UTC, t.timezone);
@@ -607,7 +633,8 @@
         assertEquals(-1, t.isDst);
     }
 
-    public void testClear() throws Exception {
+    @Test
+    public void testClear() {
         Time t = new Time("America/Los_Angeles");
         Fields.set(t, 1, 2, 3, 4, 5, 6, 7 /* isDst */, 8, 9, 10);
 
@@ -615,10 +642,11 @@
 
         Time expected = new Time(Time.TIMEZONE_UTC);
         Fields.set(expected, 0, 0, 0, 0, 0, 0, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testCompare() throws Exception {
+    @Test
+    public void testCompare() {
         String timezone = "America/New_York";
         int[] aDateTimeFields = new int[] { 2005, 2, 3, 4, 5, 6 };
 
@@ -684,32 +712,25 @@
         assertEquals(0, Time.compare(b, a));
     }
 
-    public void testCompareNullFailure() throws Exception {
+    @Test(expected=NullPointerException.class)
+    public void testCompareNullSecond() {
         Time a = new Time(Time.TIMEZONE_UTC);
-
-        try {
-            Time.compare(a, null);
-            fail("Should throw NullPointerException on second argument");
-        } catch (NullPointerException e) {
-            // pass
-        }
-
-        try {
-            Time.compare(null, a);
-            fail("Should throw NullPointerException on first argument");
-        } catch (NullPointerException e) {
-            // pass
-        }
-
-        try {
-            Time.compare(null, null);
-            fail("Should throw NullPointerException because both args are null");
-        } catch (NullPointerException e) {
-            // pass
-        }
+        Time.compare(a, null);
     }
 
-    public void testCompare_invalidDatesAreEqualIfTimezoneDiffers() throws Exception {
+    @Test(expected=NullPointerException.class)
+    public void testCompareNullFirst() {
+        Time a = new Time(Time.TIMEZONE_UTC);
+        Time.compare(null, a);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testCompareNullBoth() {
+        Time.compare(null, null);
+    }
+
+    @Test
+    public void testCompare_invalidDatesAreEqualIfTimezoneDiffers() {
         String timezone = "America/New_York";
         // This date is outside of the valid set of dates that can be calculated so toMillis()
         // returns -1.
@@ -741,40 +762,45 @@
         assertEquals(0, Time.compare(a, b));
     }
 
-    public void testFormat() throws Exception {
+    @Test
+    public void testFormat() {
         Time t = new Time(Time.TIMEZONE_UTC);
         String r = t.format("%Y%m%dT%H%M%S");
         assertEquals("19700101T000000", r);
     }
 
+    @Test
     public void testFormat_null() {
         Time t = new Time(Time.TIMEZONE_UTC);
         assertEquals(t.format("%c"), t.format(null));
     }
 
-    public void testFormat_badPatterns() throws Exception {
+    @Test
+    public void testFormat_badPatterns() {
         Time t = new Time(Time.TIMEZONE_UTC);
-        assertFormatEquals(t, "%~Y", "~Y");
-        assertFormatEquals(t, "%", "%");
+        verifyFormatEquals(t, "%~Y", "~Y");
+        verifyFormatEquals(t, "%", "%");
     }
 
-    public void testFormat_doesNotNormalize() throws Exception {
+    @Test
+    public void testFormat_doesNotNormalize() {
         Time t = new Time(Time.TIMEZONE_UTC);
         Fields.set(t, 2005, 13, 32, -1, -1, -1, -2, -2, -2, -2);
 
         Time tCopy = new Time(t);
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
 
-        assertFormatEquals(t, "%Y%m%dT%H%M%S", "20051432T-1-1-1");
+        verifyFormatEquals(t, "%Y%m%dT%H%M%S", "20051432T-1-1-1");
 
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
     }
 
-    private static void assertFormatEquals(Time t, String formatArg, String expected) {
+    private static void verifyFormatEquals(Time t, String formatArg, String expected) {
         assertEquals(expected, t.format(formatArg));
     }
 
-    public void testFormat_tokensUkLocale() throws Exception {
+    @Test
+    public void testFormat_tokensUkLocale() {
         if (!changeJavaAndAndroidLocale(Locale.UK, false /* force */)) {
             Log.w(TAG, "Skipping testFormat_tokensUkLocale: no assets found");
             return;
@@ -784,92 +810,93 @@
         Fields.setDateTime(t, 2005, 5, 1, 12, 30, 15);
 
         // Prove the un-normalized fields are used.
-        assertFormatEquals(t, "%A", "Sunday");
+        verifyFormatEquals(t, "%A", "Sunday");
 
         // Set fields like weekday.
         t.normalize(true);
 
-        assertFormatEquals(t, "%A", "Wednesday");
-        assertFormatEquals(t, "%a", "Wed");
-        assertFormatEquals(t, "%B", "June");
-        assertFormatEquals(t, "%b", "Jun");
-        assertFormatEquals(t, "%C", "20");
-        assertFormatEquals(t, "%c", "1 Jun 2005, 12:30:15");
-        assertFormatEquals(t, "%D", "06/01/05");
-        assertFormatEquals(t, "%d", "01");
-        assertFormatEquals(t, "%E", "E");
-        assertFormatEquals(t, "%e", " 1");
-        assertFormatEquals(t, "%F", "2005-06-01");
-        assertFormatEquals(t, "%G", "2005");
-        assertFormatEquals(t, "%g", "05");
-        assertFormatEquals(t, "%H", "12");
-        assertFormatEquals(t, "%h", "Jun");
-        assertFormatEquals(t, "%I", "12");
-        assertFormatEquals(t, "%j", "152");
-        assertFormatEquals(t, "%K", "K");
-        assertFormatEquals(t, "%k", "12");
-        assertFormatEquals(t, "%l", "12");
-        assertFormatEquals(t, "%M", "30");
-        assertFormatEquals(t, "%m", "06");
-        assertFormatEquals(t, "%n", "\n");
-        assertFormatEquals(t, "%O", "O");
-        assertFormatEquals(t, "%p", "pm");
-        assertFormatEquals(t, "%P", "pm");
-        assertFormatEquals(t, "%R", "12:30");
-        assertFormatEquals(t, "%r", "12:30:15 pm");
-        assertFormatEquals(t, "%S", "15");
+        verifyFormatEquals(t, "%A", "Wednesday");
+        verifyFormatEquals(t, "%a", "Wed");
+        verifyFormatEquals(t, "%B", "June");
+        verifyFormatEquals(t, "%b", "Jun");
+        verifyFormatEquals(t, "%C", "20");
+        verifyFormatEquals(t, "%c", "1 Jun 2005, 12:30:15");
+        verifyFormatEquals(t, "%D", "06/01/05");
+        verifyFormatEquals(t, "%d", "01");
+        verifyFormatEquals(t, "%E", "E");
+        verifyFormatEquals(t, "%e", " 1");
+        verifyFormatEquals(t, "%F", "2005-06-01");
+        verifyFormatEquals(t, "%G", "2005");
+        verifyFormatEquals(t, "%g", "05");
+        verifyFormatEquals(t, "%H", "12");
+        verifyFormatEquals(t, "%h", "Jun");
+        verifyFormatEquals(t, "%I", "12");
+        verifyFormatEquals(t, "%j", "152");
+        verifyFormatEquals(t, "%K", "K");
+        verifyFormatEquals(t, "%k", "12");
+        verifyFormatEquals(t, "%l", "12");
+        verifyFormatEquals(t, "%M", "30");
+        verifyFormatEquals(t, "%m", "06");
+        verifyFormatEquals(t, "%n", "\n");
+        verifyFormatEquals(t, "%O", "O");
+        verifyFormatEquals(t, "%p", "pm");
+        verifyFormatEquals(t, "%P", "pm");
+        verifyFormatEquals(t, "%R", "12:30");
+        verifyFormatEquals(t, "%r", "12:30:15 pm");
+        verifyFormatEquals(t, "%S", "15");
         // The original C implementation uses the (native) system default TZ, not the timezone of
         // the Time to calculate this and was therefore not stable. This changed to use the Time's
         // timezone when the Time class was re-written in Java.
-        assertFormatEquals(t, "%s", "1117625415");
-        assertFormatEquals(t, "%T", "12:30:15");
-        assertFormatEquals(t, "%t", "\t");
-        assertFormatEquals(t, "%U", "22");
-        assertFormatEquals(t, "%u", "3");
-        assertFormatEquals(t, "%V", "22");
-        assertFormatEquals(t, "%v", " 1-Jun-2005");
-        assertFormatEquals(t, "%W", "22");
-        assertFormatEquals(t, "%w", "3");
-        assertFormatEquals(t, "%X", "12:30:15");
-        assertFormatEquals(t, "%x", "1 June 2005");
-        assertFormatEquals(t, "%y", "05");
-        assertFormatEquals(t, "%Y", "2005");
-        assertFormatEquals(t, "%Z", "BST");
-        assertFormatEquals(t, "%z", "+0100");
-        assertFormatEquals(t, "%+", "Wed Jun  1 12:30:15 BST 2005");
-        assertFormatEquals(t, "%%", "%");
+        verifyFormatEquals(t, "%s", "1117625415");
+        verifyFormatEquals(t, "%T", "12:30:15");
+        verifyFormatEquals(t, "%t", "\t");
+        verifyFormatEquals(t, "%U", "22");
+        verifyFormatEquals(t, "%u", "3");
+        verifyFormatEquals(t, "%V", "22");
+        verifyFormatEquals(t, "%v", " 1-Jun-2005");
+        verifyFormatEquals(t, "%W", "22");
+        verifyFormatEquals(t, "%w", "3");
+        verifyFormatEquals(t, "%X", "12:30:15");
+        verifyFormatEquals(t, "%x", "1 June 2005");
+        verifyFormatEquals(t, "%y", "05");
+        verifyFormatEquals(t, "%Y", "2005");
+        verifyFormatEquals(t, "%Z", "BST");
+        verifyFormatEquals(t, "%z", "+0100");
+        verifyFormatEquals(t, "%+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%%", "%");
 
         // Modifiers
 
-        assertFormatEquals(t, "%EC", "20");
-        assertFormatEquals(t, "%OC", "20");
+        verifyFormatEquals(t, "%EC", "20");
+        verifyFormatEquals(t, "%OC", "20");
 
-        assertFormatEquals(t, "%_+", "Wed Jun  1 12:30:15 BST 2005");
-        assertFormatEquals(t, "%-+", "Wed Jun  1 12:30:15 BST 2005");
-        assertFormatEquals(t, "%0+", "Wed Jun  1 12:30:15 BST 2005");
-        assertFormatEquals(t, "%^+", "Wed Jun  1 12:30:15 BST 2005");
-        assertFormatEquals(t, "%#+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%_+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%-+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%0+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%^+", "Wed Jun  1 12:30:15 BST 2005");
+        verifyFormatEquals(t, "%#+", "Wed Jun  1 12:30:15 BST 2005");
 
-        assertFormatEquals(t, "%_A", "Wednesday");
-        assertFormatEquals(t, "%-A", "Wednesday");
-        assertFormatEquals(t, "%0A", "Wednesday");
-        assertFormatEquals(t, "%^A", "WEDNESDAY");
-        assertFormatEquals(t, "%#A", "wEDNESDAY");
+        verifyFormatEquals(t, "%_A", "Wednesday");
+        verifyFormatEquals(t, "%-A", "Wednesday");
+        verifyFormatEquals(t, "%0A", "Wednesday");
+        verifyFormatEquals(t, "%^A", "WEDNESDAY");
+        verifyFormatEquals(t, "%#A", "wEDNESDAY");
 
-        assertFormatEquals(t, "%_Y", "20 5");
-        assertFormatEquals(t, "%-Y", "205");
-        assertFormatEquals(t, "%0Y", "2005");
-        assertFormatEquals(t, "%^Y", "2005");
-        assertFormatEquals(t, "%#Y", "2005");
+        verifyFormatEquals(t, "%_Y", "20 5");
+        verifyFormatEquals(t, "%-Y", "205");
+        verifyFormatEquals(t, "%0Y", "2005");
+        verifyFormatEquals(t, "%^Y", "2005");
+        verifyFormatEquals(t, "%#Y", "2005");
 
-        assertFormatEquals(t, "%_d", " 1");
-        assertFormatEquals(t, "%-d", "1");
-        assertFormatEquals(t, "%0d", "01");
-        assertFormatEquals(t, "%^d", "01");
-        assertFormatEquals(t, "%#d", "01");
+        verifyFormatEquals(t, "%_d", " 1");
+        verifyFormatEquals(t, "%-d", "1");
+        verifyFormatEquals(t, "%0d", "01");
+        verifyFormatEquals(t, "%^d", "01");
+        verifyFormatEquals(t, "%#d", "01");
     }
 
-    public void testFormat_tokensUsLocale() throws Exception {
+    @Test
+    public void testFormat_tokensUsLocale() {
         if (!changeJavaAndAndroidLocale(Locale.US, false /* force */)) {
             Log.w(TAG, "Skipping testFormat_tokensUSLocale: no assets found");
             return;
@@ -879,92 +906,93 @@
         Fields.setDateTime(t, 2005, 5, 1, 12, 30, 15);
 
         // Prove the un-normalized fields are used.
-        assertFormatEquals(t, "%A", "Sunday");
+        verifyFormatEquals(t, "%A", "Sunday");
 
         // Set fields like weekday.
         t.normalize(true);
 
-        assertFormatEquals(t, "%A", "Wednesday");
-        assertFormatEquals(t, "%a", "Wed");
-        assertFormatEquals(t, "%B", "June");
-        assertFormatEquals(t, "%b", "Jun");
-        assertFormatEquals(t, "%C", "20");
-        assertFormatEquals(t, "%c", "Jun 1, 2005, 12:30:15 PM");
-        assertFormatEquals(t, "%D", "06/01/05");
-        assertFormatEquals(t, "%d", "01");
-        assertFormatEquals(t, "%E", "E");
-        assertFormatEquals(t, "%e", " 1");
-        assertFormatEquals(t, "%F", "2005-06-01");
-        assertFormatEquals(t, "%G", "2005");
-        assertFormatEquals(t, "%g", "05");
-        assertFormatEquals(t, "%H", "12");
-        assertFormatEquals(t, "%h", "Jun");
-        assertFormatEquals(t, "%I", "12");
-        assertFormatEquals(t, "%j", "152");
-        assertFormatEquals(t, "%K", "K");
-        assertFormatEquals(t, "%k", "12");
-        assertFormatEquals(t, "%l", "12");
-        assertFormatEquals(t, "%M", "30");
-        assertFormatEquals(t, "%m", "06");
-        assertFormatEquals(t, "%n", "\n");
-        assertFormatEquals(t, "%O", "O");
-        assertFormatEquals(t, "%p", "PM");
-        assertFormatEquals(t, "%P", "pm");
-        assertFormatEquals(t, "%R", "12:30");
-        assertFormatEquals(t, "%r", "12:30:15 PM");
-        assertFormatEquals(t, "%S", "15");
+        verifyFormatEquals(t, "%A", "Wednesday");
+        verifyFormatEquals(t, "%a", "Wed");
+        verifyFormatEquals(t, "%B", "June");
+        verifyFormatEquals(t, "%b", "Jun");
+        verifyFormatEquals(t, "%C", "20");
+        verifyFormatEquals(t, "%c", "Jun 1, 2005, 12:30:15 PM");
+        verifyFormatEquals(t, "%D", "06/01/05");
+        verifyFormatEquals(t, "%d", "01");
+        verifyFormatEquals(t, "%E", "E");
+        verifyFormatEquals(t, "%e", " 1");
+        verifyFormatEquals(t, "%F", "2005-06-01");
+        verifyFormatEquals(t, "%G", "2005");
+        verifyFormatEquals(t, "%g", "05");
+        verifyFormatEquals(t, "%H", "12");
+        verifyFormatEquals(t, "%h", "Jun");
+        verifyFormatEquals(t, "%I", "12");
+        verifyFormatEquals(t, "%j", "152");
+        verifyFormatEquals(t, "%K", "K");
+        verifyFormatEquals(t, "%k", "12");
+        verifyFormatEquals(t, "%l", "12");
+        verifyFormatEquals(t, "%M", "30");
+        verifyFormatEquals(t, "%m", "06");
+        verifyFormatEquals(t, "%n", "\n");
+        verifyFormatEquals(t, "%O", "O");
+        verifyFormatEquals(t, "%p", "PM");
+        verifyFormatEquals(t, "%P", "pm");
+        verifyFormatEquals(t, "%R", "12:30");
+        verifyFormatEquals(t, "%r", "12:30:15 PM");
+        verifyFormatEquals(t, "%S", "15");
         // The original C implementation uses the (native) system default TZ, not the timezone of
         // the Time to calculate this and was therefore not stable. This changed to use the Time's
         // timezone when the Time class was re-written in Java.
-        assertFormatEquals(t, "%s", "1117643415");
-        assertFormatEquals(t, "%T", "12:30:15");
-        assertFormatEquals(t, "%t", "\t");
-        assertFormatEquals(t, "%U", "22");
-        assertFormatEquals(t, "%u", "3");
-        assertFormatEquals(t, "%V", "22");
-        assertFormatEquals(t, "%v", " 1-Jun-2005");
-        assertFormatEquals(t, "%W", "22");
-        assertFormatEquals(t, "%w", "3");
-        assertFormatEquals(t, "%X", "12:30:15 PM");
-        assertFormatEquals(t, "%x", "June 1, 2005");
-        assertFormatEquals(t, "%y", "05");
-        assertFormatEquals(t, "%Y", "2005");
-        assertFormatEquals(t, "%Z", "EDT");
-        assertFormatEquals(t, "%z", "-0400");
-        assertFormatEquals(t, "%+", "Wed Jun  1 12:30:15 EDT 2005");
-        assertFormatEquals(t, "%%", "%");
+        verifyFormatEquals(t, "%s", "1117643415");
+        verifyFormatEquals(t, "%T", "12:30:15");
+        verifyFormatEquals(t, "%t", "\t");
+        verifyFormatEquals(t, "%U", "22");
+        verifyFormatEquals(t, "%u", "3");
+        verifyFormatEquals(t, "%V", "22");
+        verifyFormatEquals(t, "%v", " 1-Jun-2005");
+        verifyFormatEquals(t, "%W", "22");
+        verifyFormatEquals(t, "%w", "3");
+        verifyFormatEquals(t, "%X", "12:30:15 PM");
+        verifyFormatEquals(t, "%x", "June 1, 2005");
+        verifyFormatEquals(t, "%y", "05");
+        verifyFormatEquals(t, "%Y", "2005");
+        verifyFormatEquals(t, "%Z", "EDT");
+        verifyFormatEquals(t, "%z", "-0400");
+        verifyFormatEquals(t, "%+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%%", "%");
 
         // Modifiers
 
-        assertFormatEquals(t, "%EC", "20");
-        assertFormatEquals(t, "%OC", "20");
+        verifyFormatEquals(t, "%EC", "20");
+        verifyFormatEquals(t, "%OC", "20");
 
-        assertFormatEquals(t, "%_+", "Wed Jun  1 12:30:15 EDT 2005");
-        assertFormatEquals(t, "%-+", "Wed Jun  1 12:30:15 EDT 2005");
-        assertFormatEquals(t, "%0+", "Wed Jun  1 12:30:15 EDT 2005");
-        assertFormatEquals(t, "%^+", "Wed Jun  1 12:30:15 EDT 2005");
-        assertFormatEquals(t, "%#+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%_+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%-+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%0+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%^+", "Wed Jun  1 12:30:15 EDT 2005");
+        verifyFormatEquals(t, "%#+", "Wed Jun  1 12:30:15 EDT 2005");
 
-        assertFormatEquals(t, "%_A", "Wednesday");
-        assertFormatEquals(t, "%-A", "Wednesday");
-        assertFormatEquals(t, "%0A", "Wednesday");
-        assertFormatEquals(t, "%^A", "WEDNESDAY");
-        assertFormatEquals(t, "%#A", "wEDNESDAY");
+        verifyFormatEquals(t, "%_A", "Wednesday");
+        verifyFormatEquals(t, "%-A", "Wednesday");
+        verifyFormatEquals(t, "%0A", "Wednesday");
+        verifyFormatEquals(t, "%^A", "WEDNESDAY");
+        verifyFormatEquals(t, "%#A", "wEDNESDAY");
 
-        assertFormatEquals(t, "%_Y", "20 5");
-        assertFormatEquals(t, "%-Y", "205");
-        assertFormatEquals(t, "%0Y", "2005");
-        assertFormatEquals(t, "%^Y", "2005");
-        assertFormatEquals(t, "%#Y", "2005");
+        verifyFormatEquals(t, "%_Y", "20 5");
+        verifyFormatEquals(t, "%-Y", "205");
+        verifyFormatEquals(t, "%0Y", "2005");
+        verifyFormatEquals(t, "%^Y", "2005");
+        verifyFormatEquals(t, "%#Y", "2005");
 
-        assertFormatEquals(t, "%_d", " 1");
-        assertFormatEquals(t, "%-d", "1");
-        assertFormatEquals(t, "%0d", "01");
-        assertFormatEquals(t, "%^d", "01");
-        assertFormatEquals(t, "%#d", "01");
+        verifyFormatEquals(t, "%_d", " 1");
+        verifyFormatEquals(t, "%-d", "1");
+        verifyFormatEquals(t, "%0d", "01");
+        verifyFormatEquals(t, "%^d", "01");
+        verifyFormatEquals(t, "%#d", "01");
     }
 
-    public void testFormat_tokensFranceLocale() throws Exception {
+    @Test
+    public void testFormat_tokensFranceLocale() {
         if (!changeJavaAndAndroidLocale(Locale.FRANCE, false /* force */)) {
             Log.w(TAG, "Skipping testFormat_tokensFranceLocale: no assets found");
             return;
@@ -974,92 +1002,93 @@
         Fields.setDateTime(t, 2005, 5, 1, 12, 30, 15);
 
         // Prove the un-normalized fields are used.
-        assertFormatEquals(t, "%A", "dimanche");
+        verifyFormatEquals(t, "%A", "dimanche");
 
         // Set fields like weekday.
         t.normalize(true);
 
-        assertFormatEquals(t, "%A", "mercredi");
-        assertFormatEquals(t, "%a", "mer.");
-        assertFormatEquals(t, "%B", "juin");
-        assertFormatEquals(t, "%b", "juin");
-        assertFormatEquals(t, "%C", "20");
-        assertFormatEquals(t, "%c", "1 juin 2005 à 12:30:15");
-        assertFormatEquals(t, "%D", "06/01/05");
-        assertFormatEquals(t, "%d", "01");
-        assertFormatEquals(t, "%E", "E");
-        assertFormatEquals(t, "%e", " 1");
-        assertFormatEquals(t, "%F", "2005-06-01");
-        assertFormatEquals(t, "%G", "2005");
-        assertFormatEquals(t, "%g", "05");
-        assertFormatEquals(t, "%H", "12");
-        assertFormatEquals(t, "%h", "juin");
-        assertFormatEquals(t, "%I", "12");
-        assertFormatEquals(t, "%j", "152");
-        assertFormatEquals(t, "%K", "K");
-        assertFormatEquals(t, "%k", "12");
-        assertFormatEquals(t, "%l", "12");
-        assertFormatEquals(t, "%M", "30");
-        assertFormatEquals(t, "%m", "06");
-        assertFormatEquals(t, "%n", "\n");
-        assertFormatEquals(t, "%O", "O");
-        assertFormatEquals(t, "%p", "PM");
-        assertFormatEquals(t, "%P", "pm");
-        assertFormatEquals(t, "%R", "12:30");
-        assertFormatEquals(t, "%r", "12:30:15 PM");
-        assertFormatEquals(t, "%S", "15");
+        verifyFormatEquals(t, "%A", "mercredi");
+        verifyFormatEquals(t, "%a", "mer.");
+        verifyFormatEquals(t, "%B", "juin");
+        verifyFormatEquals(t, "%b", "juin");
+        verifyFormatEquals(t, "%C", "20");
+        verifyFormatEquals(t, "%c", "1 juin 2005 à 12:30:15");
+        verifyFormatEquals(t, "%D", "06/01/05");
+        verifyFormatEquals(t, "%d", "01");
+        verifyFormatEquals(t, "%E", "E");
+        verifyFormatEquals(t, "%e", " 1");
+        verifyFormatEquals(t, "%F", "2005-06-01");
+        verifyFormatEquals(t, "%G", "2005");
+        verifyFormatEquals(t, "%g", "05");
+        verifyFormatEquals(t, "%H", "12");
+        verifyFormatEquals(t, "%h", "juin");
+        verifyFormatEquals(t, "%I", "12");
+        verifyFormatEquals(t, "%j", "152");
+        verifyFormatEquals(t, "%K", "K");
+        verifyFormatEquals(t, "%k", "12");
+        verifyFormatEquals(t, "%l", "12");
+        verifyFormatEquals(t, "%M", "30");
+        verifyFormatEquals(t, "%m", "06");
+        verifyFormatEquals(t, "%n", "\n");
+        verifyFormatEquals(t, "%O", "O");
+        verifyFormatEquals(t, "%p", "PM");
+        verifyFormatEquals(t, "%P", "pm");
+        verifyFormatEquals(t, "%R", "12:30");
+        verifyFormatEquals(t, "%r", "12:30:15 PM");
+        verifyFormatEquals(t, "%S", "15");
         // The original C implementation uses the (native) system default TZ, not the timezone of
         // the Time to calculate this and was therefore not stable. This changed to use the Time's
         // timezone when the Time class was re-written in Java.
-        assertFormatEquals(t, "%s", "1117621815");
-        assertFormatEquals(t, "%T", "12:30:15");
-        assertFormatEquals(t, "%t", "\t");
-        assertFormatEquals(t, "%U", "22");
-        assertFormatEquals(t, "%u", "3");
-        assertFormatEquals(t, "%V", "22");
-        assertFormatEquals(t, "%v", " 1-juin-2005");
-        assertFormatEquals(t, "%W", "22");
-        assertFormatEquals(t, "%w", "3");
-        assertFormatEquals(t, "%X", "12:30:15");
-        assertFormatEquals(t, "%x", "1 juin 2005");
-        assertFormatEquals(t, "%y", "05");
-        assertFormatEquals(t, "%Y", "2005");
-        assertFormatEquals(t, "%Z", "GMT+02:00");
-        assertFormatEquals(t, "%z", "+0200");
-        assertFormatEquals(t, "%+", "mer. juin  1 12:30:15 GMT+02:00 2005");
-        assertFormatEquals(t, "%%", "%");
+        verifyFormatEquals(t, "%s", "1117621815");
+        verifyFormatEquals(t, "%T", "12:30:15");
+        verifyFormatEquals(t, "%t", "\t");
+        verifyFormatEquals(t, "%U", "22");
+        verifyFormatEquals(t, "%u", "3");
+        verifyFormatEquals(t, "%V", "22");
+        verifyFormatEquals(t, "%v", " 1-juin-2005");
+        verifyFormatEquals(t, "%W", "22");
+        verifyFormatEquals(t, "%w", "3");
+        verifyFormatEquals(t, "%X", "12:30:15");
+        verifyFormatEquals(t, "%x", "1 juin 2005");
+        verifyFormatEquals(t, "%y", "05");
+        verifyFormatEquals(t, "%Y", "2005");
+        verifyFormatEquals(t, "%Z", "GMT+02:00");
+        verifyFormatEquals(t, "%z", "+0200");
+        verifyFormatEquals(t, "%+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%%", "%");
 
         // Modifiers
 
-        assertFormatEquals(t, "%EC", "20");
-        assertFormatEquals(t, "%OC", "20");
+        verifyFormatEquals(t, "%EC", "20");
+        verifyFormatEquals(t, "%OC", "20");
 
-        assertFormatEquals(t, "%_+", "mer. juin  1 12:30:15 GMT+02:00 2005");
-        assertFormatEquals(t, "%-+", "mer. juin  1 12:30:15 GMT+02:00 2005");
-        assertFormatEquals(t, "%0+", "mer. juin  1 12:30:15 GMT+02:00 2005");
-        assertFormatEquals(t, "%^+", "mer. juin  1 12:30:15 GMT+02:00 2005");
-        assertFormatEquals(t, "%#+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%_+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%-+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%0+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%^+", "mer. juin  1 12:30:15 GMT+02:00 2005");
+        verifyFormatEquals(t, "%#+", "mer. juin  1 12:30:15 GMT+02:00 2005");
 
-        assertFormatEquals(t, "%_A", "mercredi");
-        assertFormatEquals(t, "%-A", "mercredi");
-        assertFormatEquals(t, "%0A", "mercredi");
-        assertFormatEquals(t, "%^A", "MERCREDI");
-        assertFormatEquals(t, "%#A", "MERCREDI");
+        verifyFormatEquals(t, "%_A", "mercredi");
+        verifyFormatEquals(t, "%-A", "mercredi");
+        verifyFormatEquals(t, "%0A", "mercredi");
+        verifyFormatEquals(t, "%^A", "MERCREDI");
+        verifyFormatEquals(t, "%#A", "MERCREDI");
 
-        assertFormatEquals(t, "%_Y", "20 5");
-        assertFormatEquals(t, "%-Y", "205");
-        assertFormatEquals(t, "%0Y", "2005");
-        assertFormatEquals(t, "%^Y", "2005");
-        assertFormatEquals(t, "%#Y", "2005");
+        verifyFormatEquals(t, "%_Y", "20 5");
+        verifyFormatEquals(t, "%-Y", "205");
+        verifyFormatEquals(t, "%0Y", "2005");
+        verifyFormatEquals(t, "%^Y", "2005");
+        verifyFormatEquals(t, "%#Y", "2005");
 
-        assertFormatEquals(t, "%_d", " 1");
-        assertFormatEquals(t, "%-d", "1");
-        assertFormatEquals(t, "%0d", "01");
-        assertFormatEquals(t, "%^d", "01");
-        assertFormatEquals(t, "%#d", "01");
+        verifyFormatEquals(t, "%_d", " 1");
+        verifyFormatEquals(t, "%-d", "1");
+        verifyFormatEquals(t, "%0d", "01");
+        verifyFormatEquals(t, "%^d", "01");
+        verifyFormatEquals(t, "%#d", "01");
     }
 
-    public void testFormat_tokensJapanLocale() throws Exception {
+    @Test
+    public void testFormat_tokensJapanLocale() {
         if (!changeJavaAndAndroidLocale(Locale.JAPAN, false /* force */)) {
             Log.w(TAG, "Skipping testFormat_tokensJapanLocale: no assets found");
             return;
@@ -1069,91 +1098,92 @@
         Fields.setDateTime(t, 2005, 5, 1, 12, 30, 15);
 
         // Prove the un-normalized fields are used.
-        assertFormatEquals(t, "%A", "日曜日");
+        verifyFormatEquals(t, "%A", "日曜日");
 
         // Set fields like weekday.
         t.normalize(true);
 
-        assertFormatEquals(t, "%A", "水曜日");
-        assertFormatEquals(t, "%a", "水");
-        assertFormatEquals(t, "%B", "6月");
-        assertFormatEquals(t, "%b", "6月");
-        assertFormatEquals(t, "%C", "20");
-        assertFormatEquals(t, "%c", "2005/06/01 12:30:15");
-        assertFormatEquals(t, "%D", "06/01/05");
-        assertFormatEquals(t, "%d", "01");
-        assertFormatEquals(t, "%E", "E");
-        assertFormatEquals(t, "%e", " 1");
-        assertFormatEquals(t, "%F", "2005-06-01");
-        assertFormatEquals(t, "%G", "2005");
-        assertFormatEquals(t, "%g", "05");
-        assertFormatEquals(t, "%H", "12");
-        assertFormatEquals(t, "%h", "6月");
-        assertFormatEquals(t, "%I", "12");
-        assertFormatEquals(t, "%j", "152");
-        assertFormatEquals(t, "%k", "12");
-        assertFormatEquals(t, "%l", "12");
-        assertFormatEquals(t, "%M", "30");
-        assertFormatEquals(t, "%m", "06");
-        assertFormatEquals(t, "%n", "\n");
-        assertFormatEquals(t, "%O", "O");
-        assertFormatEquals(t, "%p", "午後");
-        assertFormatEquals(t, "%P", "午後");
-        assertFormatEquals(t, "%R", "12:30");
-        assertFormatEquals(t, "%r", "12:30:15 午後");
-        assertFormatEquals(t, "%S", "15");
+        verifyFormatEquals(t, "%A", "水曜日");
+        verifyFormatEquals(t, "%a", "水");
+        verifyFormatEquals(t, "%B", "6月");
+        verifyFormatEquals(t, "%b", "6月");
+        verifyFormatEquals(t, "%C", "20");
+        verifyFormatEquals(t, "%c", "2005/06/01 12:30:15");
+        verifyFormatEquals(t, "%D", "06/01/05");
+        verifyFormatEquals(t, "%d", "01");
+        verifyFormatEquals(t, "%E", "E");
+        verifyFormatEquals(t, "%e", " 1");
+        verifyFormatEquals(t, "%F", "2005-06-01");
+        verifyFormatEquals(t, "%G", "2005");
+        verifyFormatEquals(t, "%g", "05");
+        verifyFormatEquals(t, "%H", "12");
+        verifyFormatEquals(t, "%h", "6月");
+        verifyFormatEquals(t, "%I", "12");
+        verifyFormatEquals(t, "%j", "152");
+        verifyFormatEquals(t, "%k", "12");
+        verifyFormatEquals(t, "%l", "12");
+        verifyFormatEquals(t, "%M", "30");
+        verifyFormatEquals(t, "%m", "06");
+        verifyFormatEquals(t, "%n", "\n");
+        verifyFormatEquals(t, "%O", "O");
+        verifyFormatEquals(t, "%p", "午後");
+        verifyFormatEquals(t, "%P", "午後");
+        verifyFormatEquals(t, "%R", "12:30");
+        verifyFormatEquals(t, "%r", "12:30:15 午後");
+        verifyFormatEquals(t, "%S", "15");
         // The original C implementation uses the (native) system default TZ, not the timezone of
         // the Time to calculate this and was therefore not stable. This changed to use the Time's
         // timezone when the Time class was re-written in Java.
-        assertFormatEquals(t, "%s", "1117596615");
-        assertFormatEquals(t, "%T", "12:30:15");
-        assertFormatEquals(t, "%t", "\t");
-        assertFormatEquals(t, "%U", "22");
-        assertFormatEquals(t, "%u", "3");
-        assertFormatEquals(t, "%V", "22");
-        assertFormatEquals(t, "%v", " 1-6月-2005");
-        assertFormatEquals(t, "%W", "22");
-        assertFormatEquals(t, "%w", "3");
-        assertFormatEquals(t, "%X", "12:30:15");
-        assertFormatEquals(t, "%x", "2005年6月1日");
-        assertFormatEquals(t, "%y", "05");
-        assertFormatEquals(t, "%Y", "2005");
-        assertFormatEquals(t, "%Z", "JST");
-        assertFormatEquals(t, "%z", "+0900");
-        assertFormatEquals(t, "%+", "水 6月  1 12:30:15 JST 2005");
-        assertFormatEquals(t, "%%", "%");
+        verifyFormatEquals(t, "%s", "1117596615");
+        verifyFormatEquals(t, "%T", "12:30:15");
+        verifyFormatEquals(t, "%t", "\t");
+        verifyFormatEquals(t, "%U", "22");
+        verifyFormatEquals(t, "%u", "3");
+        verifyFormatEquals(t, "%V", "22");
+        verifyFormatEquals(t, "%v", " 1-6月-2005");
+        verifyFormatEquals(t, "%W", "22");
+        verifyFormatEquals(t, "%w", "3");
+        verifyFormatEquals(t, "%X", "12:30:15");
+        verifyFormatEquals(t, "%x", "2005年6月1日");
+        verifyFormatEquals(t, "%y", "05");
+        verifyFormatEquals(t, "%Y", "2005");
+        verifyFormatEquals(t, "%Z", "JST");
+        verifyFormatEquals(t, "%z", "+0900");
+        verifyFormatEquals(t, "%+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%%", "%");
 
         // Modifiers
 
-        assertFormatEquals(t, "%EC", "20");
-        assertFormatEquals(t, "%OC", "20");
+        verifyFormatEquals(t, "%EC", "20");
+        verifyFormatEquals(t, "%OC", "20");
 
-        assertFormatEquals(t, "%_+", "水 6月  1 12:30:15 JST 2005");
-        assertFormatEquals(t, "%-+", "水 6月  1 12:30:15 JST 2005");
-        assertFormatEquals(t, "%0+", "水 6月  1 12:30:15 JST 2005");
-        assertFormatEquals(t, "%^+", "水 6月  1 12:30:15 JST 2005");
-        assertFormatEquals(t, "%#+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%_+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%-+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%0+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%^+", "水 6月  1 12:30:15 JST 2005");
+        verifyFormatEquals(t, "%#+", "水 6月  1 12:30:15 JST 2005");
 
-        assertFormatEquals(t, "%_A", "水曜日");
-        assertFormatEquals(t, "%-A", "水曜日");
-        assertFormatEquals(t, "%0A", "水曜日");
-        assertFormatEquals(t, "%^A", "水曜日");
-        assertFormatEquals(t, "%#A", "水曜日");
+        verifyFormatEquals(t, "%_A", "水曜日");
+        verifyFormatEquals(t, "%-A", "水曜日");
+        verifyFormatEquals(t, "%0A", "水曜日");
+        verifyFormatEquals(t, "%^A", "水曜日");
+        verifyFormatEquals(t, "%#A", "水曜日");
 
-        assertFormatEquals(t, "%_Y", "20 5");
-        assertFormatEquals(t, "%-Y", "205");
-        assertFormatEquals(t, "%0Y", "2005");
-        assertFormatEquals(t, "%^Y", "2005");
-        assertFormatEquals(t, "%#Y", "2005");
+        verifyFormatEquals(t, "%_Y", "20 5");
+        verifyFormatEquals(t, "%-Y", "205");
+        verifyFormatEquals(t, "%0Y", "2005");
+        verifyFormatEquals(t, "%^Y", "2005");
+        verifyFormatEquals(t, "%#Y", "2005");
 
-        assertFormatEquals(t, "%_d", " 1");
-        assertFormatEquals(t, "%-d", "1");
-        assertFormatEquals(t, "%0d", "01");
-        assertFormatEquals(t, "%^d", "01");
-        assertFormatEquals(t, "%#d", "01");
+        verifyFormatEquals(t, "%_d", " 1");
+        verifyFormatEquals(t, "%-d", "1");
+        verifyFormatEquals(t, "%0d", "01");
+        verifyFormatEquals(t, "%^d", "01");
+        verifyFormatEquals(t, "%#d", "01");
     }
 
-    public void testFormat2445() throws Exception {
+    @Test
+    public void testFormat2445() {
         Time t = new Time(Time.TIMEZONE_UTC);
         Fields.setDateTime(t, 2005, 5, 1, 12, 30, 15);
 
@@ -1171,22 +1201,24 @@
         assertEquals("2005000 T0 0 0 ", t.format2445());
     }
 
-    public void testFormat2445_doesNotNormalize() throws Exception {
+    @Test
+    public void testFormat2445_doesNotNormalize() {
         Time t = new Time(Time.TIMEZONE_UTC);
         Fields.set(t, 2005, 13, 32, 25, 61, 61, -2, -2, -2, -2);
 
         Time tCopy = new Time(t);
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
 
         assertEquals("20051432T256161Z", t.format2445());
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
 
         t.timezone = tCopy.timezone = "America/Los_Angeles";
         assertEquals("20051432T256161", t.format2445());
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
     }
 
-    public void testToString() throws Exception {
+    @Test
+    public void testToString() {
         Time t = new Time(Time.TIMEZONE_UTC);
         assertEquals("19700101T000000UTC(0,0,0,-1,0)", t.toString());
 
@@ -1194,25 +1226,28 @@
         assertEquals("19700101T000000America/Los_Angeles(0,0,0,-1,28800)", t.toString());
     }
 
-    public void testToString_doesNotNormalize() throws Exception {
+    @Test
+    public void testToString_doesNotNormalize() {
         Time t = new Time(Time.TIMEZONE_UTC);
         Fields.set(t, 2005, 13, 32, -1, -1, -1, -2, -2, -2, -2);
 
         Time tCopy = new Time(t);
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
 
         String r = t.toString();
         assertEquals("20051432T-1-1-1UTC(-2,-2,-2,-2,1141426739)", r);
 
-        Fields.assertTimeEquals(t, tCopy);
+        Fields.verifyTimeEquals(t, tCopy);
     }
 
-    public void testGetCurrentTimezone() throws Exception {
+    @Test
+    public void testGetCurrentTimezone() {
         String r = Time.getCurrentTimezone();
         assertEquals(TimeZone.getDefault().getID(), r);
     }
 
-    public void testSetToNow() throws Exception {
+    @Test
+    public void testSetToNow() {
         Time t = new Time(Time.TIMEZONE_UTC);
 
         // Time works in seconds so all millis values have to be divided by 1000, otherwise
@@ -1228,7 +1263,8 @@
         assertTrue(lowerBound <= actual && actual <= upperBound);
     }
 
-    public void testToMillis_utc() throws Exception {
+    @Test
+    public void testToMillis_utc() {
         Time t = new Time(Time.TIMEZONE_UTC);
 
         long winterTimeUtcMillis = 1167613323000L;
@@ -1284,7 +1320,8 @@
         assertEquals(summerTimeUtcMillis, r);
     }
 
-    public void testToMillis_dstTz() throws Exception {
+    @Test
+    public void testToMillis_dstTz() {
         Time t = new Time(PstPdt.ID);
 
         // A STD time
@@ -1296,68 +1333,71 @@
         assertEquals(stdTimeMillis, r);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(true, t, stdTimeMillis);
+        verifyToMillisResult(true, t, stdTimeMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(true, t, stdTimeMillis);
+        verifyToMillisResult(true, t, stdTimeMillis);
 
         long dstToStdCorrectionMillis =
                 PstPdt.getUtcOffsetMillis(false) - PstPdt.getUtcOffsetMillis(true);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, stdTimeMillis);
+        verifyToMillisResult(false, t, stdTimeMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, stdTimeMillis + dstToStdCorrectionMillis);
+        verifyToMillisResult(false, t, stdTimeMillis + dstToStdCorrectionMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, stdTimeMillis);
+        verifyToMillisResult(false, t, stdTimeMillis);
 
         // A DST time
         long dstTimeUtcMillis = 1180659723000L;
         long dstTimeMillis = dstTimeUtcMillis - PstPdt.getUtcOffsetMillis(true);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
-        assertToMillisResult(true, t, dstTimeMillis);
+        verifyToMillisResult(true, t, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(true, t, dstTimeMillis);
+        verifyToMillisResult(true, t, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(true, t, dstTimeMillis);
+        verifyToMillisResult(true, t, dstTimeMillis);
 
         long stdToDstCorrectionMillis = -dstToStdCorrectionMillis;
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, dstTimeMillis + stdToDstCorrectionMillis);
+        verifyToMillisResult(false, t, dstTimeMillis + stdToDstCorrectionMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, dstTimeMillis);
+        verifyToMillisResult(false, t, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
-        assertToMillisResult(false, t, dstTimeMillis);
+        verifyToMillisResult(false, t, dstTimeMillis);
     }
 
-    private static void assertToMillisResult(boolean toMillisArgument, Time t, long expectedResult) {
+    private static void verifyToMillisResult(boolean toMillisArgument, Time t,
+            long expectedResult) {
         long r = t.toMillis(toMillisArgument /* ignore isDst */);
         assertEquals(expectedResult, r);
     }
 
+    @Test
     public void testToMillis_doesNotNormalize() {
         Time t = new Time(Time.TIMEZONE_UTC);
 
         Fields.set(t, 2007, 13, 32, 25, 60, 60, -2 /* isDst */, Integer.MAX_VALUE, 367, 7);
 
         Time originalTime = new Time(t);
-        Fields.assertTimeEquals(t, originalTime);
+        Fields.verifyTimeEquals(t, originalTime);
 
         t.toMillis(true);
-        Fields.assertTimeEquals(originalTime, t);
+        Fields.verifyTimeEquals(originalTime, t);
 
         t.toMillis(false);
-        Fields.assertTimeEquals(originalTime, t);
+        Fields.verifyTimeEquals(originalTime, t);
     }
 
+    @Test
     public void testToMillis_skippedTime() {
         // Tests behavior around a transition from STD to DST that introduces an hour of "skipped"
         // time from 01:00 to 01:59.
@@ -1383,13 +1423,13 @@
             } else {
                 expectedTimeMillis = -1;
             }
-            assertToMillisResult(true, time, expectedTimeMillis);
+            verifyToMillisResult(true, time, expectedTimeMillis);
 
             // isDst = 0, toMillis(false)
             Fields.set(time, timeFields);
             time.isDst = 0;
             expectedTimeMillis = stdBaseTimeMillis + minutesInMillis;
-            assertToMillisResult(false, time, expectedTimeMillis);
+            verifyToMillisResult(false, time, expectedTimeMillis);
 
             // isDst = 1, toMillis(true)
             Fields.set(time, timeFields);
@@ -1401,13 +1441,13 @@
             } else {
                 expectedTimeMillis = -1;
             }
-            assertToMillisResult(true, time, expectedTimeMillis);
+            verifyToMillisResult(true, time, expectedTimeMillis);
 
             // isDst = 1, toMillis(false)
             Fields.set(time, timeFields);
             time.isDst = 1;
             expectedTimeMillis = dstBaseTimeMillis + minutesInMillis;
-            assertToMillisResult(false, time, expectedTimeMillis);
+            verifyToMillisResult(false, time, expectedTimeMillis);
 
             // isDst = -1, toMillis(true)
             Fields.set(time, timeFields);
@@ -1420,15 +1460,16 @@
             } else {
                 expectedTimeMillis = -1;
             }
-            assertToMillisResult(false, time, expectedTimeMillis);
+            verifyToMillisResult(false, time, expectedTimeMillis);
 
             // isDst = -1, toMillis(false)
             Fields.set(time, timeFields);
             time.isDst = -1;
-            assertToMillisResult(false, time, expectedTimeMillis);
+            verifyToMillisResult(false, time, expectedTimeMillis);
         }
     }
 
+    @Test
     public void testToMillis_duplicateWallTime() {
         // 1:00 in standard / 2:00 in DST
         long timeBaseMillis = 1194163200000L;
@@ -1460,7 +1501,7 @@
             // isDst = 0, toMillis(false)
             Fields.set(time, timeFields);
             time.isDst = 0;
-            assertToMillisResult(false, time,
+            verifyToMillisResult(false, time,
                     timeBaseMillis + minutesInMillis + dstCorrectionMillis);
 
             // isDst = 1, toMillis(true)
@@ -1481,7 +1522,7 @@
             // isDst = 1, toMillis(false)
             Fields.set(time, timeFields);
             time.isDst = 1;
-            assertToMillisResult(false, time, timeBaseMillis + minutesInMillis);
+            verifyToMillisResult(false, time, timeBaseMillis + minutesInMillis);
 
             // isDst = -1, toMillis(true)
             Fields.set(time, timeFields);
@@ -1517,59 +1558,63 @@
         }
     }
 
+    @Test
     public void testToMillis_beforeTzRecords() {
         int[] timeFields = new int[] { 1900, 0, 1, 2, 3, 4, -999 /* not used */, 9, 9, 9 };
-        assertToMillisInvalid(timeFields, PstPdt.ID);
-        assertToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyToMillisInvalid(timeFields, PstPdt.ID);
+        verifyToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
-    private static void assertToMillisInvalid(int[] timeFields, String timezone) {
+    private static void verifyToMillisInvalid(int[] timeFields, String timezone) {
         Time time = new Time(timezone);
 
         // isDst = 0, toMillis(true)
         Fields.set(time, timeFields);
         time.isDst = 0;
-        assertToMillisResult(true, time, -1);
+        verifyToMillisResult(true, time, -1);
 
         // isDst = 0, toMillis(false)
         Fields.set(time, timeFields);
         time.isDst = 0;
-        assertToMillisResult(false, time, -1);
+        verifyToMillisResult(false, time, -1);
 
         // isDst = 1, toMillis(true)
         Fields.set(time, timeFields);
         time.isDst = 1;
-        assertToMillisResult(true, time, -1);
+        verifyToMillisResult(true, time, -1);
 
         // isDst = 1, toMillis(false)
         Fields.set(time, timeFields);
         time.isDst = 1;
-        assertToMillisResult(false, time, -1);
+        verifyToMillisResult(false, time, -1);
 
         // isDst = -1, toMillis(true)
         Fields.set(time, timeFields);
         time.isDst = -1;
-        assertToMillisResult(true, time, -1);
+        verifyToMillisResult(true, time, -1);
 
         // isDst = -1, toMillis(false)
         Fields.set(time, timeFields);
         time.isDst = -1;
-        assertToMillisResult(false, time, -1);
+        verifyToMillisResult(false, time, -1);
     }
 
+    @Test
     public void testToMillis_afterTzRecords() {
         int[] timeFields = new int[] { 2039, 0, 1, 2, 3, 4, -999 /* not used */, 9, 9, 9 };
-        assertToMillisInvalid(timeFields, PstPdt.ID);
-        assertToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyToMillisInvalid(timeFields, PstPdt.ID);
+        verifyToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
+    @Test
     public void testToMillis_invalid() {
         int[] timeFields = new int[] { 0, 0, 0, 0, 0, 0, -999 /* not used */, 9, 9, 9 };
-        assertToMillisInvalid(timeFields, PstPdt.ID);
-        assertToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyToMillisInvalid(timeFields, PstPdt.ID);
+        verifyToMillisInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
-    public void testParse_date() throws Exception {
+    @Test
+    public void testParse_date() {
         String nonUtcTz = PstPdt.ID;
         Time t = new Time(nonUtcTz);
         assertFalse(t.parse("12345678"));
@@ -1577,80 +1622,78 @@
         Fields.setAllDayDate(expected, 1234, 55, 78);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testParse_null() throws Exception {
+    @Test(expected=NullPointerException.class)
+    public void testParse_null() {
         Time t = new Time(Time.TIMEZONE_UTC);
-        try {
-            t.parse(null);
-            fail();
-        } catch (NullPointerException e) {
-        }
+        t.parse(null);
     }
 
-    public void testParse() throws Exception {
+    @Test
+    public void testParse() {
         Time t = new Time(Time.TIMEZONE_UTC);
         t.parse("20061005T120000");
 
         Time expected = new Time(Time.TIMEZONE_UTC);
         Fields.set(expected, 2006, 9, 5, 12, 0, 0, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testParse_dateTime() throws Exception {
+    @Test
+    public void testParse_dateTime() {
         String nonUtcTz = PstPdt.ID;
         Time t = new Time(nonUtcTz);
         assertFalse(t.parse("12345678T901234"));
         Time expected = new Time(nonUtcTz);
         Fields.set(expected, 1234, 55, 78, 90, 12, 34, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         Time t2 = new Time(nonUtcTz);
         assertTrue(t2.parse("12345678T901234Z"));
         Time utcExpected = new Time(Time.TIMEZONE_UTC);
         Fields.set(utcExpected, 1234, 55, 78, 90, 12, 34, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(utcExpected, t2);
+        Fields.verifyTimeEquals(utcExpected, t2);
     }
 
-    public void testParse_errors() throws Exception {
-        String nonUtcTz = PstPdt.ID;
-        try {
-            Time t = new Time(nonUtcTz);
-            t.parse(null);
-            fail();
-        } catch (NullPointerException e) {
-        }
+    @Test(expected=NullPointerException.class)
+    public void testParse_pstPdtNull() {
+        Time t = new Time(PstPdt.ID);
+        t.parse(null);
+    }
 
+    @Test
+    public void testParse_errors() {
         // Too short
-        assertParseError("");
-        assertParseError("1");
-        assertParseError("12");
-        assertParseError("123");
-        assertParseError("1234");
-        assertParseError("12345");
-        assertParseError("123456");
-        assertParseError("1234567");
+        verifyParseError("");
+        verifyParseError("1");
+        verifyParseError("12");
+        verifyParseError("123");
+        verifyParseError("1234");
+        verifyParseError("12345");
+        verifyParseError("123456");
+        verifyParseError("1234567");
 
         // No "T" in the expected place
-        assertParseError("12345678S");
+        verifyParseError("12345678S");
 
         // Invalid character in the first 8 characters.
-        assertParseError("12X45678");
+        verifyParseError("12X45678");
 
         // Too short for a date/time (15 or 16 characters allowed)
-        assertParseError("12345678T");
-        assertParseError("12345678T0");
-        assertParseError("12345678T01");
-        assertParseError("12345678T012");
-        assertParseError("12345678T0123");
-        assertParseError("12345678T01234");
+        verifyParseError("12345678T");
+        verifyParseError("12345678T0");
+        verifyParseError("12345678T01");
+        verifyParseError("12345678T012");
+        verifyParseError("12345678T0123");
+        verifyParseError("12345678T01234");
 
         // Invalid character
-        assertParseError("12345678T0X2345");
+        verifyParseError("12345678T0X2345");
     }
 
-    private static void assertParseError(String s) {
+    private static void verifyParseError(String s) {
         Time t = new Time(Time.TIMEZONE_UTC);
         try {
             t.parse(s);
@@ -1659,77 +1702,76 @@
         }
     }
 
-    public void testParse3339() throws Exception {
+    @Test
+    public void testParse3339() {
         String tz = Time.TIMEZONE_UTC;
         Time expected = new Time(tz);
         Fields.setAllDayDate(expected, 1980, 4, 23);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23", expected);
 
         Fields.setDateTime(expected, 1980, 4, 23, 9, 50, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50", expected);
 
         Fields.setDateTime(expected, 1980, 4, 23, 9, 50, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50Z", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50Z", expected);
 
         Fields.setDateTime(expected, 1980, 4, 23, 9, 50, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50.0Z", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50.0Z", expected);
 
         Fields.setDateTime(expected, 1980, 4, 23, 9, 50, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50.12Z", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50.12Z", expected);
 
         Fields.setDateTime(expected, 1980, 4, 23, 9, 50, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50.123Z", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50.123Z", expected);
 
         // The time should be normalized to UTC
         Fields.setDateTime(expected, 1980, 4, 23, 10, 55, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50-01:05", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50-01:05", expected);
 
         // The time should be normalized to UTC
         Fields.setDateTime(expected, 1980, 4, 23, 10, 55, 50);
         Fields.setDst(expected, -1 /* isDst */, 0);
         Fields.setDerivedDateTime(expected, 0, 0);
-        assertParse3339Succeeds(tz, "1980-05-23T09:50:50.123-01:05", expected);
+        verifyParse3339Succeeds(tz, "1980-05-23T09:50:50.123-01:05", expected);
     }
 
-    private static void assertParse3339Succeeds(String timeZone, String toParse, Time expected) {
+    private static void verifyParse3339Succeeds(String timeZone, String toParse, Time expected) {
         Time t = new Time(timeZone);
         t.parse3339(toParse);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
+    @Test
     public void testParse3339_parseErrors() {
         // Too short
-        assertParse3339Error("1980");
+        verifyParse3339Error("1980");
 
         // Timezone too short
-        assertParse3339Error("1980-05-23T09:50:50.123+");
-        assertParse3339Error("1980-05-23T09:50:50.123+05:0");
+        verifyParse3339Error("1980-05-23T09:50:50.123+");
+        verifyParse3339Error("1980-05-23T09:50:50.123+05:0");
     }
 
+    @Test(expected=NullPointerException.class)
     public void testParse3339_null() {
         Time t = new Time(Time.TIMEZONE_UTC);
-        try {
-            t.parse3339(null);
-            fail();
-        } catch (NullPointerException e) {
-        }
+        t.parse3339(null);
     }
 
-    private void assertParse3339Error(String s) {
+    private void verifyParse3339Error(String s) {
         String tz = Time.TIMEZONE_UTC;
         Time t = new Time(tz);
         try {
@@ -1739,29 +1781,31 @@
         }
     }
 
-    public void testSetMillis_utc() throws Exception {
+    @Test
+    public void testSetMillis_utc() {
         String tz = Time.TIMEZONE_UTC;
         Time t = new Time(tz);
         t.set(1000L);
 
         Time expected = new Time(tz);
         Fields.set(expected, 1970, 0, 1, 0, 0, 1, 0 /* isDst */, 0, 0, 4);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         t.set(2000L);
         Fields.set(expected, 1970, 0, 1, 0, 0, 2, 0 /* isDst */, 0, 0, 4);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         t.set(1000L * 60);
         Fields.set(expected, 1970, 0, 1, 0, 1, 0, 0 /* isDst */, 0, 0, 4);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         t.set((1000L * 60 * 60 * 24) + 1000L);
         Fields.set(expected, 1970, 0, 2, 0, 0, 1, 0 /* isDst */, 0, 1, 5);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testSetMillis_utc_edgeCases() throws Exception {
+    @Test
+    public void testSetMillis_utc_edgeCases() {
         String tz = Time.TIMEZONE_UTC;
         Time t = new Time(tz);
         t.set(Integer.MAX_VALUE + 1L);
@@ -1769,16 +1813,17 @@
         Time expected = new Time(tz);
         // This a 32-bit int overflow bug.
         Fields.set(expected, 1970, 0, 25, 20, 31, 23, 0 /* isDst */, 0, 24, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         t = new Time(tz);
         t.set(Integer.MIN_VALUE - 1L);
         // This a 32-bit int underflow bug.
         Fields.set(expected, 1969, 11, 7, 3, 28, 37, 0 /* isDst */, 0, 340, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    public void testSetFields() throws Exception {
+    @Test
+    public void testSetFields() {
         String tz = Time.TIMEZONE_UTC;
         Time t = new Time(tz);
         Fields.set(t, 9, 9, 9, 9, 9, 9, 9 /* isDst */, 9, 9, 9);
@@ -1787,7 +1832,7 @@
 
         Time expected = new Time(tz);
         Fields.set(expected, 6, 5, 4, 3, 2, 1, -1 /* isDst */, 0, 0, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
     // Timezones that cover the world.  Some GMT offsets occur more than
@@ -1854,7 +1899,8 @@
         "Pacific/Midway",
     };
 
-    public void testGetJulianDay() throws Exception {
+    @Test
+    public void testGetJulianDay() {
         Time time = new Time();
 
         // For every 15th day of 2008, and for each of the timezones listed above,
@@ -1901,7 +1947,8 @@
         }
     }
 
-    public void testSetJulianDay() throws Exception {
+    @Test
+    public void testSetJulianDay() {
         Time time = new Time();
 
         // For each day of the year in 2008, and for each timezone,
@@ -1947,7 +1994,8 @@
         }
     }
 
-    public void testNormalize_utc() throws Exception {
+    @Test
+    public void testNormalize_utc() {
         Time t = new Time(Time.TIMEZONE_UTC);
         Time expected = new Time(Time.TIMEZONE_UTC);
 
@@ -1955,56 +2003,57 @@
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 0, 0, 1);
-        assertNormalizeResult(true, t, expected, winterTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, winterTimeUtcMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 0, 0, 1);
-        assertNormalizeResult(true, t, expected, winterTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, winterTimeUtcMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 0, 0, 1);
-        assertNormalizeResult(true, t, expected, winterTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, winterTimeUtcMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 0, 0, 1);
-        assertNormalizeResult(false, t, expected, winterTimeUtcMillis);
+        verifyNormalizeResult(false, t, expected, winterTimeUtcMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 0, 0, 1);
-        assertNormalizeResult(false, t, expected, winterTimeUtcMillis);
+        verifyNormalizeResult(false, t, expected, winterTimeUtcMillis);
 
         long summerTimeUtcMillis = 1180659723000L;
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        assertNormalizeResult(true, t, expected, summerTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, summerTimeUtcMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        assertNormalizeResult(true, t, expected, summerTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, summerTimeUtcMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        assertNormalizeResult(true, t, expected, summerTimeUtcMillis);
+        verifyNormalizeResult(true, t, expected, summerTimeUtcMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        assertNormalizeResult(false, t, expected, summerTimeUtcMillis);
+        verifyNormalizeResult(false, t, expected, summerTimeUtcMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, 1, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        assertNormalizeResult(false, t, expected, summerTimeUtcMillis);
+        verifyNormalizeResult(false, t, expected, summerTimeUtcMillis);
     }
 
-    public void testNormalize_dstTz() throws Exception {
+    @Test
+    public void testNormalize_dstTz() {
         Time t = new Time(PstPdt.ID);
         Time expected = new Time(PstPdt.ID);
 
@@ -2014,30 +2063,30 @@
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(true, t, expected, stdTimeMillis);
+        verifyNormalizeResult(true, t, expected, stdTimeMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(true, t, expected, stdTimeMillis);
+        verifyNormalizeResult(true, t, expected, stdTimeMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(true, t, expected, stdTimeMillis);
+        verifyNormalizeResult(true, t, expected, stdTimeMillis);
 
         long dstToStdCorrectionMillis =
                 PstPdt.getUtcOffsetMillis(false) - PstPdt.getUtcOffsetMillis(true);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(false, t, expected, stdTimeMillis);
+        verifyNormalizeResult(false, t, expected, stdTimeMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 0, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(false, t, expected, stdTimeMillis + dstToStdCorrectionMillis);
+        verifyNormalizeResult(false, t, expected, stdTimeMillis + dstToStdCorrectionMillis);
 
         Fields.set(t, 2007, 0, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 0, 1, 1, 2, 3, 0 /* isDst */, -28800, 0, 1);
-        assertNormalizeResult(false, t, expected, stdTimeMillis);
+        verifyNormalizeResult(false, t, expected, stdTimeMillis);
 
         // A DST time
         long dstTimeUtcMillis = 1180659723000L;
@@ -2045,31 +2094,32 @@
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(true, t, expected, dstTimeMillis);
+        verifyNormalizeResult(true, t, expected, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(true, t, expected, dstTimeMillis);
+        verifyNormalizeResult(true, t, expected, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(true, t, expected, dstTimeMillis);
+        verifyNormalizeResult(true, t, expected, dstTimeMillis);
 
         long stdToDstCorrectionMillis = -dstToStdCorrectionMillis;
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2007, 5, 1, 2, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(false, t, expected, dstTimeMillis + stdToDstCorrectionMillis);
+        verifyNormalizeResult(false, t, expected, dstTimeMillis + stdToDstCorrectionMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(false, t, expected, dstTimeMillis);
+        verifyNormalizeResult(false, t, expected, dstTimeMillis);
 
         Fields.set(t, 2007, 5, 1, 1, 2, 3, -1 /* isDst */, -25200, 151, 5);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 1 /* isDst */, -25200, 151, 5);
-        assertNormalizeResult(false, t, expected, dstTimeMillis);
+        verifyNormalizeResult(false, t, expected, dstTimeMillis);
     }
 
+    @Test
     public void testNormalize_skippedTime() {
         // Tests behavior around a transition from STD to DST that introduces an hour of "skipped"
         // time from 01:00 to 01:59.
@@ -2126,7 +2176,7 @@
                 Fields.setDerivedDateTime(expected, 9, 9);
             }
             assertEquals("i = " + i, expectedTimeMillis, timeMillis);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 0, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2144,7 +2194,7 @@
                 Fields.setDst(expected, 1, PstPdt.getUtcOffsetSeconds(1));
             }
             Fields.setDerivedDateTime(expected, 69, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 1, normalize(true)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2169,7 +2219,7 @@
                 Fields.setDerivedDateTime(expected, 9, 9);
             }
             assertEquals("i = " + i, expectedTimeMillis, timeMillis);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 1, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2187,7 +2237,7 @@
                 Fields.setDst(expected, 0, PstPdt.getUtcOffsetSeconds(0));
             }
             Fields.setDerivedDateTime(expected, 69, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = -1, normalize(true)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2212,7 +2262,7 @@
                 Fields.setDerivedDateTime(expected, 9, 9);
             }
             assertEquals("i = " + i, expectedTimeMillis, timeMillis);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = -1, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2237,10 +2287,11 @@
                 Fields.setDerivedDateTime(expected, 9, 9);
             }
             assertEquals("i = " + i, expectedTimeMillis, timeMillis);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
         }
     }
 
+    @Test
     public void testNormalize_duplicateWallTime() {
         // 1:00 in standard / 2:00 in DST
         long timeBaseMillis = 1194163200000L;
@@ -2293,7 +2344,7 @@
                 fail("i =" + i);
             }
             Fields.setDerivedDateTime(expected, 307, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 0, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2311,7 +2362,7 @@
                 Fields.setDst(expected, 0 /* isDst */, PstPdt.getUtcOffsetSeconds(0));
             }
             Fields.setDerivedDateTime(expected, 307, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 1, normalize(true)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2334,7 +2385,7 @@
                 fail("i =" + i);
             }
             Fields.setDerivedDateTime(expected, 307, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = 1, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2352,7 +2403,7 @@
             }
             Fields.setDerivedDateTime(expected, 307, 0);
             assertEquals("i = " + i, expectedTimeMillis, timeMillis);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = -1, normalize(true)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2375,7 +2426,7 @@
                 fail("i =" + i);
             }
             Fields.setDerivedDateTime(expected, 307, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
 
             // isDst = -1, normalize(false)
             Fields.setDateTime(time, dateTimeArgs);
@@ -2397,17 +2448,18 @@
                 fail("i =" + i);
             }
             Fields.setDerivedDateTime(expected, 307, 0);
-            Fields.assertTimeEquals("i = " + i, expected, time);
+            Fields.verifyTimeEquals("i = " + i, expected, time);
         }
     }
 
+    @Test
     public void testNormalize_beforeTzRecords() {
         int[] timeFields = new int[] { 1900, 0, 1, 2, 3, 4, -999 /* not used */, 9, 9, 9 };
-        assertNormalizeInvalid(timeFields, PstPdt.ID);
-        assertNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyNormalizeInvalid(timeFields, PstPdt.ID);
+        verifyNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
-    private static void assertNormalizeInvalid(int[] timeFields, String timezone) {
+    private static void verifyNormalizeInvalid(int[] timeFields, String timezone) {
         Time time = new Time(timezone);
         Time expected = new Time(timezone);
 
@@ -2416,56 +2468,59 @@
         time.isDst = 0;
         Fields.set(expected, timeFields);
         expected.isDst = -1;
-        assertNormalizeResult(true, time, expected, -1);
+        verifyNormalizeResult(true, time, expected, -1);
 
         // isDst = 0, normalize(false)
         Fields.set(time, timeFields);
         time.isDst = 0;
         Fields.set(expected, timeFields);
         expected.isDst = 0;
-        assertNormalizeResult(false, time, expected, -1);
+        verifyNormalizeResult(false, time, expected, -1);
 
         // isDst = 1, normalize(true)
         Fields.set(time, timeFields);
         time.isDst = 1;
         Fields.set(expected, timeFields);
         expected.isDst = -1;
-        assertNormalizeResult(true, time, expected, -1);
+        verifyNormalizeResult(true, time, expected, -1);
 
         // isDst = 1, normalize(false)
         Fields.set(time, timeFields);
         time.isDst = 1;
         Fields.set(expected, timeFields);
         expected.isDst = 1;
-        assertNormalizeResult(false, time, expected, -1);
+        verifyNormalizeResult(false, time, expected, -1);
 
         // isDst = -1, normalize(true)
         Fields.set(time, timeFields);
         time.isDst = -1;
         Fields.set(expected, timeFields);
         expected.isDst = -1;
-        assertNormalizeResult(true, time, expected, -1);
+        verifyNormalizeResult(true, time, expected, -1);
 
         // isDst = -1, normalize(false)
         Fields.set(time, timeFields);
         time.isDst = -1;
         Fields.set(expected, timeFields);
         expected.isDst = -1;
-        assertNormalizeResult(false, time, expected, -1);
+        verifyNormalizeResult(false, time, expected, -1);
     }
 
+    @Test
     public void testNormalize_afterTzRecords() {
         int[] timeFields = new int[] { 2039, 0, 1, 2, 3, 4, -999 /* not used */, 9, 9, 9 };
-        assertNormalizeInvalid(timeFields, PstPdt.ID);
-        assertNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyNormalizeInvalid(timeFields, PstPdt.ID);
+        verifyNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
+    @Test
     public void testNormalize_invalid() {
         int[] timeFields = new int[] { 0, 0, 0, 0, 0, 0, -999 /* not used */, 9, 9, 9 };
-        assertNormalizeInvalid(timeFields, PstPdt.ID);
-        assertNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
+        verifyNormalizeInvalid(timeFields, PstPdt.ID);
+        verifyNormalizeInvalid(timeFields, Time.TIMEZONE_UTC);
     }
 
+    @Test
     public void testNormalize_dstToDstSkip() {
         // In London, 4th May 1941 02:00 - 03:00 was a skip from DST -> DST (+1 hour -> +2 hours)
         String timezone = "Europe/London";
@@ -2475,22 +2530,22 @@
         // Demonstrate the data we expect either side of the skipped interval: 01:59
         Fields.set(t, 1941, 4, 4, 1, 59, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 4, 4, 1, 59, 0, 1 /* isDst */, 3600, 123, 0);
-        assertNormalizeResult(true, t, expected, -904518060000L);
+        verifyNormalizeResult(true, t, expected, -904518060000L);
 
         // Demonstrate the data we expect either side of the skipped interval: 03:00
         Fields.set(t, 1941, 4, 4, 3, 0, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 4, 4, 3, 0, 0, 1 /* isDst */, 7200, 123, 0);
-        assertNormalizeResult(true, t, expected, -904518000000L);
+        verifyNormalizeResult(true, t, expected, -904518000000L);
 
         // isDst = 1, normalize(false)
         Fields.set(t, 1941, 4, 4, 2, 30, 0, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 4, 4, 2, 30, 0, 1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         // isDst = -1, normalize(false)
         Fields.set(t, 1941, 4, 4, 2, 30, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 4, 4, 2, 30, 0, -1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         // The results below are potentially arbitrary: 01:30 and 02:30 are not a valid standard
         // times so normalize() must apply one of the possible STD -> DST adjustments to arrive at a
@@ -2499,7 +2554,7 @@
         // isDst = 0, normalize(false) @ 01:30
         Fields.set(t, 1941, 4, 4, 1, 30, 0, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 4, 4, 3, 30, 0, 1 /* isDst */, 7200, 123, 0);
-        assertNormalizeResult(false, t, expected, -904516200000L);
+        verifyNormalizeResult(false, t, expected, -904516200000L);
 
         // isDst = 0, normalize(false) @ 02:30
         Fields.set(t, 1941, 4, 4, 2, 30, 0, 0 /* isDst */, 9, 9, 9);
@@ -2513,9 +2568,10 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
+    @Test
     public void testNormalize_dstToDstRepeat() {
         // In London, 10th August 1941 02:00 - 03:00 was a repeat from DST -> DST
         // (+2 hour -> +1 hour)
@@ -2526,24 +2582,24 @@
         // Demonstrate the data we expect during the repeated interval: 02:30 (first)
         t.set(-896052600000L);
         Fields.set(expected, 1941, 7, 10, 2, 30, 0, 1 /* isDst */, 7200, 221, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // Demonstrate the data we expect during the repeated interval: 02:30 (second)
         t.set(-896049000000L);
         Fields.set(expected, 1941, 7, 10, 2, 30, 0, 1 /* isDst */, 3600, 221, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // Now check times in the repeated hour with different isDst assertions...
 
         // isDst = 1, normalize(false) @ 02:30
         Fields.set(t, 1941, 7, 10, 2, 30, 0, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 7, 10, 2, 30, 0, 1 /* isDst */, 3600, 221, 0);
-        assertNormalizeResult(false, t, expected, -896049000000L);
+        verifyNormalizeResult(false, t, expected, -896049000000L);
 
         // isDst = -1, normalize(false) @ 02:30
         Fields.set(t, 1941, 7, 10, 2, 30, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 7, 10, 2, 30, 0, 1 /* isDst */, 3600, 221, 0);
-        assertNormalizeResult(false, t, expected, -896049000000L);
+        verifyNormalizeResult(false, t, expected, -896049000000L);
 
         // The results below are potentially arbitrary: 01:30 and 02:30 are not a valid standard
         // times so normalize() must apply one of the possible STD -> DST adjustments to arrive at a
@@ -2560,14 +2616,15 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // isDst = 0, normalize(false) @ 02:30
         Fields.set(t, 1941, 7, 10, 2, 30, 0, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1941, 7, 10, 3, 30, 0, 1 /* isDst */, 3600, 221, 0);
-        assertNormalizeResult(false, t, expected, -896045400000L);
+        verifyNormalizeResult(false, t, expected, -896045400000L);
     }
 
+    @Test
     public void testNormalize_stdToStdRepeat() {
         // In London, 31st October 1971 02:00 - 03:00 was a repeat from STD -> STD
         String timezone = "Europe/London";
@@ -2577,12 +2634,12 @@
         // Demonstrate the data we expect during the repeated interval: 02:30 (first)
         t.set(57720600000L);
         Fields.set(expected, 1971, 9, 31, 2, 30, 0, 0 /* isDst */, 3600, 303, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // Demonstrate the data we expect during the repeated interval: 02:30 (second)
         t.set(57724200000L);
         Fields.set(expected, 1971, 9, 31, 2, 30, 0, 0 /* isDst */, 0, 303, 0);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // isDst = 0, normalize(false) @ 02:30
         Fields.set(t, 1971, 9, 31, 2, 30, 0, 0 /* isDst */, 9, 9, 9);
@@ -2598,7 +2655,7 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // isDst = -1, normalize(false) @ 02:30
         Fields.set(t, 1971, 9, 31, 2, 30, 0, -1 /* isDst */, 9, 9, 9);
@@ -2615,7 +2672,7 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // The results below are potentially arbitrary: 01:30 and 02:30 are not a valid DST
         // so normalize() must apply one of the possible STD -> DST adjustments to arrive at a
@@ -2634,7 +2691,7 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // isDst = 1, normalize(false) @ 02:30
         Fields.set(t, 1971, 9, 31, 2, 30, 0, 1 /* isDst */, 9, 9, 9);
@@ -2647,14 +2704,15 @@
         } else {
             fail();
         }
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
 
         // isDst = 1, normalize(false) @ 03:30
         Fields.set(t, 1971, 9, 31, 3, 30, 0, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1971, 9, 31, 2, 30, 0, 0 /* isDst */, 0, 303, 0);
-        assertNormalizeResult(false, t, expected, 57724200000L);
+        verifyNormalizeResult(false, t, expected, 57724200000L);
     }
 
+    @Test
     public void testNormalize_stdToStdSkip() {
         // In Kiritimati, 1st Jan 1995 10:00 - 10:40 was a skip from STD -> STD (plus they do not
         // observe DST).
@@ -2665,19 +2723,20 @@
         // isDst = 0, normalize(false)
         Fields.set(t, 1995, 0, 1, 10, 20, 0, 0 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1995, 0, 1, 10, 20, 0, 0 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         // isDst = 1, normalize(false)
         Fields.set(t, 1995, 0, 1, 10, 20, 0, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1995, 0, 1, 10, 20, 0, 1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         // isDst = -1, normalize(false)
         Fields.set(t, 1995, 0, 1, 10, 20, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 1995, 0, 1, 10, 20, 0, -1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
     }
 
+    @Test
     public void testNormalize_utcWithDst() {
         // In UTC (or other zone without DST), what happens when a DST time is specified and there
         // is no DST offset available in the timezone data.
@@ -2687,14 +2746,15 @@
         // isDst = 1, normalize(false)
         Fields.set(t, 2005, 6, 22, 1, 30, 0, 1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2005, 6, 22, 1, 30, 0, 1 /* isDst */, 9, 9, 9);
-        assertNormalizeResult(false, t, expected, -1);
+        verifyNormalizeResult(false, t, expected, -1);
 
         // isDst = -1, normalize(false)
         Fields.set(t, 2005, 6, 22, 1, 30, 0, -1 /* isDst */, 9, 9, 9);
         Fields.set(expected, 2005, 6, 22, 1, 30, 0, 0 /* isDst */, 0, 202, 5);
-        assertNormalizeResult(false, t, expected, 1121995800000L);
+        verifyNormalizeResult(false, t, expected, 1121995800000L);
     }
 
+    @Test
     public void testUnknownTz() {
         // Historically the code used UTC if the timezone is unrecognized.
 
@@ -2712,14 +2772,14 @@
 
         Time expected = new Time(unknownTimezoneId);
         Fields.set(expected, 2007, 5, 1, 1, 2, 3, 0 /* isDst */, 0, 151, 5);
-        Fields.assertTimeEquals(expected, t);
+        Fields.verifyTimeEquals(expected, t);
     }
 
-    private static void assertNormalizeResult(boolean normalizeArgument, Time toNormalize,
+    private static void verifyNormalizeResult(boolean normalizeArgument, Time toNormalize,
             Time expectedTime, long expectedTimeMillis) {
         long actualTimeMillis = toNormalize.normalize(normalizeArgument /* ignore isDst */);
         assertEquals(expectedTimeMillis, actualTimeMillis);
-        Fields.assertTimeEquals(expectedTime, toNormalize);
+        Fields.verifyTimeEquals(expectedTime, toNormalize);
     }
 
     /** A helper class for manipulating / testing fields on Time objects. */
@@ -2730,19 +2790,15 @@
 
         final static int ALL = MAIN_DATE_TIME | DST_FIELDS | DERIVED_DATE_TIME;
 
-        public static void assertTimeEquals(Time expected, Time actual) {
-            assertTimeEquals("", ALL, expected, actual);
+        public static void verifyTimeEquals(Time expected, Time actual) {
+            verifyTimeEquals("", ALL, expected, actual);
         }
 
-        public static void assertTimeEquals(int fields, Time expected, Time actual) {
-            assertTimeEquals("", fields, expected, actual);
+        public static void verifyTimeEquals(String message, Time expected, Time actual) {
+            verifyTimeEquals(message, Fields.ALL, expected, actual);
         }
 
-        public static void assertTimeEquals(String message, Time expected, Time actual) {
-            assertTimeEquals(message, Fields.ALL, expected, actual);
-        }
-
-        public static void assertTimeEquals(String message, int fields, Time expected,
+        public static void verifyTimeEquals(String message, int fields, Time expected,
                 Time actual) {
             boolean mainDateTimeOk = (fields & Fields.MAIN_DATE_TIME) == 0
                     || (Objects.equals(expected.timezone, actual.timezone)
@@ -2769,7 +2825,7 @@
         }
 
         private static String timeToString(int fields, Time time) {
-            List<Object> values = new ArrayList<Object>();
+            List<Object> values = new ArrayList<>();
             StringBuilder format = new StringBuilder();
             if ((fields & Fields.MAIN_DATE_TIME) > 0) {
                 format.append("%d-%02d-%02d %02d:%02d:%02d allDay=%b timezone=%s ");
diff --git a/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
index 08c5596..2f84486 100644
--- a/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
@@ -16,10 +16,22 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.cts.util.PollingCheck;
 import android.os.SystemClock;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.Selection;
 import android.text.Spannable;
@@ -35,6 +47,11 @@
 import android.widget.TextView;
 import android.widget.TextView.BufferType;
 
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link ArrowKeyMovementMethod}. The class is an implementation of interface
  * {@link MovementMethod}. The typical usage of {@link MovementMethod} is tested in
@@ -43,7 +60,9 @@
  *
  * @see android.widget.cts.TextViewTest
  */
-public class ArrowKeyMovementMethodTest extends ActivityInstrumentationTestCase2<CtsActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class ArrowKeyMovementMethodTest {
     private static final String THREE_LINES_TEXT = "first line\nsecond line\nlast line";
     private static final int END_OF_ALL_TEXT = THREE_LINES_TEXT.length();
     private static final int END_OF_1ST_LINE = THREE_LINES_TEXT.indexOf('\n');
@@ -51,44 +70,47 @@
     private static final int END_OF_2ND_LINE = THREE_LINES_TEXT.indexOf('\n', START_OF_2ND_LINE);
     private static final int START_OF_3RD_LINE = END_OF_2ND_LINE + 1;
     private static final int SPACE_IN_2ND_LINE = THREE_LINES_TEXT.indexOf(' ', START_OF_2ND_LINE);
+
+    private Instrumentation mInstrumentation;
     private TextView mTextView;
     private ArrowKeyMovementMethod mArrowKeyMovementMethod;
     private Editable mEditable;
     private MyMetaKeyKeyListener mMetaListener;
 
-    public ArrowKeyMovementMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() throws Throwable {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mMetaListener = new MyMetaKeyKeyListener();
         mArrowKeyMovementMethod = new ArrowKeyMovementMethod();
 
-        initTextViewWithNullLayout();
+        mActivityRule.runOnUiThread(() -> {;
+            initTextViewWithNullLayout();
 
-        getInstrumentation().runOnMainSync(() -> {
-            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
+            Activity activity = mActivityRule.getActivity();
+            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                     WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
 
-            getActivity().setContentView(mTextView);
+            activity.setContentView(mTextView);
             mTextView.setFocusable(true);
             mTextView.requestFocus();
         });
-        getInstrumentation().waitForIdleSync();
-        assertNotNull(mTextView.getLayout());
-        assertTrue(mTextView.isFocused());
+        PollingCheck.waitFor(() -> mTextView.isFocused() && (mTextView.getLayout() != null));
     }
 
+    @Test
     public void testConstructor() {
         new ArrowKeyMovementMethod();
     }
 
+    @Test
     public void testCanSelectArbitrarily() {
         assertTrue(new ArrowKeyMovementMethod().canSelectArbitrarily());
     }
 
+    @Test
     public void testGetInstance() {
         MovementMethod method0 = ArrowKeyMovementMethod.getInstance();
         assertNotNull(method0);
@@ -98,6 +120,7 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testOnTakeFocus() throws Throwable {
         /*
          * The following assertions depend on whether the TextView has a layout.
@@ -108,63 +131,64 @@
          * into several steps, setting the content at first, waiting the layout,
          * and checking the assertion at last.
          */
-        assertSelection(-1);
-        runTestOnUiThread(() -> {
+        verifySelection(-1);
+        mActivityRule.runOnUiThread(() -> {
             Selection.removeSelection(mEditable);
             mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_UP);
         });
-        getInstrumentation().waitForIdleSync();
-        assertSelection(END_OF_ALL_TEXT);
+        mInstrumentation.waitForIdleSync();
+        verifySelection(END_OF_ALL_TEXT);
 
-        runTestOnUiThread(() -> {
+        mActivityRule.runOnUiThread(() -> {
             Selection.removeSelection(mEditable);
             mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_LEFT);
         });
-        getInstrumentation().waitForIdleSync();
-        assertSelection(END_OF_ALL_TEXT);
+        mInstrumentation.waitForIdleSync();
+        verifySelection(END_OF_ALL_TEXT);
 
-        runTestOnUiThread(mTextView::setSingleLine);
+        mActivityRule.runOnUiThread(mTextView::setSingleLine);
         // wait until the textView gets layout
-        getInstrumentation().waitForIdleSync();
+        mInstrumentation.waitForIdleSync();
         assertNotNull(mTextView.getLayout());
         assertEquals(1, mTextView.getLayout().getLineCount());
 
-        runTestOnUiThread(() -> {
+        mActivityRule.runOnUiThread(() -> {
             Selection.removeSelection(mEditable);
             mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_UP);
         });
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
-        runTestOnUiThread(() -> {
+        mActivityRule.runOnUiThread(() -> {
             Selection.removeSelection(mEditable);
             mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_LEFT);
         });
-        assertSelection(END_OF_ALL_TEXT);
-    }
-
-    public void testOnTakeFoucusWithNullLayout() {
-        initTextViewWithNullLayout();
-        assertSelectEndOfContent();
-    }
-
-    public void testOnTakeFocusWithNullParameters() {
-        initTextViewWithNullLayout();
-        try {
-            mArrowKeyMovementMethod.onTakeFocus(null, mEditable, View.FOCUS_DOWN);
-            fail("The method did not throw NullPointerException when param textView is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
-
-        try {
-            mArrowKeyMovementMethod.onTakeFocus(mTextView, null, View.FOCUS_DOWN);
-            fail("The method did not throw NullPointerException when param spannable is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
+        verifySelection(END_OF_ALL_TEXT);
     }
 
     @UiThreadTest
+    @Test
+    public void testOnTakeFocusWithNullLayout() {
+        initTextViewWithNullLayout();
+        verifySelectEndOfContent();
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTakeFocusNullView() {
+        // Should throw NullPointerException when param textView is null
+        mArrowKeyMovementMethod.onTakeFocus(null, mEditable, View.FOCUS_DOWN);
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTakeFocusNullSpannable() {
+        initTextViewWithNullLayout();
+        // Should throw NullPointerException when param spannable is null
+        mArrowKeyMovementMethod.onTakeFocus(mTextView, null, View.FOCUS_DOWN);
+    }
+
+    @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeUp() {
         // shift+alt tests
         final KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -180,7 +204,7 @@
         // |first line
         // second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, 0);
+        verifySelection(SPACE_IN_2ND_LINE, 0);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP, 0,
@@ -204,7 +228,7 @@
         // |first line
         // second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, 0);
+        verifySelection(SPACE_IN_2ND_LINE, 0);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP, 0,
@@ -217,7 +241,7 @@
         // |first line
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP,
@@ -230,7 +254,7 @@
         // first lin|e
         // second line
         // last line
-        assertSelection(correspondingIn1stLine);
+        verifySelection(correspondingIn1stLine);
 
         // Move to beginning of first line (behavior changed in L)
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -238,17 +262,18 @@
         // |first line
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
 
         assertFalse(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
                 KeyEvent.KEYCODE_DPAD_UP, noMetaEvent));
         // first lin|e
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeDown() {
         // shift+alt tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -264,7 +289,7 @@
         // first line
         // second |line
         // last line|
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN,
@@ -288,7 +313,7 @@
         // first line
         // second |line
         // last line|
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, 0,
@@ -301,7 +326,7 @@
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN,
@@ -314,7 +339,7 @@
         // first line
         // second line
         // last lin|e
-        assertSelection(correspondingIn3rdLine);
+        verifySelection(correspondingIn3rdLine);
 
         // move to end of last line (behavior changed in L)
         Selection.setSelection(mEditable, END_OF_ALL_TEXT - 1);
@@ -323,17 +348,18 @@
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         assertFalse(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
                 KeyEvent.KEYCODE_DPAD_DOWN, noMetaEvent));
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeLeft() {
         // shift+alt tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -349,7 +375,7 @@
         // first line
         // |second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
 
         pressBothShiftAlt();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -357,7 +383,7 @@
         // first line
         // |second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT,
@@ -370,7 +396,7 @@
         // first line
         // second| |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE - 1);
+        verifySelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE - 1);
 
         pressShift();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -378,7 +404,7 @@
         // first line
         // secon|d |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE - 2);
+        verifySelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE - 2);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT, 0,
@@ -391,7 +417,7 @@
         // first line
         // |second line
         // last line
-        assertSelection(START_OF_2ND_LINE);
+        verifySelection(START_OF_2ND_LINE);
 
         pressAlt();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -399,7 +425,7 @@
         // first line
         // |second line
         // last line
-        assertSelection(START_OF_2ND_LINE);
+        verifySelection(START_OF_2ND_LINE);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT,
@@ -412,7 +438,7 @@
         // first line
         // second| line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE - 1);
+        verifySelection(SPACE_IN_2ND_LINE - 1);
 
         Selection.setSelection(mEditable, START_OF_2ND_LINE);
         // first line
@@ -423,10 +449,11 @@
         // first line|
         // second line
         // last line
-        assertSelection(END_OF_1ST_LINE);
+        verifySelection(END_OF_1ST_LINE);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeRight() {
         // shift+alt tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -442,7 +469,7 @@
         // first line
         // second |line|
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
 
         pressBothShiftAlt();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -450,7 +477,7 @@
         // first line
         // second |line|
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT,
@@ -463,7 +490,7 @@
         // first line
         // second |l|ine
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE + 1);
+        verifySelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE + 1);
 
         pressShift();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -471,7 +498,7 @@
         // first line
         // second |li|ne
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE + 2);
+        verifySelection(SPACE_IN_2ND_LINE, SPACE_IN_2ND_LINE + 2);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT,
@@ -484,7 +511,7 @@
         // first line
         // second line|
         // last line
-        assertSelection(END_OF_2ND_LINE);
+        verifySelection(END_OF_2ND_LINE);
 
         pressAlt();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -492,7 +519,7 @@
         // first line
         // second line|
         // last line
-        assertSelection(END_OF_2ND_LINE);
+        verifySelection(END_OF_2ND_LINE);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -505,7 +532,7 @@
         // first line
         // second l|ine
         // last line
-        assertSelection(SPACE_IN_2ND_LINE + 1);
+        verifySelection(SPACE_IN_2ND_LINE + 1);
 
         Selection.setSelection(mEditable, END_OF_2ND_LINE);
         // first line
@@ -516,10 +543,11 @@
         // first line
         // second line
         // |last line
-        assertSelection(START_OF_3RD_LINE);
+        verifySelection(START_OF_3RD_LINE);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodePageUp() {
         // shift+alt tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -535,7 +563,7 @@
         // |first line
         // second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, 0);
+        verifySelection(SPACE_IN_2ND_LINE, 0);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_UP,
@@ -548,7 +576,7 @@
         // |first line
         // second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, 0);
+        verifySelection(SPACE_IN_2ND_LINE, 0);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_UP, 0,
@@ -561,7 +589,7 @@
         // |first line
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_UP,
@@ -574,10 +602,11 @@
         // |first line
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodePageDown() {
         // shift+alt tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -593,7 +622,7 @@
         // first line
         // second |line
         // last line|
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_DOWN,
@@ -606,7 +635,7 @@
         // first line
         // second |line
         // last line|
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
 
         // alt tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_DOWN, 0,
@@ -619,7 +648,7 @@
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PAGE_DOWN,
@@ -632,10 +661,11 @@
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeMoveHome() {
         // shift+ctrl tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -651,7 +681,7 @@
         // |first line
         // second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, 0);
+        verifySelection(SPACE_IN_2ND_LINE, 0);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_HOME,
@@ -664,7 +694,7 @@
         // first line
         // |second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
 
         pressShift();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -672,7 +702,7 @@
         // first line
         // |second |line
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, START_OF_2ND_LINE);
 
         // ctrl tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_HOME, 0,
@@ -685,7 +715,7 @@
         // |first line
         // second line
         // last line
-        assertSelection(0);
+        verifySelection(0);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_HOME,
@@ -698,7 +728,7 @@
         // first line
         // |second line
         // last line
-        assertSelection(START_OF_2ND_LINE);
+        verifySelection(START_OF_2ND_LINE);
 
         MetaKeyKeyListener.resetMetaState(mEditable);
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -706,10 +736,11 @@
         // first line
         // |second line
         // last line
-        assertSelection(START_OF_2ND_LINE);
+        verifySelection(START_OF_2ND_LINE);
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithKeyCodeMoveEnd() {
         // shift+ctrl tests
         KeyEvent shiftAltEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
@@ -725,7 +756,7 @@
         // first line
         // second |line
         // last line|
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_ALL_TEXT);
 
         // shift tests
         KeyEvent shiftEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_END,
@@ -738,7 +769,7 @@
         // first line
         // second |line|
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
 
         pressShift();
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -746,7 +777,7 @@
         // first line
         // second |line|
         // last line
-        assertSelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE, END_OF_2ND_LINE);
 
         // ctrl tests
         KeyEvent altEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_END, 0,
@@ -759,7 +790,7 @@
         // first line
         // second line
         // last line|
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         // no-meta tests
         KeyEvent noMetaEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_END,
@@ -772,7 +803,7 @@
         // first line
         // second line|
         // last line
-        assertSelection(END_OF_2ND_LINE);
+        verifySelection(END_OF_2ND_LINE);
 
         MetaKeyKeyListener.resetMetaState(mEditable);
         assertTrue(mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable,
@@ -780,21 +811,19 @@
         // first line
         // second line|
         // last line
-        assertSelection(END_OF_2ND_LINE);
-    }
-
-    public void testOnKeyDownWithNullLayout() {
-        initTextViewWithNullLayout();
-        try {
-            mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable, KeyEvent.KEYCODE_DPAD_RIGHT,
-                    null);
-            fail("The method did not throw NullPointerException when layout of the view is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
+        verifySelection(END_OF_2ND_LINE);
     }
 
     @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnKeyDownWithNullLayout() {
+        initTextViewWithNullLayout();
+        // Should throw NullPointerException when layout of the view is null
+        mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable, KeyEvent.KEYCODE_DPAD_RIGHT, null);
+    }
+
+    @UiThreadTest
+    @Test
     public void testOnKeyOther() {
         // first line
         // second |line
@@ -847,6 +876,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnKeyDownWithOtherKeyCode() {
         // first line
         // second |line
@@ -866,19 +896,22 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnTouchEvent() throws Throwable {
         long now = SystemClock.currentThreadTimeMillis();
         Selection.setSelection(mEditable, SPACE_IN_2ND_LINE);
         assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
                 MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1, 0)));
-        assertSelection(SPACE_IN_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE);
 
         assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
                 MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1,
                         KeyEvent.META_SHIFT_ON)));
-        assertSelection(SPACE_IN_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE);
     }
 
+    @UiThreadTest
+    @Test
     public void testOnTouchEventWithNullLayout() {
         initTextViewWithNullLayout();
         mTextView.setFocusable(true);
@@ -891,40 +924,39 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnTouchEventWithoutFocus() {
         long now = SystemClock.currentThreadTimeMillis();
         Selection.setSelection(mEditable, SPACE_IN_2ND_LINE);
         assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
                 MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1, 0)));
-        assertSelection(SPACE_IN_2ND_LINE);
+        verifySelection(SPACE_IN_2ND_LINE);
     }
 
-    public void testOnTouchEventWithNullParameters() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTouchEventNullView() {
+        // Should throw NullPointerException when param textView is null
+        mArrowKeyMovementMethod.onTouchEvent(null, mEditable, MotionEvent.obtain(0, 0, 0, 1, 1, 0));
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTouchEventNullSpannable() {
         initTextViewWithNullLayout();
-        try {
-            mArrowKeyMovementMethod.onTouchEvent(null, mEditable,
-                    MotionEvent.obtain(0, 0, 0, 1, 1, 0));
-            fail("The method did not throw NullPointerException when param textView is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
-
-        try {
-            mArrowKeyMovementMethod.onTouchEvent(mTextView, null,
-                    MotionEvent.obtain(0, 0, 0, 1, 1, 0));
-            fail("The method did not throw NullPointerException when param spannable is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
-
-        try {
-            mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable, null);
-            fail("The method did not throw NullPointerException when param motionEvent is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
+        // Should throw NullPointerException when param spannable is null
+        mArrowKeyMovementMethod.onTouchEvent(mTextView, null, MotionEvent.obtain(0, 0, 0, 1, 1, 0));
     }
 
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTouchEventNullEvent() {
+        initTextViewWithNullLayout();
+        // Should throw NullPointerException when param motionEvent is null
+        mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable, null);
+    }
+
+    @Test
     public void testInitialize() {
         Spannable spannable = new SpannableString("test content");
         ArrowKeyMovementMethod method = new ArrowKeyMovementMethod();
@@ -941,15 +973,17 @@
         method.initialize(null, spannable);
         assertEquals(0, Selection.getSelectionStart(spannable));
         assertEquals(0, Selection.getSelectionEnd(spannable));
-
-        try {
-            method.initialize(mTextView, null);
-            fail("The method did not throw NullPointerException when param spannable is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testIntializeNullSpannable() {
+        ArrowKeyMovementMethod method = new ArrowKeyMovementMethod();
+        // Should throw NullPointerException when param spannable is null
+        method.initialize(mTextView, null);
+    }
+
+    @UiThreadTest
+    @Test
     public void testOnTrackballEven() {
         assertFalse(mArrowKeyMovementMethod.onTrackballEvent(mTextView, mEditable,
                 MotionEvent.obtain(0, 0, 0, 1, 1, 0)));
@@ -965,11 +999,13 @@
         assertFalse(mArrowKeyMovementMethod.onTrackballEvent(mTextView, mEditable, null));
     }
 
+    @UiThreadTest
+    @Test
     public void testOnKeyUp() {
         ArrowKeyMovementMethod method = new ArrowKeyMovementMethod();
         SpannableString spannable = new SpannableString("Test Content");
         KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0);
-        TextView view = new TextViewNoIme(getActivity());
+        TextView view = new TextViewNoIme(mActivityRule.getActivity());
         view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
 
         assertFalse(method.onKeyUp(view, spannable, KeyEvent.KEYCODE_0, event));
@@ -986,6 +1022,7 @@
             + "lectus porta consequ\u00e4t...  LOReM iPSuM";
 
     @UiThreadTest
+    @Test
     public void testFollowingWordStartToEnd() {
 
         // NOTE: there seems to be much variation in how word boundaries are
@@ -996,92 +1033,93 @@
 
         // |Lorem ipsum; dolor sit $met,
         Selection.setSelection(mEditable, 0);
-        assertSelection(0);
+        verifySelection(0);
 
         // Lorem| ipsum; dolor sit $met,
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(5);
+        verifySelection(5);
 
         // Lorem ipsum|; dolor sit $met,
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(11);
+        verifySelection(11);
 
         // Lorem ipsum; dolor| sit $met,
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(18);
+        verifySelection(18);
 
         // Lorem ipsum; dolor sit| $met,
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(22);
+        verifySelection(22);
 
         // $met|, conse$_$ctetur$       Adipiscing.elit.integ$r.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(27);
+        verifySelection(27);
 
         // $met, conse$_$ctetur|$       Adipiscing.elit.integ$r.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(43);
+        verifySelection(43);
 
         // TODO: enable these two additional word breaks when implemented
 //        // $met, conse$_$ctetur$       Adipiscing|.elit.integ$r.
 //        assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-//        assertSelection(61);
+//        verifySelection(61);
 //
 //        // $met, conse$_$ctetur$       Adipiscing.elit|.integ$r.
 //        assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-//        assertSelection(66);
+//        verifySelection(66);
 
         // $met, conse$_$ctetur$       Adipiscing.elit.integ$r|.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(74);
+        verifySelection(74);
 
         // integ$r. Etiam|    tristique$tortor nec   ?:?    $$lectus porta
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(81);
+        verifySelection(81);
 
         // integ$r. Etiam    tristique|$tortor nec   ?:?    $$lectus porta
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(94);
+        verifySelection(94);
 
         // integ$r. Etiam    tristique$tortor| nec   ?:?    $$lectus porta
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(101);
+        verifySelection(101);
 
         // integ$r. Etiam    tristique$tortor nec|   ?:?    $$lectus porta
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(105);
+        verifySelection(105);
 
         // integ$r. Etiam    tristique$tortor nec   ?:?    $$lectus| porta
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(123);
+        verifySelection(123);
 
         // $$lectus porta| consequ$t...  LOReM iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(129);
+        verifySelection(129);
 
         // $$lectus porta consequ$t|...  LOReM iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(139);
+        verifySelection(139);
 
         // $$lectus porta consequ$t...  LOReM| iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(149);
+        verifySelection(149);
 
         // $$lectus porta consequ$t...  LOReM iPSuM|
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(155);
+        verifySelection(155);
 
         // keep trying to push beyond end, which should fail
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(155);
+        verifySelection(155);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(155);
+        verifySelection(155);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(155);
+        verifySelection(155);
 
     }
 
     @UiThreadTest
+    @Test
     public void testPrecedingWordEndToStart() {
 
         // NOTE: there seems to be much variation in how word boundaries are
@@ -1092,88 +1130,88 @@
 
         // $$lectus porta consequ$t...  LOReM iPSuM|
         Selection.setSelection(mEditable, mEditable.length());
-        assertSelection(155);
+        verifySelection(155);
 
         // $$lectus porta consequ$t...  LOReM |iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(150);
+        verifySelection(150);
 
         // $$lectus porta consequ$t...  |LOReM iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(144);
+        verifySelection(144);
 
         // $$lectus porta |consequ$t...  LOReM iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(130);
+        verifySelection(130);
 
         // $$lectus |porta consequ$t...  LOReM iPSuM
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(124);
+        verifySelection(124);
 
         // integ$r. Etiam    tristique$tortor nec   ?:?    $$|lectus
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(117);
+        verifySelection(117);
 
         // integ$r. Etiam    tristique$tortor |nec   ?:?    $$lectus
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(102);
+        verifySelection(102);
 
         // integ$r. Etiam    tristique$|tortor nec   ?:?    $$lectus
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(95);
+        verifySelection(95);
 
         // integ$r. Etiam    |tristique$tortor nec   ?:?    $$lectus
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(85);
+        verifySelection(85);
 
         // integ$r. |Etiam    tristique$tortor nec   ?:?    $$lectus
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(76);
+        verifySelection(76);
 
         // TODO: enable these two additional word breaks when implemented
 //        // dolor sit $met, conse$_$ctetur$       Adipiscing.elit.|integ$r.
 //        assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-//        assertSelection(67);
+//        verifySelection(67);
 //
 //        // dolor sit $met, conse$_$ctetur$       Adipiscing.|elit.integ$r.
 //        assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-//        assertSelection(62);
+//        verifySelection(62);
 
         // dolor sit $met, conse$_$ctetur$       |Adipiscing.elit.integ$r.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(51);
+        verifySelection(51);
 
         // dolor sit $met, |conse$_$ctetur$       Adipiscing.elit.integ$r.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(29);
+        verifySelection(29);
 
         // dolor sit |$met, conse$_$ctetur$       Adipiscing.elit.integ$r.
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(23);
+        verifySelection(23);
 
         // Lorem ipsum; dolor |sit $met
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(19);
+        verifySelection(19);
 
         // Lorem ipsum; |dolor sit $met
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(13);
+        verifySelection(13);
 
         // Lorem |ipsum; dolor sit $met
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(6);
+        verifySelection(6);
 
         // |Lorem ipsum; dolor sit $met
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
 
         // keep trying to push before beginning, which should fail
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
 
     }
 
@@ -1181,176 +1219,181 @@
             "Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4";
 
     @UiThreadTest
+    @Test
     public void testFollowingWordStartToEndWithNumbers() {
 
         initTextViewWithNullLayout(TEXT_WORDS_WITH_NUMBERS);
 
         // |Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4
         Selection.setSelection(mEditable, 0);
-        assertSelection(0);
+        verifySelection(0);
 
         // Lorem| ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(5);
+        verifySelection(5);
 
         // Lorem ipsum123,456.90|   dolor sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(21);
+        verifySelection(21);
 
         // Lorem ipsum123,456.90   dolor| sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(29);
+        verifySelection(29);
 
         // Lorem ipsum123,456.90   dolor sit|.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(33);
+        verifySelection(33);
 
         // Lorem ipsum123,456.90   dolor sit.. 4|-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(37);
+        verifySelection(37);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0|=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(41);
+        verifySelection(41);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0=2| ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(43);
+        verifySelection(43);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4|
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(55);
+        verifySelection(55);
 
         // keep trying to push beyond end, which should fail
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(55);
+        verifySelection(55);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(55);
+        verifySelection(55);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(55);
+        verifySelection(55);
 
     }
 
     @UiThreadTest
+    @Test
     public void testFollowingWordEndToStartWithNumbers() {
 
         initTextViewWithNullLayout(TEXT_WORDS_WITH_NUMBERS);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4|
         Selection.setSelection(mEditable, mEditable.length());
-        assertSelection(55);
+        verifySelection(55);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 |ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(44);
+        verifySelection(44);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-0.0=|2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(42);
+        verifySelection(42);
 
         // Lorem ipsum123,456.90   dolor sit.. 4-|0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(38);
+        verifySelection(38);
 
         // Lorem ipsum123,456.90   dolor sit.. |4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(36);
+        verifySelection(36);
 
         // Lorem ipsum123,456.90   dolor |sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(30);
+        verifySelection(30);
 
         // Lorem ipsum123,456.90   |dolor sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(24);
+        verifySelection(24);
 
         // Lorem |ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(6);
+        verifySelection(6);
 
         // |Lorem ipsum123,456.90   dolor sit.. 4-0.0=2 ADipiscing4
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
 
         // keep trying to push before beginning, which should fail
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
 
     }
 
     private static final String TEXT_WORDS_WITH_1CHAR_FINAL_WORD = "abc d";
 
     @UiThreadTest
+    @Test
     public void testFollowingWordStartToEndWithOneCharFinalWord() {
 
         initTextViewWithNullLayout(TEXT_WORDS_WITH_1CHAR_FINAL_WORD);
 
         // |abc d
         Selection.setSelection(mEditable, 0);
-        assertSelection(0);
+        verifySelection(0);
 
         // abc| d
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(3);
+        verifySelection(3);
 
         // abc d|
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-        assertSelection(mEditable.length());
+        verifySelection(mEditable.length());
 
     }
 
     @UiThreadTest
+    @Test
     public void testFollowingWordEndToStartWithOneCharFinalWord() {
 
         initTextViewWithNullLayout(TEXT_WORDS_WITH_1CHAR_FINAL_WORD);
 
         // abc d|
         Selection.setSelection(mEditable, mEditable.length());
-        assertSelection(5);
+        verifySelection(5);
 
         // abc |d
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(4);
+        verifySelection(4);
 
         // |abc d
         assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-        assertSelection(0);
+        verifySelection(0);
 
     }
 
     @UiThreadTest
+    @Test
     public void testMovementFromMiddleOfWord() {
 
         initTextViewWithNullLayout("before word after");
-        checkMoveFromInsideWord(7, 10);
+        verifyMoveFromInsideWord(7, 10);
 
         // Surrogate characters: bairkan should be considered as a standard letter
         final String BAIRKAN = "\uD800\uDF31";
 
         initTextViewWithNullLayout("before wo" + BAIRKAN + "rd after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
 
         initTextViewWithNullLayout("before " + BAIRKAN + BAIRKAN + "xx after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
 
         initTextViewWithNullLayout("before xx" + BAIRKAN + BAIRKAN + " after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
 
         initTextViewWithNullLayout("before x" + BAIRKAN + "x" + BAIRKAN + " after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
 
         initTextViewWithNullLayout("before " + BAIRKAN + "x" + BAIRKAN + "x after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
 
         initTextViewWithNullLayout("before " + BAIRKAN + BAIRKAN + BAIRKAN + " after");
-        checkMoveFromInsideWord(7, 12);
+        verifyMoveFromInsideWord(7, 12);
     }
 
-    private void checkMoveFromInsideWord(int wordStart, int wordEnd) {
+    private void verifyMoveFromInsideWord(int wordStart, int wordEnd) {
 
         CharSequence text = mTextView.getText();
 
@@ -1362,7 +1405,7 @@
             }
             Selection.setSelection(mEditable, offset);
             assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_RIGHT));
-            assertSelection(wordEnd + 1);
+            verifySelection(wordEnd + 1);
         }
 
         // Check preceding always goes at the beginning of the word
@@ -1372,7 +1415,7 @@
             }
             Selection.setSelection(mEditable, offset);
             assertTrue(pressCtrlChord(KeyEvent.KEYCODE_DPAD_LEFT));
-            assertSelection(wordStart);
+            verifySelection(wordStart);
         }
     }
 
@@ -1381,7 +1424,7 @@
     }
 
     private void initTextViewWithNullLayout(CharSequence text) {
-        mTextView = new TextViewNoIme(getActivity());
+        mTextView = new TextViewNoIme(mActivityRule.getActivity());
         mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
         mTextView.setText(text, BufferType.EDITABLE);
         assertNull(mTextView.getLayout());
@@ -1416,19 +1459,19 @@
         return mArrowKeyMovementMethod.onKeyDown(mTextView, mEditable, keyCode, keyEvent);
     }
 
-    private void assertSelection(int expectedPosition) {
-        assertSelection(expectedPosition, expectedPosition);
+    private void verifySelection(int expectedPosition) {
+        verifySelection(expectedPosition, expectedPosition);
     }
 
-    private void assertSelection(int expectedStart, int expectedEnd) {
+    private void verifySelection(int expectedStart, int expectedEnd) {
         final int actualStart = Selection.getSelectionStart(mEditable);
         final int actualEnd = Selection.getSelectionEnd(mEditable);
 
-        assertCharSequenceIndexEquals(mEditable, expectedStart, actualStart);
-        assertCharSequenceIndexEquals(mEditable, expectedEnd, actualEnd);
+        verifyCharSequenceIndexEquals(mEditable, expectedStart, actualStart);
+        verifyCharSequenceIndexEquals(mEditable, expectedEnd, actualEnd);
     }
 
-    private static void assertCharSequenceIndexEquals(CharSequence text, int expected, int actual) {
+    private static void verifyCharSequenceIndexEquals(CharSequence text, int expected, int actual) {
         final String message = "expected <" + getCursorSnippet(text, expected) + "> but was <"
                 + getCursorSnippet(text, actual) + ">";
         assertEquals(message, expected, actual);
@@ -1443,26 +1486,26 @@
         }
     }
 
-    private void assertSelectEndOfContent() {
+    private void verifySelectEndOfContent() {
         Selection.removeSelection(mEditable);
         mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_DOWN);
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         Selection.removeSelection(mEditable);
         mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_RIGHT);
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
-        assertSelectEndOfContentExceptFocusForward();
+        verifySelectEndOfContentExceptFocusForward();
     }
 
-    private void assertSelectEndOfContentExceptFocusForward() {
+    private void verifySelectEndOfContentExceptFocusForward() {
         Selection.removeSelection(mEditable);
         mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_UP);
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
 
         Selection.removeSelection(mEditable);
         mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_LEFT);
-        assertSelection(END_OF_ALL_TEXT);
+        verifySelection(END_OF_ALL_TEXT);
     }
 
     private static class MyMetaKeyKeyListener extends MetaKeyKeyListener {
diff --git a/tests/tests/text/src/android/text/method/cts/BackspaceTest.java b/tests/tests/text/src/android/text/method/cts/BackspaceTest.java
index 43749a9..3f35371 100644
--- a/tests/tests/text/src/android/text/method/cts/BackspaceTest.java
+++ b/tests/tests/text/src/android/text/method/cts/BackspaceTest.java
@@ -16,15 +16,23 @@
 
 package android.text.method.cts;
 
-import android.support.test.filters.SmallTest;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.method.BaseKeyListener;
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test backspace key handling of {@link android.text.method.BaseKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class BackspaceTest extends KeyListenerTestCase {
     private static final BaseKeyListener mKeyListener = new BaseKeyListener() {
         public int getInputType() {
@@ -34,8 +42,8 @@
 
     // Sync the state to the TextView and call onKeyDown with KEYCODE_DEL key event.
     // Then update the state to the result of TextView.
-    private void backspace(final EditorState state, int modifiers) {
-        mInstrumentation.runOnMainSync(() -> {
+    private void backspace(final EditorState state, int modifiers) throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText(state.mText, BufferType.EDITABLE);
             mTextView.setKeyListener(mKeyListener);
             mTextView.setSelection(state.mSelectionStart, state.mSelectionEnd);
@@ -44,7 +52,7 @@
         assertTrue(mTextView.hasWindowFocus());
 
         final KeyEvent keyEvent = getKey(KeyEvent.KEYCODE_DEL, modifiers);
-        mInstrumentation.runOnMainSync(() -> mTextView.onKeyDown(keyEvent.getKeyCode(), keyEvent));
+        mActivityRule.runOnUiThread(() -> mTextView.onKeyDown(keyEvent.getKeyCode(), keyEvent));
         mInstrumentation.waitForIdleSync();
 
         state.mText = mTextView.getText();
@@ -52,8 +60,8 @@
         state.mSelectionEnd = mTextView.getSelectionEnd();
     }
 
-    @SmallTest
-    public void testCRLF() {
+    @Test
+    public void testCRLF() throws Throwable {
         EditorState state = new EditorState();
 
         // U+000A is LINE FEED.
@@ -77,8 +85,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testSurrogatePairs() {
+    @Test
+    public void testSurrogatePairs() throws Throwable {
         EditorState state = new EditorState();
 
         state.setByString("U+1F441 |");
@@ -92,8 +100,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testReplacementSpan() {
+    @Test
+    public void testReplacementSpan() throws Throwable {
         EditorState state = new EditorState();
 
         // ReplacementSpan will be set to "()" region.
@@ -134,8 +142,8 @@
         state.assertEquals("| 'g'");
     }
 
-    @SmallTest
-    public void testCombiningEnclosingKeycaps() {
+    @Test
+    public void testCombiningEnclosingKeycaps() throws Throwable {
         EditorState state = new EditorState();
 
         // U+20E3 is COMBINING ENCLOSING KEYCAP.
@@ -149,8 +157,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testVariationSelector() {
+    @Test
+    public void testVariationSelector() throws Throwable {
         EditorState state = new EditorState();
 
         // U+FE0F is VARIATION SELECTOR-16.
@@ -164,8 +172,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testFlags() {
+    @Test
+    public void testFlags() throws Throwable {
         EditorState state = new EditorState();
 
         // U+1F1FA is REGIONAL INDICATOR SYMBOL LETTER U.
diff --git a/tests/tests/text/src/android/text/method/cts/BaseKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/BaseKeyListenerTest.java
index 146f3d5..7fd1b04 100644
--- a/tests/tests/text/src/android/text/method/cts/BaseKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/BaseKeyListenerTest.java
@@ -16,8 +16,14 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import android.cts.util.CtsKeyEventUtil;
 import android.os.SystemClock;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.Selection;
@@ -28,17 +34,23 @@
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link android.text.method.BaseKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class BaseKeyListenerTest extends KeyListenerTestCase {
     private static final CharSequence TEST_STRING = "123456";
 
-    public void testBackspace() {
-        testBackspace(0);
+    @Test
+    public void testBackspace() throws Throwable {
+        verifyBackspace(0);
     }
 
-    private void testBackspace(int modifiers) {
+    private void verifyBackspace(int modifiers) throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
         final KeyEvent event = getKey(KeyEvent.KEYCODE_DEL, modifiers);
         Editable content = Editable.Factory.getInstance().newEditable(TEST_STRING);
@@ -96,11 +108,13 @@
         assertEquals("\u05D6\u05D4\u0020Anroid\u0020\u05E2\u05D5\u05D1", content.toString());
     }
 
-    public void testBackspace_withShift() {
-        testBackspace(KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON);
+    @Test
+    public void testBackspace_withShift() throws Throwable {
+        verifyBackspace(KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON);
     }
 
-    public void testBackspace_withAlt() {
+    @Test
+    public void testBackspace_withAlt() throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
         Editable content = Editable.Factory.getInstance().newEditable(TEST_STRING);
 
@@ -124,7 +138,8 @@
         assertEquals("", content.toString());
     }
 
-    public void testBackspace_withSendKeys() {
+    @Test
+    public void testBackspace_withSendKeys() throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
 
         // Delete the first character '1'
@@ -155,12 +170,13 @@
         assertEquals(TEST_STRING, mTextView.getText().toString());
     }
 
-    private void assertCursorPosition(Editable content, int offset) {
+    private void verifyCursorPosition(Editable content, int offset) {
         assertEquals(offset, Selection.getSelectionStart(content));
         assertEquals(offset, Selection.getSelectionEnd(content));
     }
 
-    public void testBackspace_withCtrl() {
+    @Test
+    public void testBackspace_withCtrl() throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
 
         // If the contents only having symbolic characters, delete all characters.
@@ -169,7 +185,7 @@
         prepTextViewSync(content, mockBaseKeyListener, false, testText.length(), testText.length());
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Latin ASCII text
         testText = "Hello, World. This is Android.";
@@ -179,32 +195,32 @@
         prepTextViewSync(content, mockBaseKeyListener, false, 0, 0);
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World. This is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         prepTextViewSync(content, mockBaseKeyListener, false, testText.length(), testText.length());
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World. This is ", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World. This ", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World. ", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, ", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Latin ASCII, cursor is middle of the text.
         testText = "Hello, World. This is Android.";
@@ -215,19 +231,19 @@
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World.  is Android.", content.toString());
-        assertCursorPosition(content, content.toString().length() - charsFromTail);
+        verifyCursorPosition(content, content.toString().length() - charsFromTail);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello,  is Android.", content.toString());
-        assertCursorPosition(content, content.toString().length() - charsFromTail);
+        verifyCursorPosition(content, content.toString().length() - charsFromTail);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals(" is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals(" is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Latin ASCII, cursor is inside word.
         testText = "Hello, World. This is Android.";
@@ -239,19 +255,19 @@
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, World. is is Android.", content.toString());
-        assertCursorPosition(content, content.toString().length() - charsFromTail);
+        verifyCursorPosition(content, content.toString().length() - charsFromTail);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("Hello, is is Android.", content.toString());
-        assertCursorPosition(content, content.toString().length() - charsFromTail);
+        verifyCursorPosition(content, content.toString().length() - charsFromTail);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("is is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("is is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Hebrew Text
         // The deletion works on a Logical direction basis.
@@ -263,24 +279,24 @@
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05E9\u05DC\u05D5\u05DD\u0020\u05D4\u05E2\u05D5\u05DC\u05DD\u002E\u0020" +
                      "\u05D6\u05D4\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05E9\u05DC\u05D5\u05DD\u0020\u05D4\u05E2\u05D5\u05DC\u05DD\u002E\u0020",
                      content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05E9\u05DC\u05D5\u05DD\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // BiDi Text
         // The deletion works on a Logical direction basis.
@@ -292,30 +308,31 @@
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05D6\u05D4\u0020\u05DC\u002D\u0020\u0041Android\u0020\u05E2\u05D5\u05D1" +
                      "\u05D3\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05D6\u05D4\u0020\u05DC\u002D\u0020\u0041Android\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05D6\u05D4\u0020\u05DC\u002D\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("\u05D6\u05D4\u0020", content.toString());
-        assertCursorPosition(content, content.toString().length());
+        verifyCursorPosition(content, content.toString().length());
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlBackspace(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
     }
 
-    public void testForwardDelete_withCtrl() {
+    @Test
+    public void testForwardDelete_withCtrl() throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
 
         // If the contents only having symbolic characters, delete all characters.
@@ -324,7 +341,7 @@
         prepTextViewSync(content, mockBaseKeyListener, false, 0, 0);
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Latin ASCII text
         testText = "Hello, World. This is Android.";
@@ -334,36 +351,36 @@
         prepTextViewSync(content, mockBaseKeyListener, false, testText.length(), testText.length());
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. This is Android.", content.toString());
-        assertCursorPosition(content, testText.length());
+        verifyCursorPosition(content, testText.length());
 
         prepTextViewSync(content, mockBaseKeyListener, false, 0, 0);
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals(", World. This is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals(". This is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals(" is Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals(" Android.", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals(".", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // Latin ASCII, cursor is middle of the text.
         testText = "Hello, World. This is Android.";
@@ -373,23 +390,23 @@
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World.  is Android.", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World.  Android.", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. .", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. ", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. ", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         // Latin ASCII, cursor is inside word.
         testText = "Hello, World. This is Android.";
@@ -399,23 +416,23 @@
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. Th is Android.", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. Th Android.", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. Th.", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. Th", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("Hello, World. Th", content.toString());
-        assertCursorPosition(content, charsFromHead);
+        verifyCursorPosition(content, charsFromHead);
 
         // Hebrew Text
         // The deletion works on a Logical direction basis.
@@ -427,29 +444,29 @@
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u0020\u05D4\u05E2\u05D5\u05DC\u05DD\u002E\u0020\u05D6\u05D4\u0020\u05D0" +
                      "\u05E0\u05D3\u05E8\u05D5\u05D0\u05D9\u05D3\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u002E\u0020\u05D6\u05D4\u0020\u05D0\u05E0\u05D3\u05E8\u05D5\u05D0\u05D9" +
                 "\u05D3\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u0020\u05D0\u05E0\u05D3\u05E8\u05D5\u05D0\u05D9\u05D3\u002E",
                      content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         // BiDi Text
         // The deletion works on a Logical direction basis.
@@ -461,33 +478,33 @@
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u0020\u05DC\u002D\u0020\u0041Android\u0020\u05E2\u05D5\u05D1\u05D3\u0020" +
                      "\u05D4\u05D9\u05D8\u05D1\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u002D\u0020\u0041Android\u0020\u05E2\u05D5\u05D1\u05D3\u0020\u05D4\u05D9" +
                      "\u05D8\u05D1\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u0020\u05E2\u05D5\u05D1\u05D3\u0020\u05D4\u05D9\u05D8\u05D1\u002E",
                      content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u0020\u05D4\u05D9\u05D8\u05D1\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("\u002E", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
 
         executeCtrlForwardDelete(content, mockBaseKeyListener);
         assertEquals("", content.toString());
-        assertCursorPosition(content, 0);
+        verifyCursorPosition(content, 0);
     }
 
     /*
@@ -496,7 +513,8 @@
      * 2. Set a selection and press DEL key, the selection is deleted.
      * 3. ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting the event's text into the content.
      */
-    public void testPressKey() {
+    @Test
+    public void testPressKey() throws Throwable {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
 
         // press '0' key.
@@ -519,6 +537,7 @@
 //        assertEquals("13abcd456", mTextView.getText().toString());
     }
 
+    @Test
     public void testOnKeyOther() {
         final BaseKeyListener mockBaseKeyListener = new MockBaseKeyListener();
         final String string = "abc";
@@ -565,8 +584,9 @@
      * the UI thread.
      */
     private void prepTextViewSync(final CharSequence content, final BaseKeyListener keyListener,
-            final boolean selectInTextView, final int selectionStart, final int selectionEnd) {
-        mInstrumentation.runOnMainSync(() -> {
+            final boolean selectInTextView, final int selectionStart, final int selectionEnd)
+                    throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText(content, BufferType.EDITABLE);
             mTextView.setKeyListener(keyListener);
             Selection.setSelection(
diff --git a/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
index f8b6163..5a9460e 100644
--- a/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
@@ -20,7 +20,9 @@
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
 import static android.widget.TextView.BufferType.EDITABLE;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.annotation.NonNull;
 import android.app.Activity;
@@ -50,129 +52,127 @@
 /**
  * Test {@link BaseMovementMethod}.
  */
+@MediumTest
 @RunWith(AndroidJUnit4.class)
 public class BaseMovementMethodTest {
-
+    private Instrumentation mInstrumentation;
     private BaseMovementMethod mMovementMethod;
+    private TextView mTextView;
 
     @Rule
     public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    private Instrumentation mInstrumentation;
-
     @Before
-    public void setUp() throws Exception {
+    public void setup() {
         mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mMovementMethod = new BaseMovementMethod();
     }
 
-    @MediumTest
     @Test
     public void testOnGenericMotionEvent_horizontalScroll() throws Throwable {
         final String testLine = "some text some text";
         final String testString = testLine + "\n" + testLine;
 
-        final TextView textView = createTextView();
+        mActivityRule.runOnUiThread(() -> mTextView = createTextView());
         // limit lines for horizontal scroll
-        textView.setSingleLine();
-        textView.setText(testString, EDITABLE);
+        mTextView.setSingleLine();
+        mTextView.setText(testString, EDITABLE);
 
         // limit width for horizontal scroll
 
-        setContentView(textView, (int) textView.getPaint().measureText(testLine) / 3);
+        setContentView(mTextView, (int) mTextView.getPaint().measureText(testLine) / 3);
         // assert the default scroll position
-        assertEquals(0, textView.getScrollX());
+        assertEquals(0, mTextView.getScrollX());
 
-        final Spannable text = (Spannable) textView.getText();
-        final double lineSpacing = Math.ceil(textView.getPaint().getFontSpacing());
+        final Spannable text = (Spannable) mTextView.getText();
+        final double lineSpacing = Math.ceil(mTextView.getPaint().getFontSpacing());
 
         // scroll right
         MotionEvent event = createScrollEvent(1, 0);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(lineSpacing, textView.getScrollX(), lineSpacing / 4);
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(lineSpacing, mTextView.getScrollX(), lineSpacing / 4);
         event.recycle();
 
         // scroll left
         event = createScrollEvent(-1, 0);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(0, textView.getScrollX());
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(0, mTextView.getScrollX());
         event.recycle();
 
         // cannot scroll to left
         event = createScrollEvent(-1, 0);
-        assertFalse(mMovementMethod.onGenericMotionEvent(textView, text, event));
+        assertFalse(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
         event.recycle();
 
         // cannot scroll to right
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView,
-                () -> textView.scrollTo((int) textView.getLayout().getLineWidth(0), 0));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView,
+                () -> mTextView.scrollTo((int) mTextView.getLayout().getLineWidth(0), 0));
         event = createScrollEvent(1, 0);
-        assertFalse(mMovementMethod.onGenericMotionEvent(textView, text, event));
+        assertFalse(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
         event.recycle();
 
         // meta shift on
         // reset scroll
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView,
-                () -> textView.scrollTo(0, 0));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView,
+                () -> mTextView.scrollTo(0, 0));
 
         // scroll top becomes scroll right
         event = createScrollEvent(0, 1, KeyEvent.META_SHIFT_ON);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(lineSpacing, textView.getScrollX(), lineSpacing / 4);
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(lineSpacing, mTextView.getScrollX(), lineSpacing / 4);
         event.recycle();
 
         // scroll down becomes scroll left
         event = createScrollEvent(0, -1, KeyEvent.META_SHIFT_ON);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(0, textView.getScrollX());
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(0, mTextView.getScrollX());
         event.recycle();
     }
 
-    @MediumTest
     @Test
     public void testOnGenericMotionEvent_verticalScroll() throws Throwable {
         final String testLine = "some text some text";
         final String testString = testLine + "\n" + testLine;
 
-        final TextView textView = createTextView();
+        mActivityRule.runOnUiThread(() -> mTextView = createTextView());
         // limit lines for vertical scroll
-        textView.setMaxLines(1);
-        textView.setText(testString, EDITABLE);
-        setContentView(textView, WRAP_CONTENT);
+        mTextView.setMaxLines(1);
+        mTextView.setText(testString, EDITABLE);
+        setContentView(mTextView, WRAP_CONTENT);
         // assert the default scroll positions
-        assertEquals(0, textView.getScrollY());
+        assertEquals(0, mTextView.getScrollY());
 
-        final Spannable text = (Spannable) textView.getText();
-        final int lineHeight = textView.getLineHeight();
+        final Spannable text = (Spannable) mTextView.getText();
+        final int lineHeight = mTextView.getLineHeight();
 
         // scroll down
         MotionEvent event = createScrollEvent(0, -1);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(lineHeight, textView.getScrollY(), lineHeight / 4);
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(lineHeight, mTextView.getScrollY(), lineHeight / 4);
         event.recycle();
 
         // scroll up
         event = createScrollEvent(0, 1);
-        assertTrue(mMovementMethod.onGenericMotionEvent(textView, text, event));
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView, null);
-        assertEquals(0, textView.getScrollY());
+        assertTrue(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView, null);
+        assertEquals(0, mTextView.getScrollY());
         event.recycle();
 
         // cannot scroll up
         event = createScrollEvent(0, 1);
-        assertFalse(mMovementMethod.onGenericMotionEvent(textView, text, event));
+        assertFalse(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
         event.recycle();
 
         // cannot scroll down
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, textView,
-                () -> textView.scrollTo(0, textView.getLayout().getHeight()));
+        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mTextView,
+                () -> mTextView.scrollTo(0, mTextView.getLayout().getHeight()));
         event = createScrollEvent(0, -1);
-        assertFalse(mMovementMethod.onGenericMotionEvent(textView, text, event));
+        assertFalse(mMovementMethod.onGenericMotionEvent(mTextView, text, event));
         event.recycle();
     }
 
diff --git a/tests/tests/text/src/android/text/method/cts/CharacterPickerDialogTest.java b/tests/tests/text/src/android/text/method/cts/CharacterPickerDialogTest.java
index b348c28..fda8469 100644
--- a/tests/tests/text/src/android/text/method/cts/CharacterPickerDialogTest.java
+++ b/tests/tests/text/src/android/text/method/cts/CharacterPickerDialogTest.java
@@ -16,50 +16,59 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.app.Activity;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.Selection;
 import android.text.method.CharacterPickerDialog;
 import android.view.View;
 import android.widget.Gallery;
 
-public class CharacterPickerDialogTest extends
-        ActivityInstrumentationTestCase2<CtsActivity> {
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class CharacterPickerDialogTest {
     private Activity mActivity;
 
-    public CharacterPickerDialogTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mActivity = getActivity();
+    @Before
+    public void setup() {
+        mActivity = mActivityRule.getActivity();
     }
 
     @UiThreadTest
+    @Test
     public void testConstructor() {
         final CharSequence str = "123456";
         final Editable content = Editable.Factory.getInstance().newEditable(str);
         final View view = new TextViewNoIme(mActivity);
         new CharacterPickerDialog(view.getContext(), view, content, "\u00A1", false);
-
-        try {
-            new CharacterPickerDialog(null, view, content, "\u00A1", false);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected.
-        }
-    }
-
-    public void testOnCreate() {
-        // Do not test. Implementation details.
     }
 
     @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNullContext() {
+        final CharSequence str = "123456";
+        final Editable content = Editable.Factory.getInstance().newEditable(str);
+        final View view = new TextViewNoIme(mActivity);
+        new CharacterPickerDialog(null, view, content, "\u00A1", false);
+    }
+
+    @UiThreadTest
+    @Test
     public void testOnItemClick() {
         final Gallery parent = new Gallery(mActivity);
         final CharSequence str = "123456";
@@ -102,6 +111,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnClick() {
         final CharSequence str = "123456";
         final Editable content = Editable.Factory.getInstance().newEditable(str);
@@ -114,6 +124,5 @@
 
         // nothing to test here, just make sure onClick does not throw exception
         characterPickerDialog.onClick(view);
-
     }
 }
diff --git a/tests/tests/text/src/android/text/method/cts/DateKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/DateKeyListenerTest.java
index fd2761e..77d1a6a 100644
--- a/tests/tests/text/src/android/text/method/cts/DateKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/DateKeyListenerTest.java
@@ -16,20 +16,33 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
 import android.cts.util.CtsKeyEventUtil;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.method.DateKeyListener;
 import android.view.KeyEvent;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link android.text.method.DateKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class DateKeyListenerTest extends KeyListenerTestCase {
-
+    @Test
     public void testConstructor() {
         new DateKeyListener();
     }
 
+    @Test
     public void testGetInstance() {
         DateKeyListener listener1 = DateKeyListener.getInstance();
         DateKeyListener listener2 = DateKeyListener.getInstance();
@@ -39,13 +52,14 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetAcceptedChars() {
         MockDateKeyListener mockDateKeyListener = new MockDateKeyListener();
 
-        TextMethodUtils.assertEquals(DateKeyListener.CHARACTERS,
-                mockDateKeyListener.getAcceptedChars());
+        assertArrayEquals(DateKeyListener.CHARACTERS, mockDateKeyListener.getAcceptedChars());
     }
 
+    @Test
     public void testGetInputType() {
         DateKeyListener dateKeyListener = new DateKeyListener();
 
@@ -62,6 +76,7 @@
      * 5. Press '/' key and check if the content of TextView becomes "12-/"
      * 6. remove DateKeyListener and Press '/' key, this key will not be accepted
      */
+    @Test
     public void testDateTimeKeyListener() {
         final DateKeyListener dateKeyListener = DateKeyListener.getInstance();
 
diff --git a/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
index 6276125..dbb5ef8 100644
--- a/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
@@ -16,21 +16,34 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
 import android.cts.util.CtsKeyEventUtil;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.method.DateTimeKeyListener;
 import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link android.text.method.DateTimeKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class DateTimeKeyListenerTest extends KeyListenerTestCase {
-
+    @Test
     public void testConstructor() {
         new DateTimeKeyListener();
     }
 
+    @Test
     public void testGetInstance() {
         DateTimeKeyListener listener1 = DateTimeKeyListener.getInstance();
         DateTimeKeyListener listener2 = DateTimeKeyListener.getInstance();
@@ -40,13 +53,15 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetAcceptedChars() {
         MockDateTimeKeyListener mockDateTimeKeyListener = new MockDateTimeKeyListener();
 
-        TextMethodUtils.assertEquals(DateTimeKeyListener.CHARACTERS,
+        assertArrayEquals(DateTimeKeyListener.CHARACTERS,
                 mockDateTimeKeyListener.getAcceptedChars());
     }
 
+    @Test
     public void testGetInputType() {
         DateTimeKeyListener listener = DateTimeKeyListener.getInstance();
 
@@ -65,6 +80,7 @@
      * 6. Press an unaccepted key if it exists. and this key will not be accepted.
      * 7. Remove DateKeyListener and Press '1' key, this key will not be accepted
      */
+    @Test
     public void testDateTimeKeyListener() {
         final DateTimeKeyListener dateTimeKeyListener = DateTimeKeyListener.getInstance();
         setKeyListenerSync(dateTimeKeyListener);
diff --git a/tests/tests/text/src/android/text/method/cts/DialerKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/DialerKeyListenerTest.java
index 219869c..7808824 100644
--- a/tests/tests/text/src/android/text/method/cts/DialerKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/DialerKeyListenerTest.java
@@ -16,25 +16,40 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.method.DialerKeyListener;
 import android.view.KeyEvent;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link android.text.method.DialerKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class DialerKeyListenerTest extends KeyListenerTestCase {
+    @Test
     public void testConstructor() {
         new DialerKeyListener();
     }
 
+    @Test
     public void testLookup() {
         MockDialerKeyListener mockDialerKeyListener = new MockDialerKeyListener();
-        final int[] events = { KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_N, KeyEvent.KEYCODE_A };
+        final int[] events = {KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_N, KeyEvent.KEYCODE_A};
         SpannableString span = new SpannableString(""); // no meta spans
-        for (int event: events) {
+        for (int event : events) {
             KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, event);
             int keyChar = keyEvent.getNumber();
             if (keyChar != 0) {
@@ -43,14 +58,16 @@
                 // cannot make any assumptions how the key code gets translated
             }
         }
-
-        try {
-            mockDialerKeyListener.lookup(null, span);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testLookupNull() {
+        MockDialerKeyListener mockDialerKeyListener = new MockDialerKeyListener();
+        SpannableString span = new SpannableString(""); // no meta spans
+        mockDialerKeyListener.lookup(null, span);
+    }
+
+    @Test
     public void testGetInstance() {
         assertNotNull(DialerKeyListener.getInstance());
 
@@ -62,13 +79,15 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetAcceptedChars() {
         MockDialerKeyListener mockDialerKeyListener = new MockDialerKeyListener();
 
-        TextMethodUtils.assertEquals(DialerKeyListener.CHARACTERS,
+        assertArrayEquals(DialerKeyListener.CHARACTERS,
                 mockDialerKeyListener.getAcceptedChars());
     }
 
+    @Test
     public void testGetInputType() {
         DialerKeyListener listener = DialerKeyListener.getInstance();
 
diff --git a/tests/tests/text/src/android/text/method/cts/DigitsKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/DigitsKeyListenerTest.java
index 2587b60..b30d42d 100644
--- a/tests/tests/text/src/android/text/method/cts/DigitsKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/DigitsKeyListenerTest.java
@@ -16,7 +16,15 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
 import android.cts.util.CtsKeyEventUtil;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.Spannable;
 import android.text.SpannableString;
@@ -24,11 +32,16 @@
 import android.text.method.DigitsKeyListener;
 import android.view.KeyEvent;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link DigitsKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class DigitsKeyListenerTest extends KeyListenerTestCase {
-
+    @Test
     public void testConstructor() {
         new DigitsKeyListener();
 
@@ -45,6 +58,7 @@
      * 5. filter Spanned("-a1.b2c3d"), return Spanned("123") and copy spans.
      * 6. filter "", return null
      */
+    @Test
     public void testFilter1() {
         String source = "123456";
         String destString = "dest string";
@@ -102,6 +116,7 @@
      * 13. filter "-123456" but dest has '-' before dstart, return "123456"
      * 14. filter "+123456" but dest has '-' before dstart, return "123456"
      */
+    @Test
     public void testFilter2() {
         String source = "-123456";
         String destString = "dest string without sign and decimal";
@@ -200,6 +215,7 @@
      * 8. filter "123.456" but dest has '.' after dend, return "123456"
      * 9. filter "123.456" but dest has '.' before dstart, return "123456"
      */
+    @Test
     public void testFilter3() {
         String source = "123.456";
         String destString = "dest string without sign and decimal";
@@ -279,6 +295,7 @@
      * 16. filter "-123.456" but dest has '-' before dstart, return "123.456"
      * 17. filter "+123.456" but dest has '-' before dstart, return "123.456"
      */
+    @Test
     public void testFilter4() {
         String source = "-123.456";
         String destString = "dest string without sign and decimal";
@@ -388,6 +405,7 @@
      *  3. Press '.' key and this key could not be accepted.
      *  4. Press '2' key and check if the content of TextView becomes "12"
      */
+    @Test
     public void testDigitsKeyListener1() {
         final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance();
 
@@ -422,6 +440,7 @@
      *  6. Press '-' key and this key could not be accepted,
      *     because text view accepts minus sign iff it at the beginning.
      */
+    @Test
     public void testDigitsKeyListener2() {
         final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance(true, false);
 
@@ -464,6 +483,7 @@
      *  6. Press '.' key and this key could not be accepted,
      *     because text view accepts only one decimal point per field.
      */
+    @Test
     public void testDigitsKeyListener3() {
         final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance(false, true);
 
@@ -508,6 +528,7 @@
      *  6. Press '.' key and this key could not be accepted,
      *     because text view accepts only one decimal point per field.
      */
+    @Test
     public void testDigitsKeyListener4() {
         final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance(true, true);
 
@@ -548,7 +569,8 @@
      *  4. Press '-' key and this key could not be accepted.
      *  5. remove DigitsKeyListener and Press '5' key, this key will not be accepted
      */
-    public void testDigitsKeyListener5() {
+    @Test
+    public void testDigitsKeyListener5() throws Throwable {
         final String accepted = "56789";
         final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance(accepted);
 
@@ -572,7 +594,7 @@
         assertEquals("5", mTextView.getText().toString());
 
         // remove DigitsKeyListener
-        mInstrumentation.runOnMainSync(() -> {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setKeyListener(null);
             mTextView.requestFocus();
         });
@@ -584,6 +606,7 @@
         assertEquals("5", mTextView.getText().toString());
     }
 
+    @Test
     public void testGetInstance1() {
         DigitsKeyListener listener1 = DigitsKeyListener.getInstance();
         DigitsKeyListener listener2 = DigitsKeyListener.getInstance();
@@ -593,6 +616,7 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetInstance2() {
         DigitsKeyListener listener1 = DigitsKeyListener.getInstance(true, true);
         DigitsKeyListener listener2 = DigitsKeyListener.getInstance(true, true);
@@ -609,6 +633,7 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetInstance3() {
         DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance("abcdefg");
         assertNotNull(digitsKeyListener);
@@ -617,6 +642,7 @@
         assertNotNull(digitsKeyListener);
     }
 
+    @Test
     public void testGetAcceptedChars() {
         MockDigitsKeyListener mockDigitsKeyListener = new MockDigitsKeyListener();
 
@@ -627,18 +653,19 @@
             new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '+', '.' },
         };
 
-        TextMethodUtils.assertEquals(expected[0], mockDigitsKeyListener.getAcceptedChars());
+        assertArrayEquals(expected[0], mockDigitsKeyListener.getAcceptedChars());
 
         mockDigitsKeyListener = new MockDigitsKeyListener(true, false);
-        TextMethodUtils.assertEquals(expected[1], mockDigitsKeyListener.getAcceptedChars());
+        assertArrayEquals(expected[1], mockDigitsKeyListener.getAcceptedChars());
 
         mockDigitsKeyListener = new MockDigitsKeyListener(false, true);
-        TextMethodUtils.assertEquals(expected[2], mockDigitsKeyListener.getAcceptedChars());
+        assertArrayEquals(expected[2], mockDigitsKeyListener.getAcceptedChars());
 
         mockDigitsKeyListener = new MockDigitsKeyListener(true, true);
-        TextMethodUtils.assertEquals(expected[3], mockDigitsKeyListener.getAcceptedChars());
+        assertArrayEquals(expected[3], mockDigitsKeyListener.getAcceptedChars());
     }
 
+    @Test
     public void testGetInputType() {
         DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance(false, false);
         int expected = InputType.TYPE_CLASS_NUMBER;
diff --git a/tests/tests/text/src/android/text/method/cts/ForwardDeleteTest.java b/tests/tests/text/src/android/text/method/cts/ForwardDeleteTest.java
index a291b6b..12ce7a6 100644
--- a/tests/tests/text/src/android/text/method/cts/ForwardDeleteTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ForwardDeleteTest.java
@@ -16,15 +16,23 @@
 
 package android.text.method.cts;
 
-import android.support.test.filters.SmallTest;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.method.BaseKeyListener;
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test forward delete key handling of  {@link android.text.method.BaseKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class ForwardDeleteTest extends KeyListenerTestCase {
     private static final BaseKeyListener mKeyListener = new BaseKeyListener() {
         public int getInputType() {
@@ -34,8 +42,8 @@
 
     // Sync the state to the TextView and call onKeyDown with KEYCODE_FORWARD_DEL key event.
     // Then update the state to the result of TextView.
-    private void forwardDelete(final EditorState state, int modifiers) {
-        mInstrumentation.runOnMainSync(() -> {
+    private void forwardDelete(final EditorState state, int modifiers) throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText(state.mText, BufferType.EDITABLE);
             mTextView.setKeyListener(mKeyListener);
             mTextView.setSelection(state.mSelectionStart, state.mSelectionEnd);
@@ -52,8 +60,8 @@
         state.mSelectionEnd = mTextView.getSelectionEnd();
     }
 
-    @SmallTest
-    public void testCRLF() {
+    @Test
+    public void testCRLF() throws Throwable {
         EditorState state = new EditorState();
 
         // U+000A is LINE FEED.
@@ -76,8 +84,8 @@
         forwardDelete(state, 0);
     }
 
-    @SmallTest
-    public void testSurrogatePairs() {
+    @Test
+    public void testSurrogatePairs() throws Throwable {
         EditorState state = new EditorState();
 
         // U+1F441 is EYE
@@ -93,8 +101,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testReplacementSpan() {
+    @Test
+    public void testReplacementSpan() throws Throwable {
         EditorState state = new EditorState();
 
         state.setByString("| 'abc' ( 'de' ) 'fg'");
@@ -130,8 +138,8 @@
         state.assertEquals("'ab' |");
     }
 
-    @SmallTest
-    public void testCombiningEnclosingKeycaps() {
+    @Test
+    public void testCombiningEnclosingKeycaps() throws Throwable {
         EditorState state = new EditorState();
 
         // U+20E3 is COMBINING ENCLOSING KEYCAP.
@@ -144,8 +152,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testVariationSelector() {
+    @Test
+    public void testVariationSelector() throws Throwable {
         EditorState state = new EditorState();
 
         // U+FE0F is VARIATION SELECTOR-16.
@@ -159,8 +167,8 @@
         state.assertEquals("|");
     }
 
-    @SmallTest
-    public void testFlags() {
+    @Test
+    public void testFlags() throws Throwable {
         EditorState state = new EditorState();
 
         // U+1F1FA is REGIONAL INDICATOR SYMBOL LETTER U.
diff --git a/tests/tests/text/src/android/text/method/cts/HideReturnsTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/HideReturnsTransformationMethodTest.java
index d789c92..df48458 100644
--- a/tests/tests/text/src/android/text/method/cts/HideReturnsTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/HideReturnsTransformationMethodTest.java
@@ -16,24 +16,35 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.method.HideReturnsTransformationMethod;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 /**
  * Test {@link HideReturnsTransformationMethod}.
  */
-public class HideReturnsTransformationMethodTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class HideReturnsTransformationMethodTest {
+    @Test
     public void testConstructor() {
         new HideReturnsTransformationMethod();
     }
 
+    @Test
     public void testGetOriginal() {
         MyHideReturnsTranformationMethod method = new MyHideReturnsTranformationMethod();
-        TextMethodUtils.assertEquals(new char[] { '\r' }, method.getOriginal());
+        assertArrayEquals(new char[] { '\r' }, method.getOriginal());
     }
 
+    @Test
     public void testGetInstance() {
         HideReturnsTransformationMethod method0 = HideReturnsTransformationMethod.getInstance();
         assertNotNull(method0);
@@ -42,9 +53,10 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testGetReplacement() {
         MyHideReturnsTranformationMethod method = new MyHideReturnsTranformationMethod();
-        TextMethodUtils.assertEquals(new char[] { '\uFEFF' }, method.getReplacement());
+        assertArrayEquals(new char[] { '\uFEFF' }, method.getReplacement());
     }
 
     private static class MyHideReturnsTranformationMethod extends HideReturnsTransformationMethod {
diff --git a/tests/tests/text/src/android/text/method/cts/KeyListenerCtsActivity.java b/tests/tests/text/src/android/text/method/cts/KeyListenerCtsActivity.java
index 857c659..9c96519 100644
--- a/tests/tests/text/src/android/text/method/cts/KeyListenerCtsActivity.java
+++ b/tests/tests/text/src/android/text/method/cts/KeyListenerCtsActivity.java
@@ -56,7 +56,7 @@
 
 public class KeyListenerCtsActivity extends Activity {
     private boolean mHasWindowFocus = false;
-    private Object mHasWindowFocusLock = new Object();
+    private final Object mHasWindowFocusLock = new Object();
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
diff --git a/tests/tests/text/src/android/text/method/cts/KeyListenerTestCase.java b/tests/tests/text/src/android/text/method/cts/KeyListenerTestCase.java
index 483835d..2f4b250 100644
--- a/tests/tests/text/src/android/text/method/cts/KeyListenerTestCase.java
+++ b/tests/tests/text/src/android/text/method/cts/KeyListenerTestCase.java
@@ -17,55 +17,36 @@
 package android.text.method.cts;
 
 import android.app.Instrumentation;
-import android.test.ActivityInstrumentationTestCase2;
+import android.cts.util.PollingCheck;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.rule.ActivityTestRule;
 import android.text.cts.R;
-import android.text.format.DateUtils;
 import android.text.method.KeyListener;
 import android.view.KeyEvent;
 import android.widget.EditText;
 
+import org.junit.Before;
+import org.junit.Rule;
+
 /**
  * Base class for various KeyListener tests.
- * {@link BaseKeyListenerTest}
- * {@link DateKeyListenerTest}
- * {@link DateTimeKeyListenerTest}
- * {@link DigitsKeyListenerTest}
- * {@link MultiTapKeyListenerTest}
- * {@link NumberKeyListenerTest}
- * {@link QwertyKeyListenerTest}
- * {@link TextKeyListenerTest}
- *
- * @see BaseKeyListenerTest
- * @see DateKeyListenerTest
- * @see DateTimeKeyListenerTest
- * @see DigitsKeyListenerTest
- * @see MultiTapKeyListenerTest
- * @see NumberKeyListenerTest
- * @see QwertyKeyListenerTest
- * @see TextKeyListenerTest
  */
-public abstract class KeyListenerTestCase extends
-        ActivityInstrumentationTestCase2<KeyListenerCtsActivity> {
+public abstract class KeyListenerTestCase {
     protected KeyListenerCtsActivity mActivity;
     protected Instrumentation mInstrumentation;
     protected EditText mTextView;
 
-    public KeyListenerTestCase() {
-        super("com.android.cts.text", KeyListenerCtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<KeyListenerCtsActivity> mActivityRule =
+            new ActivityTestRule<>(KeyListenerCtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        mActivity = getActivity();
-        mInstrumentation = getInstrumentation();
+    @Before
+    public void setup() {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mActivity = mActivityRule.getActivity();
         mTextView = (EditText) mActivity.findViewById(R.id.keylistener_textview);
 
-        // Ensure that the screen is on for this test.
-        mInstrumentation.runOnMainSync(() -> mTextView.setKeepScreenOn(true));
-        mInstrumentation.waitForIdleSync();
-        assertTrue(mActivity.waitForWindowFocus(5 * DateUtils.SECOND_IN_MILLIS));
+        PollingCheck.waitFor(5000, mActivity::hasWindowFocus);
     }
 
     /**
diff --git a/tests/tests/text/src/android/text/method/cts/LinkMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/LinkMovementMethodTest.java
index 34533f9..e7c411a 100644
--- a/tests/tests/text/src/android/text/method/cts/LinkMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/LinkMovementMethodTest.java
@@ -16,10 +16,26 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
+import android.app.Activity;
 import android.os.SystemClock;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Selection;
 import android.text.Spannable;
 import android.text.SpannableString;
@@ -34,8 +50,10 @@
 import android.widget.TextView;
 import android.widget.TextView.BufferType;
 
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 /**
  * Test {@link LinkMovementMethod}. The class is an implementation of interface
@@ -45,35 +63,33 @@
  *
  * @see android.widget.cts.TextViewTest
  */
-public class LinkMovementMethodTest extends
-        ActivityInstrumentationTestCase2<CtsActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class LinkMovementMethodTest {
     private static final String CONTENT = "clickable\nunclickable\nclickable";
 
+    private Activity mActivity;
     private LinkMovementMethod mMethod;
-
     private TextView mView;
-
     private Spannable mSpannable;
-
     private ClickableSpan mClickable0;
-
     private ClickableSpan mClickable1;
 
-    public LinkMovementMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setup() throws Throwable {
+        mActivity = mActivityRule.getActivity();
         mMethod = new LinkMovementMethod();
 
         // Set the content view with a text view which contains 3 lines,
-        mView = new TextViewNoIme(getActivity());
+        mActivityRule.runOnUiThread(() -> mView = new TextViewNoIme(mActivity));
         mView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
         mView.setText(CONTENT, BufferType.SPANNABLE);
-        getInstrumentation().runOnMainSync(() -> getActivity().setContentView(mView));
-        getInstrumentation().waitForIdleSync();
+
+        mActivityRule.runOnUiThread(() -> mActivity.setContentView(mView));
+        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
 
         mSpannable = (Spannable) mView.getText();
         // make first line clickable
@@ -82,10 +98,12 @@
         mClickable1 = markClickable(CONTENT.lastIndexOf('\n'), CONTENT.length());
     }
 
+    @Test
     public void testConstructor() {
         new LinkMovementMethod();
     }
 
+    @Test
     public void testGetInstance() {
         MovementMethod method0 = LinkMovementMethod.getInstance();
         assertTrue(method0 instanceof LinkMovementMethod);
@@ -95,13 +113,15 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testOnTakeFocus() {
         LinkMovementMethod method = new LinkMovementMethod();
         Spannable spannable = new SpannableString("test sequence");
         Selection.setSelection(spannable, 0, spannable.length());
 
         assertSelection(spannable, 0, spannable.length());
-        assertTrue("Expected at least 2 spans", 2 <= spannable.getSpans(0, spannable.length(), Object.class).length);
+        assertTrue("Expected at least 2 spans",
+                2 <= spannable.getSpans(0, spannable.length(), Object.class).length);
         method.onTakeFocus(null, spannable, View.FOCUS_UP);
         assertSelection(spannable, -1);
         assertEquals(1, spannable.getSpans(0, spannable.length(), Object.class).length);
@@ -113,7 +133,8 @@
         // focus forwards
         Selection.setSelection(spannable, 0, spannable.length());
         assertSelection(spannable, 0, spannable.length());
-        assertTrue("Expected at least 3 spans", 3 <= spannable.getSpans(0, spannable.length(), Object.class).length);
+        assertTrue("Expected at least 3 spans",
+                3 <= spannable.getSpans(0, spannable.length(), Object.class).length);
         method.onTakeFocus(null, spannable, View.FOCUS_RIGHT);
         assertSelection(spannable, -1);
         assertEquals(0, spannable.getSpans(0, spannable.length(), Object.class).length);
@@ -123,21 +144,23 @@
         // param direction is unknown(0)
         Selection.setSelection(spannable, 0, spannable.length());
         assertSelection(spannable, 0, spannable.length());
-        assertTrue("Expected at least 3 spans", 3 <= spannable.getSpans(0, spannable.length(), Object.class).length);
+        assertTrue("Expected at least 3 spans",
+                3 <= spannable.getSpans(0, spannable.length(), Object.class).length);
         method.onTakeFocus(null, spannable, 0);
         assertSelection(spannable, -1);
         assertEquals(0, spannable.getSpans(0, spannable.length(), Object.class).length);
-
-        // null parameters
-        try {
-            method.onTakeFocus(new TextViewNoIme(getActivity()), null, View.FOCUS_RIGHT);
-            fail("The method did not throw NullPointerException when param spannable is null.");
-        } catch (NullPointerException e) {
-            // expected
-        }
     }
 
     @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testOnTakeFocusNullSpannable() {
+        LinkMovementMethod method = new LinkMovementMethod();
+
+        method.onTakeFocus(new TextViewNoIme(mActivity), null, View.FOCUS_RIGHT);
+    }
+
+    @UiThreadTest
+    @Test
     public void testOnKeyDown() {
         // no selection
         assertSelection(mSpannable, -1);
@@ -225,17 +248,20 @@
         }
     }
 
+    @UiThreadTest
+    @Test
     public void testOnKeyUp() {
         LinkMovementMethod method = new LinkMovementMethod();
         // always returns false
         assertFalse(method.onKeyUp(null, null, 0, null));
-        assertFalse(method.onKeyUp(new TextViewNoIme(getActivity()), null, 0, null));
+        assertFalse(method.onKeyUp(new TextViewNoIme(mActivity), null, 0, null));
         assertFalse(method.onKeyUp(null, new SpannableString("blahblah"), 0, null));
         assertFalse(method.onKeyUp(null, null, KeyEvent.KEYCODE_0,
                 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0)));
     }
 
     @UiThreadTest
+    @Test
     public void testOnTouchEvent() {
         assertSelection(mSpannable, -1);
 
@@ -297,6 +323,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testUp() {
         final MyLinkMovementMethod method = new MyLinkMovementMethod();
         assertSelection(mSpannable, -1);
@@ -327,6 +354,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testDown() {
         final MyLinkMovementMethod method = new MyLinkMovementMethod();
         assertSelection(mSpannable, -1);
@@ -357,6 +385,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testLeft() {
         final MyLinkMovementMethod method = new MyLinkMovementMethod();
         assertSelection(mSpannable, -1);
@@ -387,6 +416,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testRight() {
         final MyLinkMovementMethod method = new MyLinkMovementMethod();
         assertSelection(mSpannable, -1);
@@ -417,6 +447,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testMoveAroundUnclickable() {
         final MyLinkMovementMethod method = new MyLinkMovementMethod();
         mSpannable.removeSpan(mClickable0);
@@ -436,6 +467,7 @@
         assertSelection(mSpannable, -1);
     }
 
+    @Test
     public void testInitialize() {
         LinkMovementMethod method = new LinkMovementMethod();
         Spannable spannable = new SpannableString("test sequence");
@@ -456,11 +488,11 @@
         }
     }
 
-    private ClickableSpan markClickable(final int start, final int end) {
+    private ClickableSpan markClickable(final int start, final int end) throws Throwable {
         final ClickableSpan clickableSpan = spy(new MockClickableSpan());
-        getInstrumentation().runOnMainSync(() -> mSpannable.setSpan(clickableSpan, start, end,
+        mActivityRule.runOnUiThread(() -> mSpannable.setSpan(clickableSpan, start, end,
                 Spanned.SPAN_MARK_MARK));
-        getInstrumentation().waitForIdleSync();
+        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
         return clickableSpan;
     }
 
diff --git a/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
index 3cfa07f..2f80106 100644
--- a/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
@@ -16,9 +16,17 @@
 
 package android.text.method.cts;
 
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Editable;
 import android.text.Selection;
 import android.text.Spannable;
@@ -30,10 +38,16 @@
 import android.view.View;
 import android.widget.ImageView;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link MetaKeyKeyListener}.
  */
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class MetaKeyKeyListenerTest extends KeyListenerTestCase {
+    @Test
     public void testPressKey() {
         final CharSequence str = "123456";
         final MetaKeyKeyListener numberKeyListener = new DateKeyListener();
@@ -59,6 +73,7 @@
         assertEquals('3', content.charAt(3));
     }
 
+    @Test
     public void testReleaseKey() {
         final CharSequence str = "123456";
         final MetaKeyKeyListener numberKeyListener = new DateKeyListener();
@@ -84,6 +99,7 @@
         assertEquals(str.charAt(3), content.charAt(3));
     }
 
+    @Test
     public void testAdjustMetaAfterKeypress() {
         CharSequence str = "123456";
         Spannable content = Editable.Factory.getInstance().newEditable(str);
@@ -113,6 +129,7 @@
         assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END));
     }
 
+    @Test
     public void testAdjustMetaAfterKeypress2() {
         long state = MetaKeyKeyListener.adjustMetaAfterKeypress(MetaKeyKeyListener.META_SHIFT_ON);
         assertEquals(MetaKeyKeyListener.META_SHIFT_ON, state);
@@ -127,6 +144,7 @@
         assertEquals(0, state);
     }
 
+    @Test
     public void testResetMetaState() {
         CharSequence str = "123456";
         Spannable text = Editable.Factory.getInstance().newEditable(str);
@@ -153,6 +171,7 @@
         assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));
     }
 
+    @Test
     public void testGetMetaState() {
         assertEquals(0, MetaKeyKeyListener.getMetaState("123456"));
         assertEquals(0, MetaKeyKeyListener.getMetaState("abc"));
@@ -179,6 +198,7 @@
                 MetaKeyKeyListener.getMetaState("@#$$#^$^", MetaKeyKeyListener.META_SYM_ON));
     }
 
+    @Test
     public void testGetMetaState2() {
         assertEquals(0, MetaKeyKeyListener.getMetaState(0));
         assertEquals(MetaKeyKeyListener.META_SHIFT_ON,
@@ -193,6 +213,7 @@
                 MetaKeyKeyListener.META_SYM_ON));
     }
 
+    @Test
     public void testGetMetaState_withCharSequenceAndKeyEvent() {
         KeyEvent event = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0, 0,
                 KeyEvent.META_SHIFT_MASK);
@@ -201,6 +222,7 @@
         assertEquals(KeyEvent.META_SHIFT_MASK, MetaKeyKeyListener.getMetaState("", event));
     }
 
+    @Test
     public void testGetMetaState_withCharSequenceAndMetaAndKeyEvent() {
         KeyEvent event = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0, 0,
                 KeyEvent.META_CTRL_ON);
@@ -224,18 +246,21 @@
                 event));
     }
 
+    @Test
     public void testIsMetaTracker() {
         assertFalse(MetaKeyKeyListener.isMetaTracker("123456", new Object()));
         assertFalse(MetaKeyKeyListener.isMetaTracker("abc", new Object()));
         assertFalse(MetaKeyKeyListener.isMetaTracker("@#$$#^$^", new Object()));
     }
 
+    @Test
     public void testIsSelectingMetaTracker() {
         assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("123456", new Object()));
         assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("abc", new Object()));
         assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("@#$$#^$^", new Object()));
     }
 
+    @Test
     public void testResetLockedMeta() {
         MockMetaKeyKeyListener mockMetaKeyKeyListener = new MockMetaKeyKeyListener();
 
@@ -259,6 +284,7 @@
         }
     }
 
+    @Test
     public void testResetLockedMeta2() {
         long state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_CAP_LOCKED);
         assertEquals(0, state);
@@ -279,6 +305,7 @@
         assertEquals(MetaKeyKeyListener.META_SYM_ON, state);
     }
 
+    @Test
     public void testClearMetaKeyState() {
         final MetaKeyKeyListener numberKeyListener = new DateKeyListener();
         CharSequence str = "123456";
@@ -306,6 +333,7 @@
         assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));
     }
 
+    @Test
     public void testClearMetaKeyState2() {
         CharSequence str = "123456";
         Editable text = Editable.Factory.getInstance().newEditable(str);
@@ -332,6 +360,7 @@
         assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));
     }
 
+    @Test
     public void testClearMetaKeyState3() {
         final MetaKeyKeyListener metaKeyKeyListener = new MetaKeyKeyListener() {};
         long state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_CAP_LOCKED,
@@ -359,6 +388,7 @@
         assertEquals(MetaKeyKeyListener.META_SYM_ON, state);
     }
 
+    @Test
     public void testHandleKeyDown() {
         KeyEvent fullEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT,
                 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0);
@@ -367,6 +397,7 @@
         assertEquals(0, state);
     }
 
+    @Test
     public void testHandleKeyUp() {
         KeyEvent fullEvent = new KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT,
                 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0);
diff --git a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
index 356dfbf..b9fa8cc 100644
--- a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
@@ -16,6 +16,21 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.Selection;
 import android.text.Spannable;
@@ -25,12 +40,18 @@
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@LargeTest
+@RunWith(AndroidJUnit4.class)
 public class MultiTapKeyListenerTest extends KeyListenerTestCase {
     /**
      * time out of MultiTapKeyListener. longer than 2000ms in case the system is sluggish.
      */
     private static final long TIME_OUT = 3000;
 
+    @Test
     public void testConstructor() {
         new MultiTapKeyListener(Capitalize.NONE, true);
 
@@ -39,21 +60,24 @@
         new MultiTapKeyListener(null, false);
     }
 
-    public void testOnSpanAdded() {
-        final MockMultiTapKeyListener mockMultiTapKeyListener
-                = new MockMultiTapKeyListener(Capitalize.CHARACTERS, true);
+    @Test
+    public void testOnSpanAdded() throws Throwable {
+        final MultiTapKeyListener mockMultiTapKeyListener
+                = spy(new MultiTapKeyListener(Capitalize.CHARACTERS, true));
         final Spannable text = new SpannableStringBuilder("123456");
 
-        assertFalse(mockMultiTapKeyListener.hadAddedSpan());
-        mInstrumentation.runOnMainSync(() -> {
+        verify(mockMultiTapKeyListener, never()).onSpanAdded(any(), any(), anyInt(), anyInt());
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setKeyListener(mockMultiTapKeyListener);
             mTextView.setText(text, BufferType.EDITABLE);
         });
         mInstrumentation.waitForIdleSync();
 
-        assertTrue(mockMultiTapKeyListener.hadAddedSpan());
+        verify(mockMultiTapKeyListener, atLeastOnce()).onSpanAdded(
+                any(), any(), anyInt(), anyInt());
     }
 
+    @Test
     public void testOnSpanChanged() {
         final MultiTapKeyListener multiTapKeyListener
                 = MultiTapKeyListener.getInstance(true, Capitalize.CHARACTERS);
@@ -68,7 +92,8 @@
         }
     }
 
-    public void testOnKeyDown_capitalizeNone() {
+    @Test
+    public void testOnKeyDown_capitalizeNone() throws Throwable {
         MultiTapKeyListener keyListener = MultiTapKeyListener.getInstance(false, Capitalize.NONE);
 
         prepareEmptyTextView();
@@ -89,7 +114,8 @@
         assertEquals("hello", mTextView.getText().toString());
     }
 
-    public void testOnKeyDown_capitalizeCharacters() {
+    @Test
+    public void testOnKeyDown_capitalizeCharacters() throws Throwable {
         MultiTapKeyListener keyListener = MultiTapKeyListener.getInstance(false,
                 Capitalize.CHARACTERS);
 
@@ -111,7 +137,8 @@
         assertEquals("HELLO", mTextView.getText().toString());
     }
 
-    public void testOnKeyDown_capitalizeSentences() {
+    @Test
+    public void testOnKeyDown_capitalizeSentences() throws Throwable {
         MultiTapKeyListener keyListener = MultiTapKeyListener.getInstance(false,
                 Capitalize.SENTENCES);
 
@@ -138,7 +165,8 @@
         assertEquals("Hi. Bye", mTextView.getText().toString());
     }
 
-    public void testOnKeyDown_capitalizeWords() {
+    @Test
+    public void testOnKeyDown_capitalizeWords() throws Throwable {
         MultiTapKeyListener keyListener = MultiTapKeyListener.getInstance(false,
                 Capitalize.WORDS);
 
@@ -162,8 +190,8 @@
         assertEquals("Hi Bye", mTextView.getText().toString());
     }
 
-    private void prepareEmptyTextView() {
-        mInstrumentation.runOnMainSync(() -> {
+    private void prepareEmptyTextView() throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText("", BufferType.EDITABLE);
             Selection.setSelection(mTextView.getEditableText(), 0, 0);
         });
@@ -172,8 +200,8 @@
     }
 
     private void callOnKeyDown(final MultiTapKeyListener keyListener, final int keyCode,
-            final int numTimes) {
-        mInstrumentation.runOnMainSync(() -> {
+            final int numTimes) throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
             for (int i = 0; i < numTimes; i++) {
                 keyListener.onKeyDown(mTextView, mTextView.getEditableText(), keyCode,
                         new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
@@ -189,11 +217,12 @@
         }
     }
 
-    private void addSpace() {
-        mInstrumentation.runOnMainSync(() -> mTextView.append(" "));
+    private void addSpace() throws Throwable {
+        mActivityRule.runOnUiThread(() -> mTextView.append(" "));
         mInstrumentation.waitForIdleSync();
     }
 
+    @Test
     public void testGetInstance() {
         MultiTapKeyListener listener1 = MultiTapKeyListener.getInstance(false, Capitalize.NONE);
         MultiTapKeyListener listener2 = MultiTapKeyListener.getInstance(false, Capitalize.NONE);
@@ -209,6 +238,7 @@
         assertNotSame(listener4, listener1);
     }
 
+    @Test
     public void testOnSpanRemoved() {
         MultiTapKeyListener multiTapKeyListener =
                 new MultiTapKeyListener(Capitalize.CHARACTERS, true);
@@ -216,6 +246,7 @@
         multiTapKeyListener.onSpanRemoved(text, new Object(), 0, 0);
     }
 
+    @Test
     public void testGetInputType() {
         MultiTapKeyListener listener = MultiTapKeyListener.getInstance(false, Capitalize.NONE);
         int expected = InputType.TYPE_CLASS_TEXT;
@@ -227,27 +258,4 @@
                 | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
         assertEquals(expected, listener.getInputType());
     }
-
-    /**
-     * A mocked {@link android.text.method.MultiTapKeyListener} for testing purposes.
-     *
-     * Tracks whether {@link MockMultiTapKeyListener#onSpanAdded()} has been called.
-     */
-    private class MockMultiTapKeyListener extends MultiTapKeyListener {
-        private boolean mHadAddedSpan;
-
-        public MockMultiTapKeyListener(Capitalize cap, boolean autotext) {
-            super(cap, autotext);
-        }
-
-        @Override
-        public void onSpanAdded(Spannable s, Object what, int start, int end) {
-            mHadAddedSpan = true;
-            super.onSpanAdded(s, what, start, end);
-        }
-
-        public boolean hadAddedSpan() {
-            return mHadAddedSpan;
-        }
-    }
 }
diff --git a/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
index 8aeefb2..6852df9 100644
--- a/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
@@ -16,7 +16,15 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import android.cts.util.CtsKeyEventUtil;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Selection;
 import android.text.Spannable;
 import android.text.SpannableString;
@@ -25,7 +33,11 @@
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class NumberKeyListenerTest extends KeyListenerTestCase {
     private MockNumberKeyListener mMockNumberKeyListener;
 
@@ -37,6 +49,7 @@
      * 4. Filter "12345 Android", return "12345".
      * 5. Filter Spanned("12345 Android"), return Spanned("12345") and copy spans.
      */
+    @Test
     public void testFilter() {
         mMockNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
         String source = "Android test";
@@ -81,6 +94,7 @@
      * If one of the chars in the getAcceptedChars() can be generated by the keyCode of this
      * key event, return the char; otherwise return '\0'.
      */
+    @Test
     public void testLookup() {
         mMockNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
         KeyEvent event1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0);
@@ -100,6 +114,7 @@
         }
     }
 
+    @Test
     public void testOk() {
         mMockNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
 
@@ -119,6 +134,7 @@
      * 2. Press an unaccepted key if it exists, it will not be added.
      * 3. remove NumberKeyListener and press '0' key, '0' will not be added.
      */
+    @Test
     public void testPressKey() {
         final CharSequence text = "123456";
         final MockNumberKeyListener mockNumberKeyListener =
@@ -144,7 +160,7 @@
             assertEquals("0123456", mTextView.getText().toString());
         }
 
-        mInstrumentation.runOnMainSync(() -> {
+        mActivity.runOnUiThread(() -> {
             mTextView.setKeyListener(null);
             mTextView.requestFocus();
         });
diff --git a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
index b872a96..b8f7608 100644
--- a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
@@ -16,14 +16,31 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 import android.app.Instrumentation;
+import android.app.UiAutomation;
 import android.cts.util.CtsKeyEventUtil;
 import android.cts.util.PollingCheck;
 import android.os.ParcelFileDescriptor;
 import android.provider.Settings.SettingNotFoundException;
 import android.provider.Settings.System;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.method.PasswordTransformationMethod;
 import android.util.TypedValue;
 import android.view.KeyCharacterMap;
@@ -32,17 +49,22 @@
 import android.widget.LinearLayout;
 import android.widget.LinearLayout.LayoutParams;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.Scanner;
 
-import static org.mockito.Mockito.*;
-
 /**
  * Test {@link PasswordTransformationMethod}.
  */
-public class PasswordTransformationMethodTest extends
-        ActivityInstrumentationTestCase2<CtsActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class PasswordTransformationMethodTest {
     private static final int EDIT_TXT_ID = 1;
 
     /** original text */
@@ -52,58 +74,42 @@
     private static final String TEST_CONTENT_TRANSFORMED =
         "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
 
-    private int mPasswordPrefBackUp;
-
-    private boolean isPasswordPrefSaved;
-
+    private Instrumentation mInstrumentation;
     private CtsActivity mActivity;
-
+    private int mPasswordPrefBackUp;
+    private boolean isPasswordPrefSaved;
     private PasswordTransformationMethod mMethod;
-
     private EditText mEditText;
-
     private CharSequence mTransformedText;
 
-    private Instrumentation mInstrumentation;
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    public PasswordTransformationMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mActivity = getActivity();
-        new PollingCheck(1000) {
-            @Override
-            protected boolean check() {
-                return mActivity.hasWindowFocus();
-            }
-        }.run();
-        mInstrumentation = getInstrumentation();
+    @Before
+    public void setup() throws Throwable {
+        mActivity = mActivityRule.getActivity();
+        PollingCheck.waitFor(1000, mActivity::hasWindowFocus);
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mMethod = spy(new PasswordTransformationMethod());
-        try {
-            runTestOnUiThread(() -> {
-                EditText editText = new EditTextNoIme(mActivity);
-                editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
-                editText.setId(EDIT_TXT_ID);
-                editText.setTransformationMethod(mMethod);
-                Button button = new Button(mActivity);
-                LinearLayout layout = new LinearLayout(mActivity);
-                layout.setOrientation(LinearLayout.VERTICAL);
-                layout.addView(editText, new LayoutParams(LayoutParams.MATCH_PARENT,
-                        LayoutParams.WRAP_CONTENT));
-                layout.addView(button, new LayoutParams(LayoutParams.MATCH_PARENT,
-                        LayoutParams.WRAP_CONTENT));
-                mActivity.setContentView(layout);
-                editText.requestFocus();
-            });
-        } catch (Throwable e) {
-            fail("Exception thrown is UI thread:" + e.getMessage());
-        }
+
+        mActivityRule.runOnUiThread(() -> {
+            EditText editText = new EditTextNoIme(mActivity);
+            editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
+            editText.setId(EDIT_TXT_ID);
+            editText.setTransformationMethod(mMethod);
+            Button button = new Button(mActivity);
+            LinearLayout layout = new LinearLayout(mActivity);
+            layout.setOrientation(LinearLayout.VERTICAL);
+            layout.addView(editText, new LayoutParams(LayoutParams.MATCH_PARENT,
+                    LayoutParams.WRAP_CONTENT));
+            layout.addView(button, new LayoutParams(LayoutParams.MATCH_PARENT,
+                    LayoutParams.WRAP_CONTENT));
+            mActivity.setContentView(layout);
+            editText.requestFocus();
+        });
         mInstrumentation.waitForIdleSync();
 
-        mEditText = (EditText) getActivity().findViewById(EDIT_TXT_ID);
+        mEditText = (EditText) mActivity.findViewById(EDIT_TXT_ID);
         assertTrue(mEditText.isFocused());
 
         enableAppOps();
@@ -111,23 +117,29 @@
         switchShowPassword(true);
     }
 
+    @After
+    public void teardown() {
+        resumePasswordPref();
+    }
+
     private void enableAppOps() {
+        UiAutomation uiAutomation = mInstrumentation.getUiAutomation();
+
         StringBuilder cmd = new StringBuilder();
         cmd.append("appops set ");
-        cmd.append(mInstrumentation.getContext().getPackageName());
+        cmd.append(mActivity.getPackageName());
         cmd.append(" android:write_settings allow");
-        mInstrumentation.getUiAutomation().executeShellCommand(cmd.toString());
+        uiAutomation.executeShellCommand(cmd.toString());
 
         StringBuilder query = new StringBuilder();
         query.append("appops get ");
-        query.append(mInstrumentation.getContext().getPackageName());
+        query.append(mActivity.getPackageName());
         query.append(" android:write_settings");
         String queryStr = query.toString();
 
         String result = "No operations.";
         while (result.contains("No operations")) {
-            ParcelFileDescriptor pfd = mInstrumentation.getUiAutomation().executeShellCommand(
-                                        queryStr);
+            ParcelFileDescriptor pfd = uiAutomation.executeShellCommand(queryStr);
             InputStream inputStream = new FileInputStream(pfd.getFileDescriptor());
             result = convertStreamToString(inputStream);
         }
@@ -139,20 +151,15 @@
         }
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        resumePasswordPref();
-        super.tearDown();
-    }
-
+    @Test
     public void testConstructor() {
         new PasswordTransformationMethod();
     }
 
+    @Test
     public void testTextChangedCallBacks() throws Throwable {
-        runTestOnUiThread(() -> {
-            mTransformedText = mMethod.getTransformation(mEditText.getText(), mEditText);
-        });
+        mActivityRule.runOnUiThread(() ->
+            mTransformedText = mMethod.getTransformation(mEditText.getText(), mEditText));
 
         reset(mMethod);
         // 12-key support
@@ -171,7 +178,7 @@
 
         reset(mMethod);
 
-        runTestOnUiThread(() -> mEditText.append(" "));
+        mActivityRule.runOnUiThread(() -> mEditText.append(" "));
 
         // the appended string will not get transformed immediately
         // "***** "
@@ -186,6 +193,7 @@
                 .equals("\u2022\u2022\u2022\u2022\u2022\u2022"));
     }
 
+    @Test
     public void testGetTransformation() {
         PasswordTransformationMethod method = new PasswordTransformationMethod();
 
@@ -202,6 +210,7 @@
         }
     }
 
+    @Test
     public void testGetInstance() {
         PasswordTransformationMethod method0 = PasswordTransformationMethod.getInstance();
         assertNotNull(method0);
@@ -211,6 +220,7 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testOnFocusChanged() {
         // lose focus
         reset(mMethod);
diff --git a/tests/tests/text/src/android/text/method/cts/QwertyKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/QwertyKeyListenerTest.java
index 9fc06c2..c2e684a 100644
--- a/tests/tests/text/src/android/text/method/cts/QwertyKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/QwertyKeyListenerTest.java
@@ -16,6 +16,13 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.Selection;
 import android.text.Spannable;
@@ -25,7 +32,13 @@
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class QwertyKeyListenerTest extends KeyListenerTestCase {
+    @Test
     public void testConstructor() {
         new QwertyKeyListener(Capitalize.NONE, false);
 
@@ -34,6 +47,7 @@
         new QwertyKeyListener(null, true);
     }
 
+    @Test
     public void testOnKeyDown_capitalizeNone() {
         final QwertyKeyListener keyListener = QwertyKeyListener.getInstance(false, Capitalize.NONE);
 
@@ -55,6 +69,7 @@
         assertEquals("hello", mTextView.getText().toString());
     }
 
+    @Test
     public void testOnKeyDown_capitalizeCharacters() {
         final QwertyKeyListener keyListener = QwertyKeyListener.getInstance(false,
                 Capitalize.CHARACTERS);
@@ -77,6 +92,7 @@
         assertEquals("HELLO", mTextView.getText().toString());
     }
 
+    @Test
     public void testOnKeyDown_capitalizeSentences() {
         final QwertyKeyListener keyListener = QwertyKeyListener.getInstance(false,
                 Capitalize.SENTENCES);
@@ -105,6 +121,7 @@
         assertEquals("Hi. Bye", mTextView.getText().toString());
     }
 
+    @Test
     public void testOnKeyDown_capitalizeWords() {
         final QwertyKeyListener keyListener = QwertyKeyListener.getInstance(false,
                 Capitalize.WORDS);
@@ -146,6 +163,7 @@
         mInstrumentation.waitForIdleSync();
     }
 
+    @Test
     public void testGetInstance() {
         final QwertyKeyListener listener1 = QwertyKeyListener.getInstance(true, Capitalize.WORDS);
         final QwertyKeyListener listener2 = QwertyKeyListener.getInstance(true, Capitalize.WORDS);
@@ -162,6 +180,7 @@
         assertNotSame(listener4, listener3);
     }
 
+    @Test
     public void testGetInstanceForFullKeyboard() {
         final QwertyKeyListener listener = QwertyKeyListener.getInstanceForFullKeyboard();
 
@@ -170,6 +189,7 @@
         assertEquals(InputType.TYPE_CLASS_TEXT, listener.getInputType());
     }
 
+    @Test
     public void testMarkAsReplaced() {
         final SpannableStringBuilder content = new SpannableStringBuilder("123456");
 
@@ -189,20 +209,19 @@
         assertEquals(1, content.getSpanStart(repl[0]));
         assertEquals(2, content.getSpanEnd(repl[0]));
         assertEquals(Spannable.SPAN_EXCLUSIVE_EXCLUSIVE, content.getSpanFlags(repl[0]));
-
-        try {
-            QwertyKeyListener.markAsReplaced(null, 1, 2, "abcd");
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-        }
-
-        try {
-            QwertyKeyListener.markAsReplaced(content, 1, 2, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testMarkAsReplacedNullContent() {
+        QwertyKeyListener.markAsReplaced(null, 1, 2, "abcd");
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testMarkAsReplacedNullOriginal() {
+        QwertyKeyListener.markAsReplaced(new SpannableStringBuilder("123456"), 1, 2, null);
+    }
+
+    @Test
     public void testGetInputType() {
         QwertyKeyListener listener = QwertyKeyListener.getInstance(false, Capitalize.NONE);
         assertEquals(InputType.TYPE_CLASS_TEXT, listener.getInputType());
diff --git a/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
index ef7de09..e75271e 100644
--- a/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
@@ -16,36 +16,48 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.method.ReplacementTransformationMethod;
 import android.util.TypedValue;
 import android.widget.EditText;
 
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link ReplacementTransformationMethod}.
  */
-public class ReplacementTransformationMethodTest extends
-        ActivityInstrumentationTestCase2<CtsActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class ReplacementTransformationMethodTest {
     private final char[] ORIGINAL = new char[] { '0', '1' };
     private final char[] ORIGINAL_WITH_MORE_CHARS = new char[] { '0', '1', '2' };
     private final char[] ORIGINAL_WITH_SAME_CHARS = new char[] { '0', '0' };
     private final char[] REPLACEMENT = new char[] { '3', '4' };
     private final char[] REPLACEMENT_WITH_MORE_CHARS = new char[] { '3', '4', '5' };
     private final char[] REPLACEMENT_WITH_SAME_CHARS = new char[] { '3', '3' };
+
     private EditText mEditText;
 
-    public ReplacementTransformationMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mEditText = new EditTextNoIme(getActivity());
+    @UiThreadTest
+    @Before
+    public void setup() throws Throwable {
+        mEditText = new EditTextNoIme(mActivityRule.getActivity());
         mEditText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
     }
 
+    @Test
     public void testGetTransformation() {
         MyReplacementTransformationMethod method =
             new MyReplacementTransformationMethod(ORIGINAL, REPLACEMENT);
@@ -57,6 +69,7 @@
         // TODO cannot get transformed text from the view
     }
 
+    @Test
     public void testGetTransformationWithAbnormalCharSequence() {
         ReplacementTransformationMethod method = new MyReplacementTransformationMethod(ORIGINAL,
                 REPLACEMENT);
@@ -71,6 +84,7 @@
         assertEquals("", method.getTransformation("", null).toString());
     }
 
+    @Test
     public void testGetTransformationWithAbmornalReplacement() {
         // replacement has same chars
         ReplacementTransformationMethod method =
@@ -90,26 +104,27 @@
         // TODO cannot get transformed text from the view
     }
 
-    public void testGetTransformationWithAbmornalOriginal() {
+    @Test
+    public void testGetTransformationWithAbnormalOriginal() {
         // original has same chars
         ReplacementTransformationMethod method =
-            new MyReplacementTransformationMethod(ORIGINAL_WITH_SAME_CHARS, REPLACEMENT);
+                new MyReplacementTransformationMethod(ORIGINAL_WITH_SAME_CHARS, REPLACEMENT);
         assertEquals("414141", method.getTransformation("010101", null).toString());
 
         mEditText.setTransformationMethod(method);
         mEditText.setText("010101");
         // TODO cannot get transformed text from the view
-
-        // original has more chars than replacement
-        method = new MyReplacementTransformationMethod(ORIGINAL_WITH_MORE_CHARS, REPLACEMENT);
-        try {
-            method.getTransformation("012012012", null);
-            fail("Threre is more chars in the original than replacement.");
-        } catch (ArrayIndexOutOfBoundsException e) {
-            // expected
-        }
     }
 
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
+    public void testGetTransformationMismatchCharCount() {
+        // original has more chars than replacement
+        ReplacementTransformationMethod method =
+                new MyReplacementTransformationMethod(ORIGINAL_WITH_MORE_CHARS, REPLACEMENT);
+        method.getTransformation("012012012", null);
+    }
+
+    @Test
     public void testOnFocusChanged() {
         ReplacementTransformationMethod method = new MyReplacementTransformationMethod(ORIGINAL,
                 REPLACEMENT);
diff --git a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
index 79d52f1..a79d753 100644
--- a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
@@ -16,9 +16,22 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import android.app.Activity;
+import android.app.Instrumentation;
 import android.cts.util.WidgetTestUtils;
 import android.os.SystemClock;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout;
 import android.text.Spannable;
 import android.text.SpannableString;
@@ -34,6 +47,11 @@
 import android.widget.TextView;
 import android.widget.TextView.BufferType;
 
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link ScrollingMovementMethod}. The class is an implementation of interface
  * {@link MovementMethod}. The typical usage of {@link MovementMethod} is tested in
@@ -42,35 +60,40 @@
  *
  * @see android.widget.cts.TextViewTest
  */
-public class ScrollingMovementMethodTest extends ActivityInstrumentationTestCase2<CtsActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class ScrollingMovementMethodTest {
     private static final int LITTLE_SPACE = 20;
 
     private static final String THREE_LINES_TEXT = "first line\nsecond line\nlast line";
 
+    private Instrumentation mInstrumentation;
+    private Activity mActivity;
     private TextView mTextView;
-
     private Spannable mSpannable;
-
     private int mScaledTouchSlop;
 
-    public ScrollingMovementMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mTextView = new TextViewNoIme(getActivity());
+    @UiThreadTest
+    @Before
+    public void setup() throws Throwable {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mActivity = mActivityRule.getActivity();
+        mTextView = new TextViewNoIme(mActivity);
         mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
         mTextView.setText(THREE_LINES_TEXT, BufferType.EDITABLE);
         mSpannable = (Spannable) mTextView.getText();
-        mScaledTouchSlop = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
+        mScaledTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
     }
 
+    @Test
     public void testConstructor() {
         new ScrollingMovementMethod();
     }
 
+    @Test
     public void testGetInstance() {
         final MovementMethod method0 = ScrollingMovementMethod.getInstance();
         assertTrue(method0 instanceof ScrollingMovementMethod);
@@ -79,14 +102,15 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testOnTouchEventHorizontalMotion() throws Throwable {
         final ScrollingMovementMethod method = new ScrollingMovementMethod();
         runActionOnUiThread(() -> {
             mTextView.setText("hello world", BufferType.SPANNABLE);
             mTextView.setSingleLine();
             mSpannable = (Spannable) mTextView.getText();
-            final int width = WidgetTestUtils.convertDipToPixels(getActivity(), LITTLE_SPACE);
-            getActivity().setContentView(mTextView,
+            final int width = WidgetTestUtils.convertDipToPixels(mActivity, LITTLE_SPACE);
+            mActivity.setContentView(mTextView,
                     new LayoutParams(width, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -175,11 +199,12 @@
         }));
     }
 
+    @Test
     public void testOnTouchEventVerticalMotion() throws Throwable {
         final ScrollingMovementMethod method = new ScrollingMovementMethod();
         runActionOnUiThread(() -> {
             mTextView.setLines(1);
-            getActivity().setContentView(mTextView,
+            mActivity.setContentView(mTextView,
                     new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -268,10 +293,11 @@
         }));
     }
 
+    @Test
     public void testOnTouchEventExceptional() throws Throwable {
         runActionOnUiThread(() -> {
-            final int width = WidgetTestUtils.convertDipToPixels(getActivity(), LITTLE_SPACE);
-            getActivity().setContentView(mTextView,
+            final int width = WidgetTestUtils.convertDipToPixels(mActivity, LITTLE_SPACE);
+            mActivity.setContentView(mTextView,
                     new LayoutParams(width, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -330,31 +356,34 @@
         });
     }
 
+    @Test
     public void testCanSelectArbitrarily() {
         assertFalse(new ScrollingMovementMethod().canSelectArbitrarily());
     }
 
+    @Test
     public void testOnKeyDownVerticalMovement() throws Throwable {
-        runActionOnUiThread(() -> getActivity().setContentView(mTextView));
+        runActionOnUiThread(() -> mActivity.setContentView(mTextView));
         assertNotNull(mTextView.getLayout());
 
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
         final MyScrollingMovementMethod method = new MyScrollingMovementMethod();
         runActionOnUiThread(() -> method.onKeyDown(mTextView, null, KeyEvent.KEYCODE_DPAD_DOWN,
                 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN)));
-        assertVisibleLineInTextView(1);
+        verifyVisibleLineInTextView(1);
 
         runActionOnUiThread(() -> method.onKeyDown(mTextView, null, KeyEvent.KEYCODE_DPAD_UP,
                 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP)));
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
     }
 
+    @Test
     public void testOnKeyDownHorizontalMovement() throws Throwable {
         runActionOnUiThread(() -> {
             mTextView.setText("short");
             mTextView.setSingleLine();
-            final int width = WidgetTestUtils.convertDipToPixels(getActivity(), LITTLE_SPACE);
-            getActivity().setContentView(mTextView,
+            final int width = WidgetTestUtils.convertDipToPixels(mActivity, LITTLE_SPACE);
+            mActivity.setContentView(mTextView,
                     new LayoutParams(width, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -373,15 +402,16 @@
         assertTrue(mTextView.getScrollX() < previousScrollX);
 
         previousScrollX = mTextView.getScrollX();
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
         runActionOnUiThread(() -> assertFalse(method.onKeyDown(mTextView, mSpannable, 0,
                 new KeyEvent(KeyEvent.ACTION_DOWN, 0))));
         assertEquals(previousScrollX, mTextView.getScrollX());
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
     }
 
+    @Test
     public void testOnKeyDownExceptions() throws Throwable {
-        runActionOnUiThread(() -> getActivity().setContentView(mTextView));
+        runActionOnUiThread(() -> mActivity.setContentView(mTextView));
         assertNotNull(mTextView.getLayout());
 
         final MyScrollingMovementMethod method = new MyScrollingMovementMethod();
@@ -408,11 +438,12 @@
         });
     }
 
+    @Test
     public void testVerticalMovement() throws Throwable {
         final MyScrollingMovementMethod method = new MyScrollingMovementMethod();
         runActionOnUiThread(() -> {
             mTextView.setLines(1);
-            getActivity().setContentView(mTextView,
+            mActivity.setContentView(mTextView,
                     new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -422,42 +453,42 @@
                 mResult = method.down(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(1);
+        verifyVisibleLineInTextView(1);
 
         assertTrue(getActionResult(new ActionRunnerWithResult() {
             public void run() {
                 mResult = method.down(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(2);
+        verifyVisibleLineInTextView(2);
 
         assertFalse(getActionResult(new ActionRunnerWithResult() {
             public void run() {
                 mResult = method.down(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(2);
+        verifyVisibleLineInTextView(2);
 
         assertTrue(getActionResult(new ActionRunnerWithResult() {
             public void run() {
                 mResult = method.up(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(1);
+        verifyVisibleLineInTextView(1);
 
         assertTrue(getActionResult(new ActionRunnerWithResult() {
             public void run() {
                 mResult = method.up(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
 
         assertFalse(getActionResult(new ActionRunnerWithResult() {
             public void run() {
                 mResult = method.up(mTextView, mSpannable);
             }
         }));
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
 
         runActionOnUiThread(() -> {
             try {
@@ -486,6 +517,7 @@
         });
     }
 
+    @Test
     public void testMovementWithNullLayout() {
         assertNull(mTextView.getLayout());
         try {
@@ -531,10 +563,12 @@
         }
     }
 
+    @Test
     public void testInitialize() {
         new ScrollingMovementMethod().initialize(null, null);
     }
 
+    @Test
     public void testOnTrackballEvent() {
         final long now = SystemClock.uptimeMillis();
         final MotionEvent event = MotionEvent.obtain(now, now, 0, 2, -2, 0);
@@ -546,11 +580,13 @@
         assertFalse(mockMethod.onTrackballEvent(mTextView, null, event));
     }
 
+    @UiThreadTest
+    @Test
     public void testOnKeyUp() {
         final ScrollingMovementMethod method = new ScrollingMovementMethod();
         final SpannableString spannable = new SpannableString("Test Content");
         final KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0);
-        final TextView view = new TextViewNoIme(getActivity());
+        final TextView view = new TextViewNoIme(mActivity);
         view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
 
         assertFalse(method.onKeyUp(view, spannable, KeyEvent.KEYCODE_0, event));
@@ -561,6 +597,7 @@
         assertFalse(method.onKeyUp(view, spannable, KeyEvent.KEYCODE_0, null));
     }
 
+    @Test
     public void testOnTakeFocus() throws Throwable {
         final ScrollingMovementMethod method = new ScrollingMovementMethod();
         // wait until the text view gets layout
@@ -572,8 +609,8 @@
         }
 
         runActionOnUiThread(() -> {
-            final int height = WidgetTestUtils.convertDipToPixels(getActivity(), LITTLE_SPACE);
-            getActivity().setContentView(mTextView,
+            final int height = WidgetTestUtils.convertDipToPixels(mActivity, LITTLE_SPACE);
+            mActivity.setContentView(mTextView,
                     new LayoutParams(LayoutParams.MATCH_PARENT,
                             height));
         });
@@ -583,12 +620,12 @@
         int previousScrollY = mTextView.getScrollY();
         runActionOnUiThread(() -> method.onTakeFocus(mTextView, mSpannable, View.FOCUS_BACKWARD));
         assertTrue(mTextView.getScrollY() >= previousScrollY);
-        assertVisibleLineInTextView(2);
+        verifyVisibleLineInTextView(2);
 
         previousScrollY = mTextView.getScrollY();
         runActionOnUiThread(() -> method.onTakeFocus(mTextView, mSpannable, View.FOCUS_FORWARD));
         assertTrue(mTextView.getScrollY() <= previousScrollY);
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
 
         runActionOnUiThread(() -> {
             try {
@@ -605,14 +642,15 @@
         });
     }
 
+    @Test
     public void testHorizontalMovement() throws Throwable {
         final MyScrollingMovementMethod method = new MyScrollingMovementMethod();
         runActionOnUiThread(() -> {
             mTextView.setText("short");
             mTextView.setSingleLine();
-            final DisplayMetrics dm = getActivity().getResources().getDisplayMetrics();
+            final DisplayMetrics dm = mActivity.getResources().getDisplayMetrics();
             final int width = (int) (LITTLE_SPACE * dm.scaledDensity);
-            getActivity().setContentView(mTextView,
+            mActivity.setContentView(mTextView,
                     new LayoutParams(width, LayoutParams.WRAP_CONTENT));
         });
         assertNotNull(mTextView.getLayout());
@@ -651,24 +689,25 @@
         assertEquals(previousScrollX, mTextView.getScrollX());
     }
 
+    @Test
     public void testOnKeyOther() throws Throwable {
-        runActionOnUiThread(() -> getActivity().setContentView(mTextView));
+        runActionOnUiThread(() -> mActivity.setContentView(mTextView));
         assertNotNull(mTextView.getLayout());
 
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
         final MyScrollingMovementMethod method = new MyScrollingMovementMethod();
         runActionOnUiThread(() -> method.onKeyOther(mTextView, null,
                 new KeyEvent(0, 0, KeyEvent.ACTION_MULTIPLE,
                         KeyEvent.KEYCODE_DPAD_DOWN, 2)));
-        assertVisibleLineInTextView(1);
+        verifyVisibleLineInTextView(1);
 
         runActionOnUiThread(() -> method.onKeyOther(mTextView, null,
                 new KeyEvent(0, 0, KeyEvent.ACTION_MULTIPLE,
                         KeyEvent.KEYCODE_DPAD_UP, 2)));
-        assertVisibleLineInTextView(0);
+        verifyVisibleLineInTextView(0);
     }
 
-    private void assertVisibleLineInTextView(int line) {
+    private void verifyVisibleLineInTextView(int line) {
         final Layout layout = mTextView.getLayout();
         final int scrollY = mTextView.getScrollY();
         final int padding = mTextView.getTotalPaddingTop() + mTextView.getTotalPaddingBottom();
@@ -682,8 +721,8 @@
     }
 
     private void runActionOnUiThread(Runnable actionRunner) throws Throwable {
-        runTestOnUiThread(actionRunner);
-        getInstrumentation().waitForIdleSync();
+        mActivityRule.runOnUiThread(actionRunner);
+        mInstrumentation.waitForIdleSync();
     }
 
     private static abstract class ActionRunnerWithResult implements Runnable {
diff --git a/tests/tests/text/src/android/text/method/cts/SingleLineTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/SingleLineTransformationMethodTest.java
index 0eec6bf..5db4a6f 100644
--- a/tests/tests/text/src/android/text/method/cts/SingleLineTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/SingleLineTransformationMethodTest.java
@@ -16,25 +16,34 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
 
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.method.SingleLineTransformationMethod;
 import android.util.TypedValue;
 import android.widget.EditText;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link SingleLineTransformationMethod}.
  */
-public class SingleLineTransformationMethodTest
-        extends ActivityInstrumentationTestCase2<CtsActivity> {
-    public SingleLineTransformationMethodTest() {
-        super("android.text.cts", CtsActivity.class);
-    }
-
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SingleLineTransformationMethodTest {
+    @Test
     public void testConstructor() {
         new SingleLineTransformationMethod();
     }
 
+    @Test
     public void testGetInstance() {
         SingleLineTransformationMethod method0 = SingleLineTransformationMethod.getInstance();
         assertNotNull(method0);
@@ -43,26 +52,26 @@
         assertSame(method0, method1);
     }
 
+    @Test
     public void testGetReplacement() {
         MySingleLineTranformationMethod method = new MySingleLineTranformationMethod();
-        TextMethodUtils.assertEquals(new char[] { ' ', '\uFEFF' }, method.getReplacement());
-        TextMethodUtils.assertEquals(new char[] { '\n', '\r' }, method.getOriginal());
+        assertArrayEquals(new char[] { ' ', '\uFEFF' }, method.getReplacement());
+        assertArrayEquals(new char[] { '\n', '\r' }, method.getOriginal());
     }
 
+    @UiThreadTest
+    @Test
     public void testGetTransformation() {
         SingleLineTransformationMethod method = SingleLineTransformationMethod.getInstance();
         CharSequence result = method.getTransformation("hello\nworld\r", null);
         assertEquals("hello world\uFEFF", result.toString());
 
-        EditText editText = new EditTextNoIme(getActivity());
+        EditText editText = new EditTextNoIme(InstrumentationRegistry.getTargetContext());
         editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
         editText.setText("hello\nworld\r");
         // TODO cannot get transformed text from the view
     }
 
-    /**
-     * The Class MySingleLineTranformationMethod.
-     */
     private static class MySingleLineTranformationMethod extends SingleLineTransformationMethod {
         @Override
         protected char[] getOriginal() {
diff --git a/tests/tests/text/src/android/text/method/cts/TextKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/TextKeyListenerTest.java
index 47c0a6c..4019e2e 100644
--- a/tests/tests/text/src/android/text/method/cts/TextKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TextKeyListenerTest.java
@@ -16,8 +16,24 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
 import android.cts.util.CtsKeyEventUtil;
 import android.os.SystemClock;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.test.UiThreadTest;
 import android.text.Editable;
 import android.text.InputType;
@@ -30,20 +46,25 @@
 import android.view.KeyEvent;
 import android.widget.TextView.BufferType;
 
-import static org.mockito.Mockito.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@MediumTest
+@RunWith(AndroidJUnit4.class)
 public class TextKeyListenerTest extends KeyListenerTestCase {
     /**
      * time out of MultiTapKeyListener. longer than 2000ms in case the system is sluggish.
      */
     private static final long TIME_OUT = 3000;
 
+    @Test
     public void testConstructor() {
         new TextKeyListener(Capitalize.NONE, true);
 
         new TextKeyListener(null, true);
     }
 
+    @Test
     public void testShouldCap() {
         String str = "hello world! man";
 
@@ -68,21 +89,21 @@
         assertFalse(TextKeyListener.shouldCap(Capitalize.SENTENCES, str, 14));
         assertFalse(TextKeyListener.shouldCap(Capitalize.WORDS, str, 14));
         assertTrue(TextKeyListener.shouldCap(Capitalize.CHARACTERS, str, 14));
-
-        try {
-            TextKeyListener.shouldCap(Capitalize.WORDS, null, 16);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-        }
     }
 
-    public void testOnSpanAdded() {
+    @Test(expected=NullPointerException.class)
+    public void testShouldCapNull() {
+        TextKeyListener.shouldCap(Capitalize.WORDS, null, 16);
+    }
+
+    @Test
+    public void testOnSpanAdded() throws Throwable {
         final TextKeyListener mockTextKeyListener = spy(
                 new TextKeyListener(Capitalize.CHARACTERS, true));
         final Spannable text = new SpannableStringBuilder("123456");
 
         verify(mockTextKeyListener, never()).onSpanAdded(any(), any(), anyInt(), anyInt());
-        mInstrumentation.runOnMainSync(() -> {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setKeyListener(mockTextKeyListener);
             mTextView.setText(text, BufferType.EDITABLE);
         });
@@ -92,6 +113,7 @@
         mockTextKeyListener.release();
     }
 
+    @Test
     public void testGetInstance1() {
         TextKeyListener listener1 = TextKeyListener.getInstance(true, Capitalize.WORDS);
         TextKeyListener listener2 = TextKeyListener.getInstance(true, Capitalize.WORDS);
@@ -112,6 +134,7 @@
         listener4.release();
     }
 
+    @Test
     public void testGetInstance2() {
         TextKeyListener listener1 = TextKeyListener.getInstance();
         TextKeyListener listener2 = TextKeyListener.getInstance();
@@ -124,21 +147,23 @@
         listener2.release();
     }
 
+    @Test
     public void testOnSpanChanged() {
         TextKeyListener textKeyListener = TextKeyListener.getInstance();
         final Spannable text = new SpannableStringBuilder("123456");
         textKeyListener.onSpanChanged(text, Selection.SELECTION_END, 0, 0, 0, 0);
 
-        try {
-            textKeyListener.onSpanChanged(null, Selection.SELECTION_END, 0, 0, 0, 0);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-        }
-
         textKeyListener.release();
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testOnSpanChangedNull() {
+        TextKeyListener textKeyListener = TextKeyListener.getInstance();
+        textKeyListener.onSpanChanged(null, Selection.SELECTION_END, 0, 0, 0, 0);
+    }
+
     @UiThreadTest
+    @Test
     public void testClear() {
         CharSequence text = "123456";
         mTextView.setText(text, BufferType.EDITABLE);
@@ -150,6 +175,7 @@
         assertEquals("", content.toString());
     }
 
+    @Test
     public void testOnSpanRemoved() {
         TextKeyListener textKeyListener = new TextKeyListener(Capitalize.CHARACTERS, true);
         final Spannable text = new SpannableStringBuilder("123456");
@@ -174,11 +200,12 @@
      * 1. press KEYCODE_4 once. if it's ALPHA key board, text will be "4", if it's
      *    NUMERIC key board, text will be "g", else text will be "".
      */
-    public void testPressKey() {
+    @Test
+    public void testPressKey() throws Throwable {
         final TextKeyListener textKeyListener
                 = TextKeyListener.getInstance(false, Capitalize.NONE);
 
-        mInstrumentation.runOnMainSync(() -> {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText("", BufferType.EDITABLE);
             Selection.setSelection(mTextView.getText(), 0, 0);
             mTextView.setKeyListener(textKeyListener);
@@ -203,12 +230,13 @@
         textKeyListener.release();
     }
 
-    public void testOnKeyOther() {
+    @Test
+    public void testOnKeyOther() throws Throwable {
         final String text = "abcd";
         final TextKeyListener textKeyListener
                 = TextKeyListener.getInstance(false, Capitalize.NONE);
 
-        mInstrumentation.runOnMainSync(() -> {
+        mActivityRule.runOnUiThread(() -> {
             mTextView.setText("", BufferType.EDITABLE);
             Selection.setSelection(mTextView.getText(), 0, 0);
             mTextView.setKeyListener(textKeyListener);
@@ -227,6 +255,7 @@
         textKeyListener.release();
     }
 
+    @Test
     public void testGetInputType() {
         TextKeyListener listener = TextKeyListener.getInstance(false, Capitalize.NONE);
         int expected = InputType.TYPE_CLASS_TEXT;
@@ -239,5 +268,4 @@
 
         listener.release();
     }
-
 }
diff --git a/tests/tests/text/src/android/text/method/cts/TextMethodUtils.java b/tests/tests/text/src/android/text/method/cts/TextMethodUtils.java
index 0785cff..dbeb1e8 100644
--- a/tests/tests/text/src/android/text/method/cts/TextMethodUtils.java
+++ b/tests/tests/text/src/android/text/method/cts/TextMethodUtils.java
@@ -18,26 +18,8 @@
 
 import android.view.KeyEvent;
 
-import junit.framework.Assert;
-
 public class TextMethodUtils {
     /**
-     * Assert that two char arrays are equal.
-     *
-     * @param expected the expected char array.
-     * @param actual the actual char array.
-     */
-    public static void assertEquals(char[] expected, char[] actual) {
-        if (expected != actual) {
-            if (expected == null || actual == null) {
-                Assert.fail("the char arrays are not equal");
-            }
-
-            Assert.assertEquals(String.valueOf(expected), String.valueOf(actual));
-        }
-    }
-
-    /**
      * Get an unaccepted key code.
      *
      * @param acceptedChars accepted chars array.
diff --git a/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
index 9fed354..9515ab9 100644
--- a/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
@@ -16,18 +16,31 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
 import android.cts.util.CtsKeyEventUtil;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.InputType;
 import android.text.method.TimeKeyListener;
 import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 
-public class TimeKeyListenerTest extends KeyListenerTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class TimeKeyListenerTest extends KeyListenerTestCase {
+    @Test
     public void testConstructor() {
         new TimeKeyListener();
     }
 
+    @Test
     public void testGetInstance() {
         TimeKeyListener listener1 = TimeKeyListener.getInstance();
         TimeKeyListener listener2 = TimeKeyListener.getInstance();
@@ -37,12 +50,13 @@
         assertSame(listener1, listener2);
     }
 
+    @Test
     public void testGetAcceptedChars() {
         MockTimeKeyListener mockTimeKeyListener = new MockTimeKeyListener();
-        TextMethodUtils.assertEquals(TimeKeyListener.CHARACTERS,
-                mockTimeKeyListener.getAcceptedChars());
+        assertArrayEquals(TimeKeyListener.CHARACTERS, mockTimeKeyListener.getAcceptedChars());
     }
 
+    @Test
     public void testGetInputType() {
         TimeKeyListener listener = TimeKeyListener.getInstance();
         int expected = InputType.TYPE_CLASS_DATETIME
@@ -60,6 +74,7 @@
      * 6. Press an unaccepted key if it exists and this key could not be entered.
      * 7. Remove TimeKeyListener, '1' key will not be accepted.
      */
+    @Test
     public void testTimeKeyListener() {
         final TimeKeyListener timeKeyListener = TimeKeyListener.getInstance();
         String expectedText = "";
diff --git a/tests/tests/text/src/android/text/method/cts/TouchTest.java b/tests/tests/text/src/android/text/method/cts/TouchTest.java
index cc672f9..8bd4fda 100644
--- a/tests/tests/text/src/android/text/method/cts/TouchTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TouchTest.java
@@ -16,10 +16,17 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import android.app.Activity;
+import android.app.Instrumentation;
 import android.os.SystemClock;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout;
 import android.text.SpannableString;
 import android.text.TextPaint;
@@ -29,8 +36,14 @@
 import android.view.MotionEvent;
 import android.widget.TextView;
 
-public class TouchTest extends ActivityInstrumentationTestCase2<CtsActivity> {
-    private Activity mActivity;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class TouchTest {
     private static final String LONG_TEXT = "Scrolls the specified widget to the specified " +
             "coordinates, except constrains the X scrolling position to the horizontal regions " +
             "of the text that will be visible after scrolling to the specified Y position." +
@@ -40,62 +53,64 @@
             "of the text that will be visible after scrolling to the specified Y position." +
             "This is the description of the test.";
 
+    private Instrumentation mInstrumentation;
+    private Activity mActivity;
     private boolean mReturnFromTouchEvent;
+    private TextView mTextView;
 
-    public TouchTest() {
-        super("android.text.cts", CtsActivity.class);
+    @Rule
+    public ActivityTestRule<CtsActivity> mActivityRule = new ActivityTestRule<>(CtsActivity.class);
+
+    @UiThreadTest
+    @Before
+    public void setup() {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mActivity = mActivityRule.getActivity();
+        mTextView = new TextViewNoIme(mActivity);
+        mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mActivity = getActivity();
-    }
-
+    @Test
     public void testScrollTo() throws Throwable {
-        final TextView tv = new TextViewNoIme(mActivity);
-        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
-
-        runTestOnUiThread(() -> {
-            mActivity.setContentView(tv);
-            tv.setSingleLine(true);
-            tv.setLines(2);
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mTextView);
+            mTextView.setSingleLine(true);
+            mTextView.setLines(2);
         });
-        getInstrumentation().waitForIdleSync();
-        TextPaint paint = tv.getPaint();
-        final Layout layout = tv.getLayout();
+        mInstrumentation.waitForIdleSync();
+        TextPaint paint = mTextView.getPaint();
+        final Layout layout = mTextView.getLayout();
 
-        runTestOnUiThread(() -> tv.setText(LONG_TEXT));
-        getInstrumentation().waitForIdleSync();
+        mActivityRule.runOnUiThread(() -> mTextView.setText(LONG_TEXT));
+        mInstrumentation.waitForIdleSync();
 
         // get the total length of string
         final int width = getTextWidth(LONG_TEXT, paint);
 
-        runTestOnUiThread(() -> Touch.scrollTo(tv, layout, width - tv.getWidth() - 1, 0));
-        getInstrumentation().waitForIdleSync();
-        assertEquals(width - tv.getWidth() - 1, tv.getScrollX());
-        assertEquals(0, tv.getScrollY());
+        mActivityRule.runOnUiThread(
+                () -> Touch.scrollTo(mTextView, layout, width - mTextView.getWidth() - 1, 0));
+        mInstrumentation.waitForIdleSync();
+        assertEquals(width - mTextView.getWidth() - 1, mTextView.getScrollX());
+        assertEquals(0, mTextView.getScrollY());
 
         // the X to which scroll is greater than the total length of string.
-        runTestOnUiThread(() -> Touch.scrollTo(tv, layout, width + 100, 5));
-        getInstrumentation().waitForIdleSync();
-        assertEquals(width - tv.getWidth(), tv.getScrollX(), 1.0f);
-        assertEquals(5, tv.getScrollY());
+        mActivityRule.runOnUiThread(() -> Touch.scrollTo(mTextView, layout, width + 100, 5));
+        mInstrumentation.waitForIdleSync();
+        assertEquals(width - mTextView.getWidth(), mTextView.getScrollX(), 1.0f);
+        assertEquals(5, mTextView.getScrollY());
 
-        runTestOnUiThread(() -> Touch.scrollTo(tv, layout, width - 10, 5));
-        getInstrumentation().waitForIdleSync();
-        assertEquals(width - tv.getWidth(), tv.getScrollX(), 1.0f);
-        assertEquals(5, tv.getScrollY());
+        mActivityRule.runOnUiThread(() -> Touch.scrollTo(mTextView, layout, width - 10, 5));
+        mInstrumentation.waitForIdleSync();
+        assertEquals(width - mTextView.getWidth(), mTextView.getScrollX(), 1.0f);
+        assertEquals(5, mTextView.getScrollY());
     }
 
+    @Test
     public void testOnTouchEvent() throws Throwable {
-        final TextView tv = new TextViewNoIme(mActivity);
-        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
-
         // Create a string that is wider than the screen.
         DisplayMetrics metrics = mActivity.getResources().getDisplayMetrics();
         int screenWidth = metrics.widthPixels;
-        TextPaint paint = tv.getPaint();
+        TextPaint paint = mTextView.getPaint();
         String text = LONG_TEXT;
         int textWidth = Math.round(paint.measureText(text));
         while (textWidth < screenWidth) {
@@ -108,12 +123,12 @@
         assertTrue(dragAmount > 0);
         final String finalText = text;
         final SpannableString spannable = new SpannableString(finalText);
-        runTestOnUiThread(() -> {
-            mActivity.setContentView(tv);
-            tv.setSingleLine(true);
-            tv.setText(finalText);
+        mActivityRule.runOnUiThread(() -> {
+            mActivity.setContentView(mTextView);
+            mTextView.setSingleLine(true);
+            mTextView.setText(finalText);
         });
-        getInstrumentation().waitForIdleSync();
+        mInstrumentation.waitForIdleSync();
 
         long downTime = SystemClock.uptimeMillis();
         long eventTime = SystemClock.uptimeMillis();
@@ -123,37 +138,40 @@
                 MotionEvent.ACTION_MOVE, 0, 0, 0);
         final MotionEvent event3 = MotionEvent.obtain(downTime, eventTime,
                 MotionEvent.ACTION_UP, 0, 0, 0);
-        assertEquals(0, tv.getScrollX());
-        assertEquals(0, tv.getScrollY());
+        assertEquals(0, mTextView.getScrollX());
+        assertEquals(0, mTextView.getScrollY());
         mReturnFromTouchEvent = false;
-        runTestOnUiThread(() -> mReturnFromTouchEvent = Touch.onTouchEvent(tv, spannable, event1));
-        getInstrumentation().waitForIdleSync();
+        mActivityRule.runOnUiThread(
+                () -> mReturnFromTouchEvent = Touch.onTouchEvent(mTextView, spannable, event1));
+        mInstrumentation.waitForIdleSync();
         assertTrue(mReturnFromTouchEvent);
         // TextView has not been scrolled.
-        assertEquals(0, tv.getScrollX());
-        assertEquals(0, tv.getScrollY());
-        assertEquals(0, Touch.getInitialScrollX(tv, spannable));
-        assertEquals(0, Touch.getInitialScrollY(tv, spannable));
+        assertEquals(0, mTextView.getScrollX());
+        assertEquals(0, mTextView.getScrollY());
+        assertEquals(0, Touch.getInitialScrollX(mTextView, spannable));
+        assertEquals(0, Touch.getInitialScrollY(mTextView, spannable));
 
         mReturnFromTouchEvent = false;
-        runTestOnUiThread(() -> mReturnFromTouchEvent = Touch.onTouchEvent(tv, spannable, event2));
-        getInstrumentation().waitForIdleSync();
+        mActivityRule.runOnUiThread(
+                () -> mReturnFromTouchEvent = Touch.onTouchEvent(mTextView, spannable, event2));
+        mInstrumentation.waitForIdleSync();
         assertTrue(mReturnFromTouchEvent);
         // TextView has been scrolled.
-        assertEquals(dragAmount, tv.getScrollX());
-        assertEquals(0, tv.getScrollY());
-        assertEquals(0, Touch.getInitialScrollX(tv, spannable));
-        assertEquals(0, Touch.getInitialScrollY(tv, spannable));
+        assertEquals(dragAmount, mTextView.getScrollX());
+        assertEquals(0, mTextView.getScrollY());
+        assertEquals(0, Touch.getInitialScrollX(mTextView, spannable));
+        assertEquals(0, Touch.getInitialScrollY(mTextView, spannable));
 
         mReturnFromTouchEvent = false;
-        runTestOnUiThread(() -> mReturnFromTouchEvent = Touch.onTouchEvent(tv, spannable, event3));
-        getInstrumentation().waitForIdleSync();
+        mActivityRule.runOnUiThread(
+                () -> mReturnFromTouchEvent = Touch.onTouchEvent(mTextView, spannable, event3));
+        mInstrumentation.waitForIdleSync();
         assertTrue(mReturnFromTouchEvent);
         // TextView has not been scrolled.
-        assertEquals(dragAmount, tv.getScrollX());
-        assertEquals(0, tv.getScrollY());
-        assertEquals(-1, Touch.getInitialScrollX(tv, spannable));
-        assertEquals(-1, Touch.getInitialScrollY(tv, spannable));
+        assertEquals(dragAmount, mTextView.getScrollX());
+        assertEquals(0, mTextView.getScrollY());
+        assertEquals(-1, Touch.getInitialScrollX(mTextView, spannable));
+        assertEquals(-1, Touch.getInitialScrollY(mTextView, spannable));
     }
 
     private int getTextWidth(String str, TextPaint paint) {
diff --git a/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java b/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java
index e042a00..ab524a7 100644
--- a/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java
+++ b/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java
@@ -16,117 +16,128 @@
 
 package android.text.method.cts;
 
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.method.WordIterator;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.text.BreakIterator;
 
-public class WordIteratorTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class WordIteratorTest {
+    private WordIterator mWordIterator = new WordIterator();
 
-    WordIterator wi = new WordIterator();
-
-    private void checkIsWordWithSurrogate(int beginning, int end, int surrogateIndex) {
+    private void verifyIsWordWithSurrogate(int beginning, int end, int surrogateIndex) {
         for (int i = beginning; i <= end; i++) {
             if (i == surrogateIndex) continue;
-            assertEquals(beginning, wi.getBeginning(i));
-            assertEquals(end, wi.getEnd(i));
+            assertEquals(beginning, mWordIterator.getBeginning(i));
+            assertEquals(end, mWordIterator.getEnd(i));
         }
     }
 
     private void setCharSequence(String string) {
-        wi.setCharSequence(string, 0, string.length());
+        mWordIterator.setCharSequence(string, 0, string.length());
     }
 
-    private void checkIsWord(int beginning, int end) {
-        checkIsWordWithSurrogate(beginning, end, -1);
+    private void verifyIsWord(int beginning, int end) {
+        verifyIsWordWithSurrogate(beginning, end, -1);
     }
 
-    private void checkIsNotWord(int beginning, int end) {
+    private void verifyIsNotWord(int beginning, int end) {
         for (int i = beginning; i <= end; i++) {
-            assertEquals(BreakIterator.DONE, wi.getBeginning(i));
-            assertEquals(BreakIterator.DONE, wi.getEnd(i));
+            assertEquals(BreakIterator.DONE, mWordIterator.getBeginning(i));
+            assertEquals(BreakIterator.DONE, mWordIterator.getEnd(i));
         }
     }
 
+    @Test
     public void testEmptyString() {
         setCharSequence("");
-        assertEquals(BreakIterator.DONE, wi.following(0));
-        assertEquals(BreakIterator.DONE, wi.preceding(0));
+        assertEquals(BreakIterator.DONE, mWordIterator.following(0));
+        assertEquals(BreakIterator.DONE, mWordIterator.preceding(0));
 
-        assertEquals(BreakIterator.DONE, wi.getBeginning(0));
-        assertEquals(BreakIterator.DONE, wi.getEnd(0));
+        assertEquals(BreakIterator.DONE, mWordIterator.getBeginning(0));
+        assertEquals(BreakIterator.DONE, mWordIterator.getEnd(0));
     }
 
+    @Test
     public void testOneWord() {
         setCharSequence("I");
-        checkIsWord(0, 1);
+        verifyIsWord(0, 1);
 
         setCharSequence("am");
-        checkIsWord(0, 2);
+        verifyIsWord(0, 2);
 
         setCharSequence("zen");
-        checkIsWord(0, 3);
+        verifyIsWord(0, 3);
     }
 
+    @Test
     public void testSpacesOnly() {
         setCharSequence(" ");
-        checkIsNotWord(0, 1);
+        verifyIsNotWord(0, 1);
 
         setCharSequence(", ");
-        checkIsNotWord(0, 2);
+        verifyIsNotWord(0, 2);
 
         setCharSequence(":-)");
-        checkIsNotWord(0, 3);
+        verifyIsNotWord(0, 3);
     }
 
+    @Test
     public void testBeginningEnd() {
         setCharSequence("Well hello,   there! ");
         //                  0123456789012345678901
-        checkIsWord(0, 4);
-        checkIsWord(5, 10);
-        checkIsNotWord(11, 13);
-        checkIsWord(14, 19);
-        checkIsNotWord(20, 21);
+        verifyIsWord(0, 4);
+        verifyIsWord(5, 10);
+        verifyIsNotWord(11, 13);
+        verifyIsWord(14, 19);
+        verifyIsNotWord(20, 21);
 
         setCharSequence("  Another - sentence");
         //                  012345678901234567890
-        checkIsNotWord(0, 1);
-        checkIsWord(2, 9);
-        checkIsNotWord(10, 11);
-        checkIsWord(12, 20);
+        verifyIsNotWord(0, 1);
+        verifyIsWord(2, 9);
+        verifyIsNotWord(10, 11);
+        verifyIsWord(12, 20);
 
         setCharSequence("This is \u0644\u0627 tested"); // Lama-aleph
         //                  012345678     9     01234567
-        checkIsWord(0, 4);
-        checkIsWord(5, 7);
-        checkIsWord(8, 10);
-        checkIsWord(11, 17);
+        verifyIsWord(0, 4);
+        verifyIsWord(5, 7);
+        verifyIsWord(8, 10);
+        verifyIsWord(11, 17);
     }
 
+    @Test
     public void testSurrogate() {
         final String BAIRKAN = "\uD800\uDF31";
 
         setCharSequence("one we" + BAIRKAN + "ird word");
         //                  012345    67         890123456
 
-        checkIsWord(0, 3);
+        verifyIsWord(0, 3);
         // Skip index 7 (there is no point in starting between the two surrogate characters)
-        checkIsWordWithSurrogate(4, 11, 7);
-        checkIsWord(12, 16);
+        verifyIsWordWithSurrogate(4, 11, 7);
+        verifyIsWord(12, 16);
 
         setCharSequence("one " + BAIRKAN + "xxx word");
         //                  0123    45         678901234
 
-        checkIsWord(0, 3);
-        checkIsWordWithSurrogate(4, 9, 5);
-        checkIsWord(10, 14);
+        verifyIsWord(0, 3);
+        verifyIsWordWithSurrogate(4, 9, 5);
+        verifyIsWord(10, 14);
 
         setCharSequence("one xxx" + BAIRKAN + " word");
         //                  0123456    78         901234
 
-        checkIsWord(0, 3);
-        checkIsWordWithSurrogate(4, 9, 8);
-        checkIsWord(10, 14);
+        verifyIsWord(0, 3);
+        verifyIsWordWithSurrogate(4, 9, 8);
+        verifyIsWord(10, 14);
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/AbsoluteSizeSpanTest.java b/tests/tests/text/src/android/text/style/cts/AbsoluteSizeSpanTest.java
index e825bd1..ac04619 100644
--- a/tests/tests/text/src/android/text/style/cts/AbsoluteSizeSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/AbsoluteSizeSpanTest.java
@@ -16,14 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.AbsoluteSizeSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class AbsoluteSizeSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AbsoluteSizeSpanTest {
+    @Test
     public void testConstructor() {
         new AbsoluteSizeSpan(0);
         new AbsoluteSizeSpan(-5);
@@ -39,6 +47,7 @@
         }
     }
 
+    @Test
     public void testGetSize() {
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(5);
         assertEquals(5, absoluteSizeSpan.getSize());
@@ -47,64 +56,73 @@
         assertEquals(-5, absoluteSizeSpan.getSize());
     }
 
+    @Test
     public void testGetDip() {
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(5);
         assertEquals(false, absoluteSizeSpan.getDip());
 
         absoluteSizeSpan = new AbsoluteSizeSpan(5, true);
-        assertEquals(true, absoluteSizeSpan.getDip());
+        assertTrue(absoluteSizeSpan.getDip());
     }
 
+    @Test
     public void testUpdateMeasureState() {
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(1);
 
         TextPaint tp = new TextPaint();
         absoluteSizeSpan.updateMeasureState(tp);
-        assertEquals(1.0f, tp.getTextSize());
+        assertEquals(1.0f, tp.getTextSize(), 0.0f);
 
         absoluteSizeSpan = new AbsoluteSizeSpan(10);
         absoluteSizeSpan.updateMeasureState(tp);
-        assertEquals(10.0f, tp.getTextSize());
-
-        try {
-            absoluteSizeSpan.updateMeasureState(null);
-            fail("should throw NullPointerException when TextPaint is null.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(10.0f, tp.getTextSize(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        // Should throw NullPointerException when TextPaint is null
+        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(1);
+
+        absoluteSizeSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         // new the AbsoluteSizeSpan instance
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(2);
 
         TextPaint tp = new TextPaint();
         absoluteSizeSpan.updateDrawState(tp);
-        assertEquals(2.0f, tp.getTextSize());
+        assertEquals(2.0f, tp.getTextSize(), 0.0f);
 
         // new the AbsoluteSizeSpan instance
         absoluteSizeSpan = new AbsoluteSizeSpan(20);
         absoluteSizeSpan.updateDrawState(tp);
-        assertEquals(20.0f, tp.getTextSize());
-
-        try {
-            absoluteSizeSpan.updateDrawState(null);
-            fail("should throw NullPointerException when TextPaint is null.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(20.0f, tp.getTextSize(), 0.0f);
     }
 
+
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        // Should throw NullPointerException when TextPaint is null
+        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(2);
+
+        absoluteSizeSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(2);
         absoluteSizeSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(2);
         absoluteSizeSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/AlignmentSpan_StandardTest.java b/tests/tests/text/src/android/text/style/cts/AlignmentSpan_StandardTest.java
index 26ed21e..78bcd6a 100644
--- a/tests/tests/text/src/android/text/style/cts/AlignmentSpan_StandardTest.java
+++ b/tests/tests/text/src/android/text/style/cts/AlignmentSpan_StandardTest.java
@@ -16,17 +16,24 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout.Alignment;
 import android.text.style.AlignmentSpan.Standard;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 /**
  * Test {@link Standard}.
  */
-public class AlignmentSpan_StandardTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class AlignmentSpan_StandardTest {
+    @Test
     public void testConstructor() {
         new Standard(Alignment.ALIGN_CENTER);
 
@@ -41,6 +48,7 @@
         }
     }
 
+    @Test
     public void testGetAlignment() {
         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
         assertEquals(Alignment.ALIGN_NORMAL, standard.getAlignment());
@@ -52,16 +60,19 @@
         assertEquals(Alignment.ALIGN_CENTER, standard.getAlignment());
     }
 
+    @Test
     public void testDescribeContents() {
         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
         standard.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
         standard.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/BackgroundColorSpanTest.java b/tests/tests/text/src/android/text/style/cts/BackgroundColorSpanTest.java
index 690da5d..2724dfe 100644
--- a/tests/tests/text/src/android/text/style/cts/BackgroundColorSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/BackgroundColorSpanTest.java
@@ -16,15 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.graphics.Color;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.BackgroundColorSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class BackgroundColorSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BackgroundColorSpanTest {
+    @Test
     public void testConstructor() {
         BackgroundColorSpan b = new BackgroundColorSpan(Color.GREEN);
 
@@ -38,6 +45,7 @@
         }
     }
 
+    @Test
     public void testUpdateDrawState() {
         BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.BLACK);
 
@@ -48,15 +56,16 @@
         backgroundColorSpan = new BackgroundColorSpan(Color.BLUE);
         backgroundColorSpan.updateDrawState(tp);
         assertEquals(Color.BLUE, tp.bgColor);
-
-        try {
-            backgroundColorSpan.updateDrawState(null);
-            fail("did not throw NullPointerException when TextPaint is null.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.BLACK);
+
+        backgroundColorSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testGetBackgroundColor() {
         BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.CYAN);
         assertEquals(Color.CYAN, backgroundColorSpan.getBackgroundColor());
@@ -65,16 +74,19 @@
         assertEquals(Color.GRAY, backgroundColorSpan.getBackgroundColor());
     }
 
+    @Test
     public void testDescribeContents() {
         BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.RED);
         backgroundColorSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.RED);
         backgroundColorSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/BulletSpanTest.java b/tests/tests/text/src/android/text/style/cts/BulletSpanTest.java
index 18add4e..4d1985b 100644
--- a/tests/tests/text/src/android/text/style/cts/BulletSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/BulletSpanTest.java
@@ -16,18 +16,25 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertTrue;
 
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Html;
 import android.text.Spanned;
 import android.text.style.BulletSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class BulletSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BulletSpanTest {
+    @Test
     public void testConstructor() {
         new BulletSpan();
         new BulletSpan(BulletSpan.STANDARD_GAP_WIDTH);
@@ -43,6 +50,7 @@
         }
     }
 
+    @Test
     public void testGetLeadingMargin() {
         BulletSpan bulletSpan = new BulletSpan(1);
         int leadingMargin1 = bulletSpan.getLeadingMargin(true);
@@ -53,6 +61,7 @@
         assertTrue(leadingMargin2 > leadingMargin1);
     }
 
+    @Test
     public void testDrawLeadingMargin() {
         BulletSpan bulletSpan = new BulletSpan(10, 20);
 
@@ -63,36 +72,36 @@
         bulletSpan.drawLeadingMargin(canvas, paint, 10, 0, 10, 0, 20, text, 0, 0, true, null);
     }
 
-    public void testDrawLeadingMarginFailure() {
-        // new the BulletSpan instance
+    @Test(expected=ClassCastException.class)
+    public void testDrawLeadingMarginString() {
         BulletSpan bulletSpan = new BulletSpan(10, 20);
 
-        try {
-            String text = "cts test.";
-            bulletSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, text, 0, 0, true, null);
-            fail("did not throw ClassCastException when use a String as text");
-        } catch (ClassCastException e) {
-            // expected, test success.
-        }
-
-        try {
-            bulletSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, null, 0, 0, false, null);
-            fail("did not throw NullPointerException when text is null");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        String text = "cts test.";
+        // Should throw ClassCastException when use a String as text
+        bulletSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, text, 0, 0, true, null);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testDrawLeadingMarginNull() {
+        BulletSpan bulletSpan = new BulletSpan(10, 20);
+
+        // Should throw NullPointerException when text is null
+        bulletSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, null, 0, 0, false, null);
+    }
+
+    @Test
     public void testDescribeContents() {
         BulletSpan bulletSpan = new BulletSpan();
         bulletSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         BulletSpan bulletSpan = new BulletSpan();
         bulletSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         int leadingMargin1 = 0;
         int leadingMargin2 = 0;
diff --git a/tests/tests/text/src/android/text/style/cts/CharacterStyleTest.java b/tests/tests/text/src/android/text/style/cts/CharacterStyleTest.java
index 49a811f..791f362 100644
--- a/tests/tests/text/src/android/text/style/cts/CharacterStyleTest.java
+++ b/tests/tests/text/src/android/text/style/cts/CharacterStyleTest.java
@@ -16,15 +16,25 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.CharacterStyle;
 import android.text.style.MetricAffectingSpan;
 import android.text.style.SuperscriptSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class CharacterStyleTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class CharacterStyleTest {
+    @Test
     public void testWrap() {
         // use a MetricAffectingSpan
         MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan();
@@ -51,6 +61,7 @@
         assertTrue(result instanceof CharacterStyle);
     }
 
+    @Test
     public void testGetUnderlying() {
         CharacterStyle expected = new MyCharacterStyle();
         assertSame(expected, expected.getUnderlying());
@@ -62,13 +73,9 @@
         assertSame(metricAffectingSpan, result.getUnderlying());
     }
 
-    /**
-     * MyCharacterStyle for test.
-     */
     private class MyCharacterStyle extends CharacterStyle {
         @Override
         public void updateDrawState(TextPaint tp) {
-            // implement abstract method.
         }
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/ClickableSpanTest.java b/tests/tests/text/src/android/text/style/cts/ClickableSpanTest.java
index 3ef6562..a00a28d 100644
--- a/tests/tests/text/src/android/text/style/cts/ClickableSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ClickableSpanTest.java
@@ -16,15 +16,24 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.graphics.Color;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.ClickableSpan;
 import android.view.View;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class ClickableSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ClickableSpanTest {
+    @Test
     public void testUpdateDrawState() {
         ClickableSpan clickableSpan = new MyClickableSpan();
 
@@ -41,22 +50,19 @@
         clickableSpan.updateDrawState(tp);
         assertEquals(Color.BLUE, tp.getColor());
         assertTrue(tp.isUnderlineText());
-
-        try {
-            clickableSpan.updateDrawState(null);
-            fail("should throw NullPointerException when TextPaint is null.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
-    /**
-     * MyClickableSpan for test.
-     */
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        ClickableSpan clickableSpan = new MyClickableSpan();
+
+        // Should throw NullPointerException when TextPaint is null
+        clickableSpan.updateDrawState(null);
+    }
+
     private class MyClickableSpan extends ClickableSpan {
         @Override
         public void onClick(View widget) {
-            // implement abstract method.
         }
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/DrawableMarginSpanTest.java b/tests/tests/text/src/android/text/style/cts/DrawableMarginSpanTest.java
index 4b88979..4ccf3bd 100644
--- a/tests/tests/text/src/android/text/style/cts/DrawableMarginSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/DrawableMarginSpanTest.java
@@ -16,10 +16,16 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Paint.FontMetricsInt;
 import android.graphics.drawable.Drawable;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Html;
 import android.text.Layout;
 import android.text.Spanned;
@@ -28,39 +34,54 @@
 import android.text.cts.R;
 import android.text.style.DrawableMarginSpan;
 
-public class DrawableMarginSpanTest extends AndroidTestCase {
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class DrawableMarginSpanTest {
+    private Context mContext;
+    private Drawable mDrawable;
+
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
+        mDrawable = mContext.getDrawable(R.drawable.scenery);
+    }
+
+    @Test
     public void testConstructor() {
-        Drawable d = mContext.getResources().getDrawable(R.drawable.pass);
+        Drawable d = mContext.getDrawable(R.drawable.pass);
 
         new DrawableMarginSpan(d);
         new DrawableMarginSpan(d, 1);
         new DrawableMarginSpan(null, -1);
     }
 
+    @Test
     public void testGetLeadingMargin() {
-        Drawable drawable = mContext.getResources().getDrawable(R.drawable.scenery);
-
-        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(drawable, 1);
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 1);
         int leadingMargin1 = drawableMarginSpan.getLeadingMargin(true);
 
-        drawableMarginSpan = new DrawableMarginSpan(drawable, 10);
+        drawableMarginSpan = new DrawableMarginSpan(mDrawable, 10);
         int leadingMargin2 = drawableMarginSpan.getLeadingMargin(true);
 
         assertTrue(leadingMargin2 > leadingMargin1);
     }
 
+    @Test
     public void testDrawLeadingMargin() {
-        Drawable drawable = mContext.getResources().getDrawable(R.drawable.scenery);
-        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(drawable, 0);
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
 
-        assertEquals(0, drawable.getBounds().top);
-        assertEquals(0, drawable.getBounds().bottom);
-        assertEquals(0, drawable.getBounds().left);
-        assertEquals(0, drawable.getBounds().right);
+        assertEquals(0, mDrawable.getBounds().top);
+        assertEquals(0, mDrawable.getBounds().bottom);
+        assertEquals(0, mDrawable.getBounds().left);
+        assertEquals(0, mDrawable.getBounds().right);
 
         Canvas canvas = new Canvas();
         Spanned text = Html.fromHtml("<b>hello</b>");
-        TextPaint paint= new TextPaint();
+        TextPaint paint = new TextPaint();
         Layout layout = new StaticLayout("cts test.", paint, 200,
                 Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
 
@@ -69,31 +90,32 @@
                 0, 0, text, 0, 0, true, layout);
 
         // 0 means the top location
-        assertEquals(0, drawable.getBounds().top);
-        assertEquals(0 + drawable.getIntrinsicHeight(), drawable.getBounds().bottom);
-        assertEquals(x, drawable.getBounds().left);
-        assertEquals(x + drawable.getIntrinsicWidth(), drawable.getBounds().right);
-
-        try {
-            drawableMarginSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0,
-                    null, 0, 0, false, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
-
-        try {
-            drawableMarginSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0,
-                    "cts test.", 0, 0, false, null);
-            fail("When try to use a String as the text, should throw ClassCastException.");
-        } catch (ClassCastException e) {
-            // expected, test success.
-        }
+        assertEquals(0, mDrawable.getBounds().top);
+        assertEquals(mDrawable.getIntrinsicHeight(), mDrawable.getBounds().bottom);
+        assertEquals(x, mDrawable.getBounds().left);
+        assertEquals(x + mDrawable.getIntrinsicWidth(), mDrawable.getBounds().right);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testDrawLeadingMarginNull() {
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
+
+        drawableMarginSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0,
+                null, 0, 0, false, null);
+    }
+
+    @Test(expected=ClassCastException.class)
+    public void testDrawLeadingMarginString() {
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
+
+        // When try to use a String as the text, should throw ClassCastException
+        drawableMarginSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0,
+                "cts test.", 0, 0, false, null);
+    }
+
+    @Test
     public void testChooseHeight() {
-        Drawable drawable = mContext.getResources().getDrawable(R.drawable.scenery);
-        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(drawable, 0);
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
 
         Spanned text = Html.fromHtml("cts test.");
         FontMetricsInt fm = new FontMetricsInt();
@@ -113,19 +135,21 @@
         assertTrue(fm.descent > 0);
         assertEquals(0, fm.leading);
         assertEquals(0, fm.top);
+    }
 
-        try {
-            drawableMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+    @Test(expected=NullPointerException.class)
+    public void testChooseHeightNull() {
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
 
-        try {
-            drawableMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
-            fail("When try to use a String as the text, should throw ClassCastException.");
-        } catch (ClassCastException e) {
-            // expected, test success.
-        }
+        drawableMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
+    }
+
+
+    @Test(expected=ClassCastException.class)
+    public void testChooseHeightString() {
+        DrawableMarginSpan drawableMarginSpan = new DrawableMarginSpan(mDrawable, 0);
+
+        // When try to use a String as the text, should throw ClassCastException
+        drawableMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/DynamicDrawableSpanTest.java b/tests/tests/text/src/android/text/style/cts/DynamicDrawableSpanTest.java
index 921b0aa..5ad529b 100644
--- a/tests/tests/text/src/android/text/style/cts/DynamicDrawableSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/DynamicDrawableSpanTest.java
@@ -16,15 +16,25 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+
 import android.graphics.Canvas;
 import android.graphics.Paint.FontMetricsInt;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.cts.R;
 import android.text.style.DynamicDrawableSpan;
 
-public class DynamicDrawableSpanTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class DynamicDrawableSpanTest {
+    @Test
     public void testConstructor() {
         DynamicDrawableSpan d = new MyDynamicDrawableSpan();
         assertEquals(DynamicDrawableSpan.ALIGN_BOTTOM, d.getVerticalAlignment());
@@ -36,6 +46,7 @@
         assertEquals(DynamicDrawableSpan.ALIGN_BOTTOM, d.getVerticalAlignment());
     }
 
+    @Test
     public void testGetSize() {
         DynamicDrawableSpan dynamicDrawableSpan = new MyDynamicDrawableSpan();
         FontMetricsInt fm = new FontMetricsInt();
@@ -58,22 +69,20 @@
         assertEquals(rect.right, dynamicDrawableSpan.getSize(null, null, 0, 0, null));
     }
 
+    @Test
     public void testDraw() {
         DynamicDrawableSpan dynamicDrawableSpan = new MyDynamicDrawableSpan();
         Canvas canvas = new Canvas();
         dynamicDrawableSpan.draw(canvas, null, 0, 0, 1.0f, 0, 0, 1, null);
-
-        try {
-            dynamicDrawableSpan.draw(null, null, 0, 0, 1.0f, 0, 0, 1, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
-    /**
-     * The MyDynamicDrawableSpan for test.
-     */
+    @Test(expected=NullPointerException.class)
+    public void testDrawNullCanvas() {
+        DynamicDrawableSpan dynamicDrawableSpan = new MyDynamicDrawableSpan();
+
+        dynamicDrawableSpan.draw(null, null, 0, 0, 1.0f, 0, 0, 1, null);
+    }
+
     private class MyDynamicDrawableSpan extends DynamicDrawableSpan {
         public MyDynamicDrawableSpan() {
             super();
@@ -85,8 +94,7 @@
 
         @Override
         public Drawable getDrawable() {
-            // implement abstract method
-            return getContext().getResources().getDrawable(R.drawable.scenery);
+            return InstrumentationRegistry.getTargetContext().getDrawable(R.drawable.scenery);
         }
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/EasyEditSpanTest.java b/tests/tests/text/src/android/text/style/cts/EasyEditSpanTest.java
index 080e9a6..831ce09 100644
--- a/tests/tests/text/src/android/text/style/cts/EasyEditSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/EasyEditSpanTest.java
@@ -19,15 +19,23 @@
 import android.app.PendingIntent;
 import android.content.Intent;
 import android.os.Parcel;
+import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.EasyEditSpan;
 
-public class EasyEditSpanTest extends AndroidTestCase {
-    @SmallTest
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class EasyEditSpanTest {
+    @Test
     public void testConstructor() {
         new EasyEditSpan();
-        new EasyEditSpan(PendingIntent.getActivity(getContext(), 0, new Intent(), 0));
+        new EasyEditSpan(PendingIntent.getActivity(
+                InstrumentationRegistry.getTargetContext(), 0, new Intent(), 0));
+
         Parcel p = Parcel.obtain();
         try {
             new EasyEditSpan(p);
@@ -36,19 +44,19 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDescribeContents_doesNotThrowException() {
         EasyEditSpan easyEditSpan = new EasyEditSpan();
         easyEditSpan.describeContents();
     }
 
-    @SmallTest
+    @Test
     public void testGetSpanTypeId_doesNotThrowException() {
         EasyEditSpan easyEditSpan = new EasyEditSpan();
         easyEditSpan.getSpanTypeId();
     }
 
-    @SmallTest
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/ForegroundColorSpanTest.java b/tests/tests/text/src/android/text/style/cts/ForegroundColorSpanTest.java
index bacf89b..a259065 100644
--- a/tests/tests/text/src/android/text/style/cts/ForegroundColorSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ForegroundColorSpanTest.java
@@ -16,15 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.graphics.Color;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.ForegroundColorSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class ForegroundColorSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ForegroundColorSpanTest {
+    @Test
     public void testConstructor() {
         ForegroundColorSpan f = new ForegroundColorSpan(Color.GREEN);
 
@@ -38,6 +45,7 @@
         }
     }
 
+    @Test
     public void testGetForegroundColor() {
         ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLUE);
         assertEquals(Color.BLUE, foregroundColorSpan.getForegroundColor());
@@ -46,6 +54,7 @@
         assertEquals(Color.BLACK, foregroundColorSpan.getForegroundColor());
     }
 
+    @Test
     public void testUpdateDrawState() {
         ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.CYAN);
 
@@ -58,25 +67,28 @@
         foregroundColorSpan = new ForegroundColorSpan(Color.DKGRAY);
         foregroundColorSpan.updateDrawState(tp);
         assertEquals(Color.DKGRAY, tp.getColor());
-
-        try {
-            foregroundColorSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.CYAN);
+
+        foregroundColorSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
         foregroundColorSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
         foregroundColorSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/IconMarginSpanTest.java b/tests/tests/text/src/android/text/style/cts/IconMarginSpanTest.java
index f9442ce..3ee2564 100644
--- a/tests/tests/text/src/android/text/style/cts/IconMarginSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/IconMarginSpanTest.java
@@ -16,11 +16,14 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint.FontMetricsInt;
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Html;
 import android.text.Layout;
 import android.text.Spanned;
@@ -28,19 +31,26 @@
 import android.text.TextPaint;
 import android.text.style.IconMarginSpan;
 
-public class IconMarginSpanTest extends AndroidTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class IconMarginSpanTest {
     private static final int WIDTH = 80;
     private static final int HEIGHT = 120;
     private static final int[] COLOR = new int[WIDTH * HEIGHT];
     private static final Bitmap BITMAP_80X120 =
         Bitmap.createBitmap(COLOR, WIDTH, HEIGHT, Bitmap.Config.RGB_565);
 
+    @Test
     public void testConstructor() {
         new IconMarginSpan(BITMAP_80X120);
         new IconMarginSpan(BITMAP_80X120, 1);
         new IconMarginSpan(null, -1);
     }
 
+    @Test
     public void testGetLeadingMargin() {
         IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 1);
         int leadingMargin1 = iconMarginSpan.getLeadingMargin(true);
@@ -51,6 +61,7 @@
         assertTrue(leadingMargin2 > leadingMargin1);
     }
 
+    @Test
     public void testDrawLeadingMargin() {
         IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
         Canvas c = new Canvas();
@@ -59,22 +70,24 @@
         Layout layout = new StaticLayout("cts test.", p, 200, Layout.Alignment.ALIGN_NORMAL,
                 1, 0, true);
         iconMarginSpan.drawLeadingMargin(c, p, 0, 0, 0, 0, 0, text, 0, 0, true, layout);
-
-        try {
-            iconMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
-
-        try {
-            iconMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
-            fail("When try to use a String as the text, should throw ClassCastException.");
-        } catch (ClassCastException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testDrawLeadingMarginNull() {
+        IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
+
+        iconMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
+    }
+
+    @Test(expected=ClassCastException.class)
+    public void testDrawLeadingMarginString() {
+        IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
+
+        // When try to use a String as the text, should throw ClassCastException
+        iconMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
+    }
+
+    @Test
     public void testChooseHeight() {
         IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
 
@@ -94,19 +107,20 @@
         assertEquals(HEIGHT, fm.descent);
         assertEquals(0, fm.leading);
         assertEquals(0, fm.top);
+    }
 
-        try {
-            iconMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+    @Test(expected=NullPointerException.class)
+    public void testChooseHeightNull() {
+        IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
 
-        try {
-            iconMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
-            fail("When try to use a String as the text, should throw ClassCastException.");
-        } catch (ClassCastException e) {
-            // expected, test success.
-        }
+        iconMarginSpan.chooseHeight(null, 0, 0, 0, 0, null);
+    }
+
+    @Test(expected=ClassCastException.class)
+    public void testChooseHeightString() {
+        IconMarginSpan iconMarginSpan = new IconMarginSpan(BITMAP_80X120, 0);
+
+        // When try to use a String as the text, should throw ClassCastException
+        iconMarginSpan.chooseHeight("cts test.", 0, 0, 0, 0, null);
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java b/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
index 6d3d2e5..7d14e7ad 100644
--- a/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
@@ -16,18 +16,38 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
 import android.content.Context;
 import android.cts.util.WidgetTestUtils;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.cts.R;
 import android.text.style.DynamicDrawableSpan;
 import android.text.style.ImageSpan;
 
-public class ImageSpanTest extends AndroidTestCase {
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ImageSpanTest {
+    private Context mContext;
+
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
+    }
+
+    @Test
     public void testConstructor() {
         int width = 80;
         int height = 120;
@@ -71,8 +91,9 @@
         new ImageSpan((Context) null, -1, -1);
     }
 
+    @Test
     public void testGetSource() {
-        Drawable d = mContext.getResources().getDrawable(R.drawable.pass);
+        Drawable d = mContext.getDrawable(R.drawable.pass);
 
         ImageSpan imageSpan = new ImageSpan(d);
         assertNull(imageSpan.getSource());
@@ -86,8 +107,9 @@
         assertEquals(source, imageSpan.getSource());
     }
 
+    @Test
     public void testGetDrawable() {
-        Drawable drawable = mContext.getResources().getDrawable(R.drawable.pass);
+        Drawable drawable = mContext.getDrawable(R.drawable.pass);
 
         ImageSpan imageSpan = new ImageSpan(drawable);
         assertSame(drawable, imageSpan.getDrawable());
diff --git a/tests/tests/text/src/android/text/style/cts/LeadingMarginSpan_StandardTest.java b/tests/tests/text/src/android/text/style/cts/LeadingMarginSpan_StandardTest.java
index cbca876..6679caf 100644
--- a/tests/tests/text/src/android/text/style/cts/LeadingMarginSpan_StandardTest.java
+++ b/tests/tests/text/src/android/text/style/cts/LeadingMarginSpan_StandardTest.java
@@ -16,14 +16,21 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.LeadingMarginSpan;
 import android.text.style.LeadingMarginSpan.Standard;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class LeadingMarginSpan_StandardTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LeadingMarginSpan_StandardTest {
+    @Test
     public void testConstructor() {
         new Standard(1, 2);
         new Standard(3);
@@ -41,6 +48,7 @@
         }
     }
 
+    @Test
     public void testGetLeadingMargin() {
         int first = 4;
         int rest = 5;
@@ -54,21 +62,25 @@
         assertEquals(-1, standard.getLeadingMargin(false));
     }
 
+    @Test
     public void testDrawLeadingMargin() {
         Standard standard = new LeadingMarginSpan.Standard(10);
         standard.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, null, 0, 0, false, null);
     }
 
+    @Test
     public void testDescribeContents() {
         Standard standard = new Standard(1);
         standard.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         Standard standard = new Standard(1);
         standard.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java b/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
index 7aa044c..bc07e0a 100644
--- a/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
@@ -16,18 +16,24 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+
 import android.annotation.NonNull;
 import android.os.LocaleList;
 import android.os.Parcel;
 import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.LocaleSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class LocaleSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LocaleSpanTest {
 
-    private void checkGetLocales(@NonNull final LocaleList locales) {
+    private void verifyGetLocales(@NonNull final LocaleList locales) {
         final LocaleSpan span = new LocaleSpan(locales);
         assertEquals(locales.get(0), span.getLocale());
         assertEquals(locales, span.getLocales());
@@ -37,23 +43,17 @@
         assertEquals(locales, cloned.getLocales());
     }
 
-    @SmallTest
+    @Test
     public void testGetLocales() {
-        checkGetLocales(LocaleList.getEmptyLocaleList());
-        checkGetLocales(LocaleList.forLanguageTags("en"));
-        checkGetLocales(LocaleList.forLanguageTags("en-GB,en"));
-        checkGetLocales(LocaleList.forLanguageTags("de-DE-u-co-phonebk,en-GB,en"));
+        verifyGetLocales(LocaleList.getEmptyLocaleList());
+        verifyGetLocales(LocaleList.forLanguageTags("en"));
+        verifyGetLocales(LocaleList.forLanguageTags("en-GB,en"));
+        verifyGetLocales(LocaleList.forLanguageTags("de-DE-u-co-phonebk,en-GB,en"));
     }
 
-    @SmallTest
+    @Test(expected=NullPointerException.class)
     public void testConstructorWithLocaleList() {
-        try {
-            new LocaleSpan((LocaleList) null);
-        } catch (NullPointerException e) {
-            // Expected.
-            return;
-        }
-        fail("NullPointerException must have been thrown.");
+        new LocaleSpan((LocaleList) null);
     }
 
     @NonNull
@@ -71,19 +71,19 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDescribeContents_doesNotThrowException() {
         LocaleSpan localeSpan = new LocaleSpan(LocaleList.getEmptyLocaleList());
         localeSpan.describeContents();
     }
 
-    @SmallTest
+    @Test
     public void testGetSpanTypeId_doesNotThrowException() {
         LocaleSpan localeSpan = new LocaleSpan(LocaleList.getEmptyLocaleList());
         localeSpan.getSpanTypeId();
     }
 
-    @SmallTest
+    @Test
     public void testUpdateDrawState() {
         LocaleList localeListForSpan = LocaleList.forLanguageTags("en");
         LocaleSpan localeSpan = new LocaleSpan(localeListForSpan);
@@ -99,7 +99,7 @@
         assertEquals(localeListForSpan.get(0), tp.getTextLocale());
     }
 
-    @SmallTest
+    @Test
     public void testUpdateMeasureState() {
         LocaleList localeListForSpan = LocaleList.forLanguageTags("en");
         LocaleSpan localeSpan = new LocaleSpan(localeListForSpan);
diff --git a/tests/tests/text/src/android/text/style/cts/MaskFilterSpanTest.java b/tests/tests/text/src/android/text/style/cts/MaskFilterSpanTest.java
index 0ed33c9..7b9f3d9 100644
--- a/tests/tests/text/src/android/text/style/cts/MaskFilterSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/MaskFilterSpanTest.java
@@ -16,20 +16,29 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 
 import android.graphics.MaskFilter;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.MaskFilterSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class MaskFilterSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class MaskFilterSpanTest {
+    @Test
     public void testConstructor() {
         MaskFilter mf = new MaskFilter();
         new MaskFilterSpan(mf);
         new MaskFilterSpan(null);
     }
 
+    @Test
     public void testUpdateDrawState() {
         MaskFilter mf = new MaskFilter();
         MaskFilterSpan maskFilterSpan = new MaskFilterSpan(mf);
@@ -39,15 +48,17 @@
 
         maskFilterSpan.updateDrawState(tp);
         assertSame(mf, tp.getMaskFilter());
-
-        try {
-            maskFilterSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        MaskFilter mf = new MaskFilter();
+        MaskFilterSpan maskFilterSpan = new MaskFilterSpan(mf);
+
+        maskFilterSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testGetMaskFilter() {
         MaskFilter expected = new MaskFilter();
 
diff --git a/tests/tests/text/src/android/text/style/cts/MetricAffectingSpanTest.java b/tests/tests/text/src/android/text/style/cts/MetricAffectingSpanTest.java
index af6533c..cb8850e 100644
--- a/tests/tests/text/src/android/text/style/cts/MetricAffectingSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/MetricAffectingSpanTest.java
@@ -16,15 +16,24 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.CharacterStyle;
 import android.text.style.MetricAffectingSpan;
 import android.text.style.SuperscriptSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class MetricAffectingSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class MetricAffectingSpanTest {
+    @Test
     public void testGetUnderlying() {
         MetricAffectingSpan metricAffectingSpan = new MyMetricAffectingSpan();
         assertSame(metricAffectingSpan, metricAffectingSpan.getUnderlying());
@@ -36,18 +45,13 @@
         assertSame(metricAffectingSpan, result.getUnderlying());
     }
 
-    /**
-     * MyMetricAffectingSpan for test.
-     */
     private class MyMetricAffectingSpan extends MetricAffectingSpan {
         @Override
         public void updateMeasureState(TextPaint p) {
-            // implement abstract method.
         }
 
         @Override
         public void updateDrawState(TextPaint tp) {
-            // implement abstract method.
         }
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/QuoteSpanTest.java b/tests/tests/text/src/android/text/style/cts/QuoteSpanTest.java
index a19c926..358be07 100644
--- a/tests/tests/text/src/android/text/style/cts/QuoteSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/QuoteSpanTest.java
@@ -16,16 +16,23 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.QuoteSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class QuoteSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class QuoteSpanTest {
+    @Test
     public void testConstructor() {
         new QuoteSpan();
         QuoteSpan q = new QuoteSpan(Color.RED);
@@ -40,6 +47,7 @@
         }
     }
 
+    @Test
     public void testGetLeadingMargin() {
         QuoteSpan quoteSpan = new QuoteSpan();
 
@@ -47,6 +55,7 @@
         quoteSpan.getLeadingMargin(false);
     }
 
+    @Test
     public void testGetColor() {
         QuoteSpan quoteSpan = new QuoteSpan(Color.BLACK);
         assertEquals(Color.BLACK, quoteSpan.getColor());
@@ -55,31 +64,35 @@
         assertEquals(Color.BLUE, quoteSpan.getColor());
     }
 
+    @Test
     public void testDrawLeadingMargin() {
         QuoteSpan quoteSpan = new QuoteSpan();
 
         Canvas c = new Canvas();
         Paint p = new Paint();
         quoteSpan.drawLeadingMargin(c, p, 0, 0, 0, 0, 0, null, 0, 0, true, null);
-
-        try {
-            quoteSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, null, 0, 0, true, null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testDrawLeadingMarginNull() {
+        QuoteSpan quoteSpan = new QuoteSpan();
+
+        quoteSpan.drawLeadingMargin(null, null, 0, 0, 0, 0, 0, null, 0, 0, true, null);
+    }
+
+    @Test
     public void testDescribeContents() {
         QuoteSpan quoteSpan = new QuoteSpan(Color.RED);
         quoteSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         QuoteSpan quoteSpan = new QuoteSpan(Color.RED);
         quoteSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/RasterizerSpanTest.java b/tests/tests/text/src/android/text/style/cts/RasterizerSpanTest.java
index 8c5f71e..0ff8f22 100644
--- a/tests/tests/text/src/android/text/style/cts/RasterizerSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/RasterizerSpanTest.java
@@ -16,14 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 
 import android.graphics.Rasterizer;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.RasterizerSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class RasterizerSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class RasterizerSpanTest {
+    @Test
     public void testConstructor() {
         Rasterizer r = new Rasterizer();
 
@@ -31,6 +39,7 @@
         new RasterizerSpan(null);
     }
 
+    @Test
     public void testGetRasterizer() {
         Rasterizer expected = new Rasterizer();
 
@@ -41,6 +50,7 @@
         assertNull(rasterizerSpan.getRasterizer());
     }
 
+    @Test
     public void testUpdateDrawState() {
         Rasterizer rasterizer = new Rasterizer();
         RasterizerSpan rasterizerSpan = new RasterizerSpan(rasterizer);
@@ -50,12 +60,13 @@
 
         rasterizerSpan.updateDrawState(tp);
         assertSame(rasterizer, tp.getRasterizer());
+    }
 
-        try {
-            rasterizerSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        Rasterizer rasterizer = new Rasterizer();
+        RasterizerSpan rasterizerSpan = new RasterizerSpan(rasterizer);
+
+        rasterizerSpan.updateDrawState(null);
     }
 }
diff --git a/tests/tests/text/src/android/text/style/cts/RelativeSizeSpanTest.java b/tests/tests/text/src/android/text/style/cts/RelativeSizeSpanTest.java
index 5f67a0a..3cac62e 100644
--- a/tests/tests/text/src/android/text/style/cts/RelativeSizeSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/RelativeSizeSpanTest.java
@@ -16,14 +16,21 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.RelativeSizeSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class RelativeSizeSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class RelativeSizeSpanTest {
+    @Test
     public void testConstructor() {
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(1.0f);
 
@@ -39,14 +46,16 @@
         }
     }
 
+    @Test
     public void testGetSizeChange() {
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(2.0f);
-        assertEquals(2.0f, relativeSizeSpan.getSizeChange());
+        assertEquals(2.0f, relativeSizeSpan.getSizeChange(), 0.0f);
 
         relativeSizeSpan = new RelativeSizeSpan(-2.0f);
-        assertEquals(-2.0f, relativeSizeSpan.getSizeChange());
+        assertEquals(-2.0f, relativeSizeSpan.getSizeChange(), 0.0f);
     }
 
+    @Test
     public void testUpdateMeasureState() {
         float proportion = 3.0f;
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(proportion);
@@ -55,22 +64,23 @@
         tp.setTextSize(2.0f);
         float oldSize = tp.getTextSize();
         relativeSizeSpan.updateMeasureState(tp);
-        assertEquals(2.0f * proportion, tp.getTextSize());
+        assertEquals(2.0f * proportion, tp.getTextSize(), 0.0f);
 
         // setTextSize, the value must >0, so set to negative is useless.
         tp.setTextSize(-3.0f);
         oldSize = tp.getTextSize();
         relativeSizeSpan.updateMeasureState(tp);
-        assertEquals(oldSize * proportion, tp.getTextSize());
-
-        try {
-            relativeSizeSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(oldSize * proportion, tp.getTextSize(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(3.0f);
+
+        relativeSizeSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         float proportion = 3.0f;
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(proportion);
@@ -79,32 +89,35 @@
         tp.setTextSize(2.0f);
         float oldSize = tp.getTextSize();
         relativeSizeSpan.updateDrawState(tp);
-        assertEquals(oldSize * proportion, tp.getTextSize());
+        assertEquals(oldSize * proportion, tp.getTextSize(), 0.0f);
 
         // setTextSize, the value must >0, so set to negative is useless.
         tp.setTextSize(-3.0f);
         oldSize = tp.getTextSize();
         relativeSizeSpan.updateDrawState(tp);
-        assertEquals(oldSize * proportion, tp.getTextSize());
-
-        try {
-            relativeSizeSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(oldSize * proportion, tp.getTextSize(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(3.0f);
+
+        relativeSizeSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(2.0f);
         relativeSizeSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(2.0f);
         relativeSizeSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
@@ -113,7 +126,7 @@
             relativeSizeSpan.writeToParcel(p, 0);
             p.setDataPosition(0);
             RelativeSizeSpan newSpan = new RelativeSizeSpan(p);
-            assertEquals(proportion, newSpan.getSizeChange());
+            assertEquals(proportion, newSpan.getSizeChange(), 0.0f);
         } finally {
             p.recycle();
         }
diff --git a/tests/tests/text/src/android/text/style/cts/ReplacementSpanTest.java b/tests/tests/text/src/android/text/style/cts/ReplacementSpanTest.java
index 8f4b611..514e22b 100644
--- a/tests/tests/text/src/android/text/style/cts/ReplacementSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ReplacementSpanTest.java
@@ -19,35 +19,37 @@
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Paint.FontMetricsInt;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.ReplacementSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class ReplacementSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ReplacementSpanTest {
+    @Test
     public void testUpdateMeasureState() {
         ReplacementSpan replacementSpan = new MockReplacementSpan();
         replacementSpan.updateMeasureState(null);
     }
 
+    @Test
     public void testUpdateDrawState() {
         ReplacementSpan replacementSpan = new MockReplacementSpan();
         replacementSpan.updateDrawState(null);
     }
 
-    /**
-     * MockReplacementSpan for test.
-     */
     private class MockReplacementSpan extends ReplacementSpan {
         @Override
         public void draw(Canvas canvas, CharSequence text, int start, int end,
                 float x, int top, int y, int bottom, Paint paint) {
-            // implement abstract method
         }
 
         @Override
         public int getSize(Paint paint, CharSequence text, int start, int end,
                 FontMetricsInt fm) {
-            // implement abstract method
             return 0;
         }
     }
diff --git a/tests/tests/text/src/android/text/style/cts/ScaleXSpanTest.java b/tests/tests/text/src/android/text/style/cts/ScaleXSpanTest.java
index 2ec9f65..d243ef6 100644
--- a/tests/tests/text/src/android/text/style/cts/ScaleXSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ScaleXSpanTest.java
@@ -16,14 +16,21 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.ScaleXSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class ScaleXSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ScaleXSpanTest {
+    @Test
     public void testConstructor() {
         ScaleXSpan scaleXSpan = new ScaleXSpan(1.5f);
 
@@ -39,6 +46,7 @@
         }
     }
 
+    @Test
     public void testUpdateDrawState() {
         float proportion = 3.0f;
         ScaleXSpan scaleXSpan = new ScaleXSpan(proportion);
@@ -46,20 +54,21 @@
         TextPaint tp = new TextPaint();
         tp.setTextScaleX(2.0f);
         scaleXSpan.updateDrawState(tp);
-        assertEquals(2.0f * proportion, tp.getTextScaleX());
+        assertEquals(2.0f * proportion, tp.getTextScaleX(), 0.0f);
 
         tp.setTextScaleX(-3.0f);
         scaleXSpan.updateDrawState(tp);
-        assertEquals(-3.0f * proportion, tp.getTextScaleX());
-
-        try {
-            scaleXSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(-3.0f * proportion, tp.getTextScaleX(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        ScaleXSpan scaleXSpan = new ScaleXSpan(3.0f);
+
+        scaleXSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testUpdateMeasureState() {
         float proportion = 3.0f;
         ScaleXSpan scaleXSpan = new ScaleXSpan(proportion);
@@ -67,38 +76,42 @@
         TextPaint tp = new TextPaint();
         tp.setTextScaleX(2.0f);
         scaleXSpan.updateMeasureState(tp);
-        assertEquals(2.0f * proportion, tp.getTextScaleX());
+        assertEquals(2.0f * proportion, tp.getTextScaleX(), 0.0f);
 
         tp.setTextScaleX(-3.0f);
         scaleXSpan.updateMeasureState(tp);
-        assertEquals(-3.0f * proportion, tp.getTextScaleX());
-
-        try {
-            scaleXSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        assertEquals(-3.0f * proportion, tp.getTextScaleX(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        ScaleXSpan scaleXSpan = new ScaleXSpan(3.0f);
+
+        scaleXSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testGetScaleX() {
         ScaleXSpan scaleXSpan = new ScaleXSpan(5.0f);
-        assertEquals(5.0f, scaleXSpan.getScaleX());
+        assertEquals(5.0f, scaleXSpan.getScaleX(), 0.0f);
 
         scaleXSpan = new ScaleXSpan(-5.0f);
-        assertEquals(-5.0f, scaleXSpan.getScaleX());
+        assertEquals(-5.0f, scaleXSpan.getScaleX(), 0.0f);
     }
 
+    @Test
     public void testDescribeContents() {
         ScaleXSpan scaleXSpan = new ScaleXSpan(5.0f);
         scaleXSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         ScaleXSpan scaleXSpan = new ScaleXSpan(5.0f);
         scaleXSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
@@ -107,7 +120,7 @@
             scaleXSpan.writeToParcel(p, 0);
             p.setDataPosition(0);
             ScaleXSpan newSpan = new ScaleXSpan(p);
-            assertEquals(proportion, newSpan.getScaleX());
+            assertEquals(proportion, newSpan.getScaleX(), 0.0f);
         } finally {
             p.recycle();
         }
diff --git a/tests/tests/text/src/android/text/style/cts/StrikethroughSpanTest.java b/tests/tests/text/src/android/text/style/cts/StrikethroughSpanTest.java
index a3c3d9d..aa4ccdd 100644
--- a/tests/tests/text/src/android/text/style/cts/StrikethroughSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/StrikethroughSpanTest.java
@@ -16,14 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.StrikethroughSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class StrikethroughSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class StrikethroughSpanTest {
+    @Test
     public void testConstructor() {
         StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
 
@@ -37,6 +45,7 @@
         }
     }
 
+    @Test
     public void testUpdateDrawState() {
         StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
 
@@ -46,25 +55,28 @@
 
         strikethroughSpan.updateDrawState(tp);
         assertTrue(tp.isStrikeThruText());
-
-        try {
-            strikethroughSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
+
+        strikethroughSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
         strikethroughSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
         strikethroughSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/StyleSpanTest.java b/tests/tests/text/src/android/text/style/cts/StyleSpanTest.java
index 753dca4..4b4fc7e 100644
--- a/tests/tests/text/src/android/text/style/cts/StyleSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/StyleSpanTest.java
@@ -16,15 +16,23 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import android.graphics.Typeface;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.StyleSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class StyleSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class StyleSpanTest {
+    @Test
     public void testConstructor() {
         StyleSpan styleSpan = new StyleSpan(2);
 
@@ -40,6 +48,7 @@
         }
     }
 
+    @Test
     public void testGetStyle() {
         StyleSpan styleSpan = new StyleSpan(2);
         assertEquals(2, styleSpan.getStyle());
@@ -48,6 +57,7 @@
         assertEquals(-2, styleSpan.getStyle());
     }
 
+    @Test
     public void testUpdateMeasureState() {
         StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
 
@@ -62,15 +72,16 @@
 
         assertNotNull(tp.getTypeface());
         assertEquals(Typeface.BOLD, tp.getTypeface().getStyle());
-
-        try {
-            styleSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
+
+        styleSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
 
@@ -85,24 +96,28 @@
 
         assertNotNull(tp.getTypeface());
         assertEquals(Typeface.BOLD, tp.getTypeface().getStyle());
-
-        try {
-            styleSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
+
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
+
+        styleSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
         styleSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
         styleSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/SubscriptSpanTest.java b/tests/tests/text/src/android/text/style/cts/SubscriptSpanTest.java
index 314b342..000be8d 100644
--- a/tests/tests/text/src/android/text/style/cts/SubscriptSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/SubscriptSpanTest.java
@@ -17,13 +17,21 @@
 package android.text.style.cts;
 
 
+import static org.junit.Assert.assertEquals;
+
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.SubscriptSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class SubscriptSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SubscriptSpanTest {
+    @Test
     public void testConstructor() {
         SubscriptSpan subscriptSpan = new SubscriptSpan();
 
@@ -37,6 +45,7 @@
         }
     }
 
+    @Test
     public void testUpdateMeasureState() {
         // the expected result is: tp.baselineShift -= (int) (tp.ascent() / 2)
         SubscriptSpan subscriptSpan = new SubscriptSpan();
@@ -48,15 +57,16 @@
 
         subscriptSpan.updateMeasureState(tp);
         assertEquals(baselineShift - (int) (ascent / 2), tp.baselineShift);
-
-        try {
-            subscriptSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        SubscriptSpan subscriptSpan = new SubscriptSpan();
+
+        subscriptSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         // the expected result is: tp.baselineShift -= (int) (tp.ascent() / 2)
         SubscriptSpan subscriptSpan = new SubscriptSpan();
@@ -68,25 +78,28 @@
 
         subscriptSpan.updateDrawState(tp);
         assertEquals(baselineShift - (int) (ascent / 2), tp.baselineShift);
-
-        try {
-            subscriptSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        SubscriptSpan subscriptSpan = new SubscriptSpan();
+
+        subscriptSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         SubscriptSpan subscriptSpan = new SubscriptSpan();
         subscriptSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         SubscriptSpan subscriptSpan = new SubscriptSpan();
         subscriptSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java b/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
index 05918ab..686f9c3 100644
--- a/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
@@ -17,6 +17,9 @@
 package android.text.style.cts;
 
 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 android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -24,24 +27,30 @@
 import android.content.res.Configuration;
 import android.os.LocaleList;
 import android.os.Parcel;
+import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.SuggestionSpan;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 
 /**
  * Test {@link SuggestionSpan}.
  */
-public class SuggestionSpanTest extends AndroidTestCase {
-
-    @SmallTest
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SuggestionSpanTest {
+    @Test
     public void testConstructorWithContext() {
-        final String[] suggestions = new String[]{"suggestion1", "suggestion2"};
+        final String[] suggestions = new String[] {"suggestion1", "suggestion2"};
         final Configuration overrideConfig = new Configuration();
         final Locale locale = Locale.forLanguageTag("az-Arab");
         overrideConfig.setLocales(new LocaleList(locale));
-        final Context context = getContext().createConfigurationContext(overrideConfig);
+        final Context context = InstrumentationRegistry.getTargetContext().
+                createConfigurationContext(overrideConfig);
 
         final SuggestionSpan span = new SuggestionSpan(context, suggestions,
                 SuggestionSpan.FLAG_AUTO_CORRECTION);
@@ -51,7 +60,7 @@
         assertEquals(SuggestionSpan.FLAG_AUTO_CORRECTION, span.getFlags());
     }
 
-    @SmallTest
+    @Test
     public void testGetSuggestionSpans() {
         final String[] suggestions = new String[]{"suggestion1", "suggestion2"};
         final SuggestionSpan span = new SuggestionSpan(Locale.forLanguageTag("en"), suggestions,
@@ -64,7 +73,7 @@
                 suggestions, clonedSpan.getSuggestions());
     }
 
-    @SmallTest
+    @Test
     public void testGetSuggestionSpans_emptySuggestions() {
         final String[] suggestions = new String[0];
         final SuggestionSpan span = new SuggestionSpan(Locale.forLanguageTag("en"), suggestions,
@@ -78,7 +87,7 @@
                 suggestions, clonedSpan.getSuggestions());
     }
 
-    @SmallTest
+    @Test
     public void testGetSuggestionSpans_suggestionsWithNullValue() {
         final String[] suggestions = new String[]{"suggestion", null};
         final SuggestionSpan span = new SuggestionSpan(Locale.forLanguageTag("en"), suggestions,
@@ -91,7 +100,7 @@
                 suggestions, clonedSpan.getSuggestions());
     }
 
-    @SmallTest
+    @Test
     public void testGetFlags() {
         final String[] anySuggestions = new String[0];
         final int flag = SuggestionSpan.FLAG_AUTO_CORRECTION;
@@ -104,7 +113,7 @@
         assertEquals("Should (de)serialize flags", flag, clonedSpan.getFlags());
     }
 
-    @SmallTest
+    @Test
     public void testEquals_returnsTrueForDeserializedInstances() {
         final SuggestionSpan span1 = new SuggestionSpan(null, Locale.forLanguageTag("en"),
                 new String[0], SuggestionSpan.FLAG_AUTO_CORRECTION, SuggestionSpan.class);
@@ -113,7 +122,7 @@
         assertTrue("(De)serialized instances should be equal", span1.equals(span2));
     }
 
-    @SmallTest
+    @Test
     public void testEquals_returnsTrueIfTheFlagsAreDifferent() {
         final SuggestionSpan span1 = new SuggestionSpan(null, Locale.forLanguageTag("en"),
                 new String[0], SuggestionSpan.FLAG_AUTO_CORRECTION, SuggestionSpan.class);
@@ -126,7 +135,7 @@
         assertTrue("Instances with different flags should be equal", span1.equals(span2));
     }
 
-    @SmallTest
+    @Test
     public void testEquals_returnsFalseIfCreationTimeIsNotSame() {
         final Locale anyLocale = Locale.forLanguageTag("en");
         final String[] anySuggestions = new String[0];
@@ -168,7 +177,7 @@
         return original.toString();
     }
 
-    private void checkGetLocaleObject(final Locale locale) {
+    private void verifyGetLocaleObject(final Locale locale) {
         final SuggestionSpan span = new SuggestionSpan(locale, new String[0],
                 SuggestionSpan.FLAG_AUTO_CORRECTION);
         // In the context of SuggestionSpan#getLocaleObject(), we do care only about subtags that
@@ -182,18 +191,18 @@
         assertEquals(getNonNullLocaleString(locale), cloned.getLocale());
     }
 
-    @SmallTest
+    @Test
     public void testGetLocaleObject() {
-        checkGetLocaleObject(Locale.forLanguageTag("en"));
-        checkGetLocaleObject(Locale.forLanguageTag("en-GB"));
-        checkGetLocaleObject(Locale.forLanguageTag("EN-GB"));
-        checkGetLocaleObject(Locale.forLanguageTag("en-gb"));
-        checkGetLocaleObject(Locale.forLanguageTag("En-gB"));
-        checkGetLocaleObject(Locale.forLanguageTag("und"));
-        checkGetLocaleObject(Locale.forLanguageTag("de-DE-u-co-phonebk"));
-        checkGetLocaleObject(Locale.forLanguageTag(""));
-        checkGetLocaleObject(null);
-        checkGetLocaleObject(new Locale(" an  ", " i n v a l i d ", "data"));
+        verifyGetLocaleObject(Locale.forLanguageTag("en"));
+        verifyGetLocaleObject(Locale.forLanguageTag("en-GB"));
+        verifyGetLocaleObject(Locale.forLanguageTag("EN-GB"));
+        verifyGetLocaleObject(Locale.forLanguageTag("en-gb"));
+        verifyGetLocaleObject(Locale.forLanguageTag("En-gB"));
+        verifyGetLocaleObject(Locale.forLanguageTag("und"));
+        verifyGetLocaleObject(Locale.forLanguageTag("de-DE-u-co-phonebk"));
+        verifyGetLocaleObject(Locale.forLanguageTag(""));
+        verifyGetLocaleObject(null);
+        verifyGetLocaleObject(new Locale(" an  ", " i n v a l i d ", "data"));
     }
 
     @NonNull
diff --git a/tests/tests/text/src/android/text/style/cts/SuperscriptSpanTest.java b/tests/tests/text/src/android/text/style/cts/SuperscriptSpanTest.java
index 92a2db4..68fa8c8 100644
--- a/tests/tests/text/src/android/text/style/cts/SuperscriptSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/SuperscriptSpanTest.java
@@ -16,14 +16,21 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.SuperscriptSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class SuperscriptSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SuperscriptSpanTest {
+    @Test
     public void testConstructor() {
         SuperscriptSpan superscriptSpan = new SuperscriptSpan();
 
@@ -37,6 +44,7 @@
         }
     }
 
+    @Test
     public void testUpdateMeasureState() {
         // the expected result is: tp.baselineShift += (int) (tp.ascent() / 2)
         SuperscriptSpan superscriptSpan = new SuperscriptSpan();
@@ -48,15 +56,16 @@
 
         superscriptSpan.updateMeasureState(tp);
         assertEquals(baselineShift + (int) (ascent / 2), tp.baselineShift);
-
-        try {
-            superscriptSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        SuperscriptSpan superscriptSpan = new SuperscriptSpan();
+
+        superscriptSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         // the expected result is: tp.baselineShift += (int) (tp.ascent() / 2)
         SuperscriptSpan superscriptSpan = new SuperscriptSpan();
@@ -68,25 +77,28 @@
 
         superscriptSpan.updateDrawState(tp);
         assertEquals(baselineShift + (int) (ascent / 2), tp.baselineShift);
-
-        try {
-            superscriptSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        SuperscriptSpan superscriptSpan = new SuperscriptSpan();
+
+        superscriptSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         SuperscriptSpan superscriptSpan = new SuperscriptSpan();
         superscriptSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         SuperscriptSpan superscriptSpan = new SuperscriptSpan();
         superscriptSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/TabStopSpan_StandardTest.java b/tests/tests/text/src/android/text/style/cts/TabStopSpan_StandardTest.java
index ae11191..34c487e 100644
--- a/tests/tests/text/src/android/text/style/cts/TabStopSpan_StandardTest.java
+++ b/tests/tests/text/src/android/text/style/cts/TabStopSpan_StandardTest.java
@@ -16,18 +16,27 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.TabStopSpan;
 import android.text.style.TabStopSpan.Standard;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class TabStopSpan_StandardTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TabStopSpan_StandardTest {
+    @Test
     public void testConstructor() {
         new TabStopSpan.Standard(3);
 
         new TabStopSpan.Standard(-3);
     }
 
+    @Test
     public void testGetTabStop() {
         Standard standard = new Standard(3);
         assertEquals(3, standard.getTabStop());
diff --git a/tests/tests/text/src/android/text/style/cts/TextAppearanceSpanTest.java b/tests/tests/text/src/android/text/style/cts/TextAppearanceSpanTest.java
index 2d45566..5af81d8 100644
--- a/tests/tests/text/src/android/text/style/cts/TextAppearanceSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/TextAppearanceSpanTest.java
@@ -16,24 +16,46 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 
+import android.content.Context;
 import android.content.res.ColorStateList;
 import android.graphics.Color;
 import android.os.Parcel;
-import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.TextAppearanceSpan;
 
-public class TextAppearanceSpanTest extends AndroidTestCase {
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TextAppearanceSpanTest {
+    private Context mContext;
+    private ColorStateList mColorStateList;
+
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
+
+        int[][] states = new int[][] { new int[0], new int[0] };
+        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
+        mColorStateList = new ColorStateList(states, colors);
+    }
+
+    @Test
     public void testConstructor() {
         new TextAppearanceSpan(mContext, 1);
         new TextAppearanceSpan(mContext, 1, 1);
 
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         Parcel p = Parcel.obtain();
         try {
             textAppearanceSpan.writeToParcel(p, 0);
@@ -42,23 +64,22 @@
         } finally {
             p.recycle();
         }
-        try {
-            new TextAppearanceSpan(null, -1);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success
-        }
-
-        try {
-            new TextAppearanceSpan(null, -1, -1);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success
-        }
 
         new TextAppearanceSpan(null, -1, -1, null, null);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNullContext1() {
+        new TextAppearanceSpan(null, -1);
+    }
+
+
+    @Test(expected=NullPointerException.class)
+    public void testConstructorNullContext2() {
+        new TextAppearanceSpan(null, -1, -1);
+    }
+
+    @Test
     public void testGetFamily() {
         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
         assertNull(textAppearanceSpan.getFamily());
@@ -66,48 +87,41 @@
         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
         assertNull(textAppearanceSpan.getFamily());
 
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         assertEquals("sans", textAppearanceSpan.getFamily());
     }
 
+    @Test
     public void testUpdateMeasureState() {
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         TextPaint tp = new TextPaint();
-        tp.setTextSize((float) 1);
-        assertEquals((float) 1, tp.getTextSize());
+        tp.setTextSize(1.0f);
+        assertEquals(1.0f, tp.getTextSize(), 0.0f);
 
         textAppearanceSpan.updateMeasureState(tp);
 
-        assertEquals((float) 6, tp.getTextSize());
-
-        try {
-            textAppearanceSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success
-        }
+        assertEquals(6.0f, tp.getTextSize(), 0.0f);
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
+        textAppearanceSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testGetTextColor() {
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
+        assertSame(mColorStateList, textAppearanceSpan.getTextColor());
 
-        TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
-        assertSame(csl, textAppearanceSpan.getTextColor());
-
-        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, null, csl);
+        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, null, mColorStateList);
         assertNull(textAppearanceSpan.getTextColor());
     }
 
+    @Test
     public void testGetTextSize() {
         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
         assertEquals(-1, textAppearanceSpan.getTextSize());
@@ -115,14 +129,11 @@
         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
         assertEquals(-1, textAppearanceSpan.getTextSize());
 
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         assertEquals(6, textAppearanceSpan.getTextSize());
     }
 
+    @Test
     public void testGetTextStyle() {
         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
         assertEquals(0, textAppearanceSpan.getTextStyle());
@@ -130,32 +141,24 @@
         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
         assertEquals(0, textAppearanceSpan.getTextStyle());
 
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         assertEquals(1, textAppearanceSpan.getTextStyle());
     }
 
+    @Test
     public void testGetLinkTextColor() {
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
+        assertSame(mColorStateList, textAppearanceSpan.getLinkTextColor());
 
-        TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
-        assertSame(csl, textAppearanceSpan.getLinkTextColor());
-
-        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, null);
+        textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, null);
         assertNull(textAppearanceSpan.getLinkTextColor());
     }
 
+    @Test
     public void testUpdateDrawState() {
-        int[][] states = new int[][] { new int[0], new int[0] };
-        int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
-        ColorStateList csl = new ColorStateList(states, colors);
-
-        TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, csl, csl);
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
         TextPaint tp = new TextPaint();
         tp.setColor(0);
         tp.linkColor = 0;
@@ -163,28 +166,32 @@
 
         textAppearanceSpan.updateDrawState(tp);
 
-        int expected = csl.getColorForState(tp.drawableState, 0);
+        int expected = mColorStateList.getColorForState(tp.drawableState, 0);
         assertEquals(expected, tp.getColor());
         assertEquals(expected, tp.linkColor);
-
-        try {
-            textAppearanceSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        TextAppearanceSpan textAppearanceSpan =
+                new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
+
+        textAppearanceSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
         textAppearanceSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
         textAppearanceSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         String family = "sans";
diff --git a/tests/tests/text/src/android/text/style/cts/TtsSpanTest.java b/tests/tests/text/src/android/text/style/cts/TtsSpanTest.java
index b5b11d6..c8a23fc 100644
--- a/tests/tests/text/src/android/text/style/cts/TtsSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/TtsSpanTest.java
@@ -16,29 +16,35 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+
 import android.os.Parcel;
 import android.os.PersistableBundle;
 import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.TtsSpan;
 
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class TtsSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TtsSpanTest {
+    private PersistableBundle mBundle;
 
-    PersistableBundle bundle;
-
-    @Override
-    protected void setUp() {
-        bundle = new PersistableBundle();
-        bundle.putString("argument.one", "value.one");
-        bundle.putString("argument.two", "value.two");
-        bundle.putLong("argument.three", 3);
-        bundle.putLong("argument.four", 4);
+    @Before
+    public void setup() {
+        mBundle = new PersistableBundle();
+        mBundle.putString("argument.one", "value.one");
+        mBundle.putString("argument.two", "value.two");
+        mBundle.putLong("argument.three", 3);
+        mBundle.putLong("argument.four", 4);
     }
 
-    @SmallTest
+    @Test
     public void testGetArgs() {
-        TtsSpan t = new TtsSpan("test.type.one", bundle);
+        TtsSpan t = new TtsSpan("test.type.one", mBundle);
         final PersistableBundle args = t.getArgs();
         assertEquals(4, args.size());
         assertEquals("value.one", args.getString("argument.one"));
@@ -47,29 +53,29 @@
         assertEquals(4, args.getLong("argument.four"));
     }
 
-    @SmallTest
+    @Test
     public void testGetType() {
-        TtsSpan t = new TtsSpan("test.type.two", bundle);
+        TtsSpan t = new TtsSpan("test.type.two", mBundle);
         assertEquals("test.type.two", t.getType());
     }
 
-    @SmallTest
+    @Test
     public void testDescribeContents() {
-        TtsSpan span = new TtsSpan("test.type.three", bundle);
+        TtsSpan span = new TtsSpan("test.type.three", mBundle);
         span.describeContents();
     }
 
-    @SmallTest
+    @Test
     public void testGetSpanTypeId() {
-        TtsSpan span = new TtsSpan("test.type.four", bundle);
+        TtsSpan span = new TtsSpan("test.type.four", mBundle);
         span.getSpanTypeId();
     }
 
-    @SmallTest
+    @Test
     public void testWriteAndReadParcel() {
         Parcel p = Parcel.obtain();
         try {
-            TtsSpan span = new TtsSpan("test.type.five", bundle);
+            TtsSpan span = new TtsSpan("test.type.five", mBundle);
             span.writeToParcel(p, 0);
             p.setDataPosition(0);
 
@@ -87,7 +93,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testBuilder() {
         final TtsSpan t = new TtsSpan.Builder<>("test.type.builder")
                 .setStringArgument("argument.string", "value")
@@ -102,7 +108,7 @@
         assertEquals(Long.MAX_VALUE, args.getLong("argument.long"));
     }
 
-    @SmallTest
+    @Test
     public void testSemioticClassBuilder() {
         final TtsSpan t = new TtsSpan.SemioticClassBuilder<>("test.type.semioticClassBuilder")
                 .setGender(TtsSpan.GENDER_FEMALE)
@@ -119,7 +125,7 @@
         assertEquals(TtsSpan.CASE_NOMINATIVE, args.getString(TtsSpan.ARG_CASE));
     }
 
-    @SmallTest
+    @Test
     public void testTextBuilder() {
         {
             final TtsSpan t = new TtsSpan.TextBuilder()
@@ -139,7 +145,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testCardinalBuilder() {
         {
             final TtsSpan t = new TtsSpan.CardinalBuilder()
@@ -175,7 +181,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testOrdinalBuilder() {
         {
             final TtsSpan t = new TtsSpan.OrdinalBuilder()
@@ -211,7 +217,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDecimalBuilder() {
         {
             final TtsSpan t = new TtsSpan.DecimalBuilder()
@@ -316,7 +322,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testFractionBuilder() {
         {
             final TtsSpan t = new TtsSpan.FractionBuilder()
@@ -371,7 +377,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testMeasureBuilder() {
         {
             final TtsSpan t = new TtsSpan.MeasureBuilder()
@@ -441,7 +447,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testTimeBuilder() {
         {
             final TtsSpan t = new TtsSpan.TimeBuilder()
@@ -464,7 +470,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDateBuilder() {
         {
             final TtsSpan t = new TtsSpan.DateBuilder()
@@ -501,7 +507,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testMoneyBuilder() {
         {
             final TtsSpan t = new TtsSpan.MoneyBuilder()
@@ -534,7 +540,7 @@
 
     }
 
-    @SmallTest
+    @Test
     public void testTelephoneBuilder() {
         {
             final TtsSpan t = new TtsSpan.TelephoneBuilder()
@@ -558,7 +564,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testElectronicBuilder() {
         {
             final TtsSpan t = new TtsSpan.ElectronicBuilder()
@@ -595,7 +601,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testDigitsBuilder() {
         {
             final TtsSpan t = new TtsSpan.DigitsBuilder()
@@ -615,7 +621,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testVerbatimBuilder() {
         {
             final TtsSpan t = new TtsSpan.VerbatimBuilder()
diff --git a/tests/tests/text/src/android/text/style/cts/TypefaceSpanTest.java b/tests/tests/text/src/android/text/style/cts/TypefaceSpanTest.java
index 7a05167..ffc024a 100644
--- a/tests/tests/text/src/android/text/style/cts/TypefaceSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/TypefaceSpanTest.java
@@ -16,17 +16,26 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import android.graphics.Typeface;
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.TypefaceSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class TypefaceSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TypefaceSpanTest {
     private static final String FAMILY = "monospace";
 
+    @Test
     public void testConstructor() {
         TypefaceSpan t = new TypefaceSpan(FAMILY);
 
@@ -40,11 +49,13 @@
         }
     }
 
+    @Test
     public void testGetFamily() {
         TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
         assertEquals(FAMILY, typefaceSpan.getFamily());
     }
 
+    @Test
     public void testUpdateMeasureState() {
         TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
 
@@ -56,15 +67,16 @@
         assertNotNull(tp.getTypeface());
         // the style should be default style.
         assertEquals(Typeface.NORMAL, tp.getTypeface().getStyle());
-
-        try {
-            typefaceSpan.updateMeasureState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateMeasureStateNull() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+
+        typefaceSpan.updateMeasureState(null);
+    }
+
+    @Test
     public void testUpdateDrawState() {
         TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
 
@@ -76,25 +88,28 @@
         assertNotNull(tp.getTypeface());
         // the style should be default style.
         assertEquals(Typeface.NORMAL, tp.getTypeface().getStyle());
-
-        try {
-            typefaceSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+
+        typefaceSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
         typefaceSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
         typefaceSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/URLSpanTest.java b/tests/tests/text/src/android/text/style/cts/URLSpanTest.java
index 8fac2dd..067b56b 100644
--- a/tests/tests/text/src/android/text/style/cts/URLSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/URLSpanTest.java
@@ -16,30 +16,45 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.app.Instrumentation.ActivityMonitor;
 import android.os.Parcel;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.LargeTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.cts.R;
 import android.text.style.URLSpan;
 import android.widget.TextView;
 
-public class URLSpanTest extends ActivityInstrumentationTestCase2<URLSpanCtsActivity> {
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class URLSpanTest {
     // The scheme of TEST_URL must be "ctstesttext" to launch MockURLSpanTestActivity
     private static final String TEST_URL = "ctstesttext://urlSpan/test";
+
     private Activity mActivity;
 
-    public URLSpanTest() {
-        super("android.text.cts", URLSpanCtsActivity.class);
+    @Rule
+    public ActivityTestRule<URLSpanCtsActivity> mActivityRule =
+            new ActivityTestRule<>(URLSpanCtsActivity.class);
+
+    @Before
+    public void setup() {
+        mActivity = mActivityRule.getActivity();
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mActivity = getActivity();
-    }
-
+    @Test
     public void testConstructor() {
         URLSpan urlSpan = new URLSpan(TEST_URL);
 
@@ -53,51 +68,49 @@
         }
     }
 
+    @Test
     public void testGetURL() {
         URLSpan urlSpan = new URLSpan(TEST_URL);
         assertEquals(TEST_URL, urlSpan.getURL());
     }
 
-    public void testOnClick() {
+    @LargeTest
+    @Test
+    public void testOnClick() throws Throwable {
         final URLSpan urlSpan = new URLSpan(TEST_URL);
         final TextView textView = (TextView) mActivity.findViewById(R.id.url);
 
-        Instrumentation instrumentation = getInstrumentation();
+        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
         ActivityMonitor am = instrumentation.addMonitor(MockURLSpanTestActivity.class.getName(),
                 null, false);
 
-        try {
-            runTestOnUiThread(() -> urlSpan.onClick(textView));
-        } catch (Throwable e) {
-            fail("Exception error!");
-        }
+        mActivityRule.runOnUiThread(() -> urlSpan.onClick(textView));
 
         Activity newActivity = am.waitForActivityWithTimeout(5000);
         assertNotNull(newActivity);
         newActivity.finish();
     }
 
+    @Test(expected=NullPointerException.class)
     public void testOnClickFailure() {
         URLSpan urlSpan = new URLSpan(TEST_URL);
 
-        try {
-            urlSpan.onClick(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
+        urlSpan.onClick(null);
     }
 
+    @Test
     public void testDescribeContents() {
         URLSpan urlSpan = new URLSpan(TEST_URL);
         urlSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         URLSpan urlSpan = new URLSpan(TEST_URL);
         urlSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java b/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
index 4f200d2..0661833 100644
--- a/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
@@ -16,14 +16,22 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
 import android.text.style.UnderlineSpan;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class UnderlineSpanTest extends TestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class UnderlineSpanTest {
+    @Test
     public void testConstructor() {
         new UnderlineSpan();
 
@@ -35,6 +43,7 @@
         }
     }
 
+    @Test
     public void testUpdateDrawState() {
         UnderlineSpan underlineSpan = new UnderlineSpan();
 
@@ -44,25 +53,28 @@
 
         underlineSpan.updateDrawState(tp);
         assertTrue(tp.isUnderlineText());
-
-        try {
-            underlineSpan.updateDrawState(null);
-            fail("should throw NullPointerException.");
-        } catch (NullPointerException e) {
-            // expected, test success.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testUpdateDrawStateNull() {
+        UnderlineSpan underlineSpan = new UnderlineSpan();
+
+        underlineSpan.updateDrawState(null);
+    }
+
+    @Test
     public void testDescribeContents() {
         UnderlineSpan underlineSpan = new UnderlineSpan();
         underlineSpan.describeContents();
     }
 
+    @Test
     public void testGetSpanTypeId() {
         UnderlineSpan underlineSpan = new UnderlineSpan();
         underlineSpan.getSpanTypeId();
     }
 
+    @Test
     public void testWriteToParcel() {
         Parcel p = Parcel.obtain();
         try {
diff --git a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
index c23f45f..d20792e 100644
--- a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
+++ b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
@@ -16,9 +16,15 @@
 
 package android.text.util.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
-import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.style.URLSpan;
@@ -28,6 +34,10 @@
 import android.util.Patterns;
 import android.widget.TextView;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -35,26 +45,26 @@
 /**
  * Test {@link Linkify}.
  */
-public class LinkifyTest extends AndroidTestCase {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class LinkifyTest {
     private static final Pattern LINKIFY_TEST_PATTERN = Pattern.compile(
             "(test:)?[a-zA-Z0-9]+(\\.pattern)?");
 
-    private MatchFilter mMatchFilterStartWithDot = new MatchFilter() {
-        public final boolean acceptMatch(final CharSequence s, final int start, final int end) {
-            if (start == 0) {
+    private MatchFilter mMatchFilterStartWithDot =
+            (final CharSequence s, final int start, final int end) -> {
+                if (start == 0) {
+                    return true;
+                }
+
+                if (s.charAt(start - 1) == '.') {
+                    return false;
+                }
+
                 return true;
-            }
+            };
 
-            if (s.charAt(start - 1) == '.') {
-                return false;
-            }
-
-            return true;
-        }
-    };
-
-    private TransformFilter mTransformFilterUpperChar = new TransformFilter() {
-        public final String transformUrl(final Matcher match, String url) {
+    private TransformFilter mTransformFilterUpperChar = (final Matcher match, String url) -> {
             StringBuilder buffer = new StringBuilder();
             String matchingRegion = match.group();
 
@@ -67,14 +77,22 @@
                 }
             }
             return buffer.toString();
-        }
-    };
+        };
 
+    private Context mContext;
+
+    @Before
+    public void setup() {
+        mContext = InstrumentationRegistry.getTargetContext();
+    }
+
+    @Test
     public void testConstructor() {
         new Linkify();
     }
 
-    public void testAddLinks1() {
+    @Test
+    public void testAddLinksToSpannable() {
         // Verify URLs including the ones that have new gTLDs, and the
         // ones that look like gTLDs (and so are accepted by linkify)
         // and the ones that should not be linkified due to non-compliant
@@ -101,44 +119,45 @@
         assertEquals(1, spans.length);
         assertEquals("mailto:name@gmail.com", spans[0].getURL());
 
-        try {
-            Linkify.addLinks((Spannable) null, Linkify.WEB_URLS);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
         assertFalse(Linkify.addLinks((Spannable) null, 0));
     }
 
-    public void testAddLinks2() {
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToSpannableNullWithWebUrls() {
+        Linkify.addLinks((Spannable) null, Linkify.WEB_URLS);
+    }
+
+    @UiThreadTest
+    @Test
+    public void testAddLinksToTextView() {
         String text = "www.google.com, name@gmail.com";
         TextView tv = new TextView(mContext);
         tv.setText(text);
 
         assertTrue(Linkify.addLinks(tv, Linkify.WEB_URLS));
-        URLSpan[] spans = ((Spannable)tv.getText()).getSpans(0, text.length(), URLSpan.class);
+        URLSpan[] spans = ((Spannable) tv.getText()).getSpans(0, text.length(), URLSpan.class);
         assertEquals(1, spans.length);
         assertEquals("http://www.google.com", spans[0].getURL());
 
         SpannableString spannable = SpannableString.valueOf(text);
         tv.setText(spannable);
         assertTrue(Linkify.addLinks(tv, Linkify.EMAIL_ADDRESSES));
-        spans = ((Spannable)tv.getText()).getSpans(0, text.length(), URLSpan.class);
+        spans = ((Spannable) tv.getText()).getSpans(0, text.length(), URLSpan.class);
         assertEquals(1, spans.length);
         assertEquals("mailto:name@gmail.com", spans[0].getURL());
 
-        try {
-            Linkify.addLinks((TextView)null, Linkify.WEB_URLS);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
-        assertFalse(Linkify.addLinks((TextView)null, 0));
+        assertFalse(Linkify.addLinks((TextView) null, 0));
     }
 
-    public void testAddLinks3() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToTextViewNullWithWebUrls() {
+        Linkify.addLinks((TextView) null, Linkify.WEB_URLS);
+    }
+
+    @UiThreadTest
+    @Test
+    public void testAddLinksToTextViewWithScheme() {
         String text = "Alan, Charlie";
         TextView tv = new TextView(mContext);
         tv.setText(text);
@@ -157,20 +176,6 @@
         assertEquals("test:google.pattern", spans[0].getURL());
         assertEquals("test:AZ0101.pattern", spans[1].getURL());
 
-        try {
-            Linkify.addLinks((TextView) null, LINKIFY_TEST_PATTERN, "Test:");
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
-        try {
-            Linkify.addLinks(tv, null, "Test:");
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
         tv = new TextView(mContext);
         tv.setText(text);
         Linkify.addLinks(tv, LINKIFY_TEST_PATTERN, null);
@@ -180,10 +185,26 @@
         assertEquals("test:AZ0101.pattern", spans[1].getURL());
     }
 
-    public void testAddLinks4() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToTextViewWithSchemeNullView() {
+        Linkify.addLinks((TextView) null, LINKIFY_TEST_PATTERN, "Test:");
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToTextViewWithSchemeNullPattern() {
+        TextView tv = new TextView(mContext);
+        tv.setText("Alan, Charlie");
+        Linkify.addLinks(tv, null, "Test:");
+    }
+
+    @UiThreadTest
+    @Test
+    public void testAddLinksToTextViewWithSchemeAndFilter() {
         TextView tv = new TextView(mContext);
 
-        String text =  "FilterUpperCase.pattern, 12.345.pattern";
+        String text = "FilterUpperCase.pattern, 12.345.pattern";
         tv.setText(text);
         Linkify.addLinks(tv, LINKIFY_TEST_PATTERN, "Test:",
                 mMatchFilterStartWithDot, mTransformFilterUpperChar);
@@ -192,22 +213,6 @@
         assertEquals("test:ilterpperase.pattern", spans[0].getURL());
         assertEquals("test:12", spans[1].getURL());
 
-        try {
-            Linkify.addLinks((TextView) null, LINKIFY_TEST_PATTERN, "Test:",
-                    mMatchFilterStartWithDot, mTransformFilterUpperChar);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
-        try {
-            Linkify.addLinks(tv, null, "Test:",
-                    mMatchFilterStartWithDot, mTransformFilterUpperChar);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
         tv.setText(text);
         Linkify.addLinks(tv, LINKIFY_TEST_PATTERN, null,
                 mMatchFilterStartWithDot, mTransformFilterUpperChar);
@@ -232,7 +237,24 @@
         assertEquals("test:12", spans[1].getURL());
     }
 
-    public void testAddLinks5() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToTextViewWithSchemeAndFilterNullView() {
+        Linkify.addLinks((TextView) null, LINKIFY_TEST_PATTERN, "Test:",
+                mMatchFilterStartWithDot, mTransformFilterUpperChar);
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToTextViewWithSchemeAndFilterNullPattern() {
+        TextView tv = new TextView(mContext);
+        tv.setText("FilterUpperCase.pattern, 12.345.pattern");
+        Linkify.addLinks(tv, null, "Test:",
+                mMatchFilterStartWithDot, mTransformFilterUpperChar);
+    }
+
+    @Test
+    public void testAddLinksToSpannableWithScheme() {
         String text = "google.pattern, test:AZ0101.pattern";
 
         SpannableString spannable = new SpannableString(text);
@@ -242,18 +264,6 @@
         assertEquals("test:google.pattern", spans[0].getURL());
         assertEquals("test:AZ0101.pattern", spans[1].getURL());
 
-        try {
-            Linkify.addLinks((Spannable)null, LINKIFY_TEST_PATTERN, "Test:");
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-        }
-
-        try {
-            Linkify.addLinks(spannable, null, "Test:");
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-        }
-
         spannable = new SpannableString(text);
         Linkify.addLinks(spannable, LINKIFY_TEST_PATTERN, null);
         spans = (spannable.getSpans(0, spannable.length(), URLSpan.class));
@@ -262,7 +272,23 @@
         assertEquals("test:AZ0101.pattern", spans[1].getURL());
     }
 
-    public void testAddLinks6() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToSpannableWithSchemeNullSpannable() {
+        Linkify.addLinks((Spannable)null, LINKIFY_TEST_PATTERN, "Test:");
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToSpannableWithSchemeNullPattern() {
+        String text = "google.pattern, test:AZ0101.pattern";
+        SpannableString spannable = new SpannableString(text);
+
+        Linkify.addLinks(spannable, null, "Test:");
+    }
+
+    @Test
+    public void testAddLinksToSpannableWithSchemeAndFilter() {
         String text = "FilterUpperCase.pattern, 12.345.pattern";
 
         SpannableString spannable = new SpannableString(text);
@@ -273,22 +299,6 @@
         assertEquals("test:ilterpperase.pattern", spans[0].getURL());
         assertEquals("test:12", spans[1].getURL());
 
-        try {
-            Linkify.addLinks((Spannable)null, LINKIFY_TEST_PATTERN, "Test:",
-                    mMatchFilterStartWithDot, mTransformFilterUpperChar);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
-        try {
-            Linkify.addLinks(spannable, null, "Test:", mMatchFilterStartWithDot,
-                    mTransformFilterUpperChar);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
         spannable = new SpannableString(text);
         Linkify.addLinks(spannable, LINKIFY_TEST_PATTERN, null, mMatchFilterStartWithDot,
                 mTransformFilterUpperChar);
@@ -313,7 +323,25 @@
         assertEquals("test:12", spans[1].getURL());
     }
 
-    public void testAddLinks7() {
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToSpannableWithSchemeAndFilterNullSpannable() {
+        Linkify.addLinks((Spannable)null, LINKIFY_TEST_PATTERN, "Test:",
+                mMatchFilterStartWithDot, mTransformFilterUpperChar);
+    }
+
+    @UiThreadTest
+    @Test(expected=NullPointerException.class)
+    public void testAddLinksToSpannableWithSchemeAndFilterNullPattern() {
+        String text = "FilterUpperCase.pattern, 12.345.pattern";
+        SpannableString spannable = new SpannableString(text);
+
+        Linkify.addLinks(spannable, null, "Test:", mMatchFilterStartWithDot,
+                mTransformFilterUpperChar);
+    }
+
+    @Test
+    public void testAddLinksPhoneNumbers() {
         String numbersInvalid = "123456789 not a phone number";
         String numbersUKLocal = "tel:(0812)1234560 (0812)1234561";
         String numbersUSLocal = "tel:(812)1234562 (812)123.4563 "
@@ -342,17 +370,10 @@
             assertEquals("tel:+18005551214", spans[8].getURL());
         }
 
-        try {
-            Linkify.addLinks((Spannable) null, Linkify.WEB_URLS);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // expect
-        }
-
         assertFalse(Linkify.addLinks((Spannable) null, 0));
     }
 
-    @SmallTest
+    @Test
     public void testAddLinks_addsLinksWhenDefaultSchemeIsNull() {
         Spannable spannable = new SpannableString("any https://android.com any android.com any");
         Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, null, null, null);
@@ -363,7 +384,7 @@
         assertEquals("android.com", spans[1].getURL());
     }
 
-    @SmallTest
+    @Test
     public void testAddLinks_addsLinksWhenSchemesArrayIsNull() {
         Spannable spannable = new SpannableString("any https://android.com any android.com any");
         Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://", null, null);
@@ -375,7 +396,7 @@
         assertEquals("http://android.com", spans[1].getURL());
     }
 
-    @SmallTest
+    @Test
     public void testAddLinks_prependsDefaultSchemeToBeginingOfLink() {
         Spannable spannable = new SpannableString("any android.com any");
         Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://",
@@ -386,7 +407,7 @@
         assertEquals("http://android.com", spans[0].getURL());
     }
 
-    @SmallTest
+    @Test
     public void testAddLinks_doesNotPrependSchemeIfSchemeExists() {
         Spannable spannable = new SpannableString("any https://android.com any");
         Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://",
@@ -399,7 +420,8 @@
 
     // Add links with scheme (array)
 
-    @SmallTest
+    @UiThreadTest
+    @Test
     public void testAddLinks_withTextView_addsLinksWhenDefaultSchemeIsNull() {
         Pattern pattern = Pattern.compile("\\b((http|https)://)?android\\.com+\\b");
         TextView textView = new TextView(mContext);
@@ -413,7 +435,8 @@
         assertEquals("android.com", spans[1].getURL());
     }
 
-    @SmallTest
+    @UiThreadTest
+    @Test
     public void testAddLinks_withTextView_addsLinksWhenSchemesArrayIsNull() {
         Pattern pattern = Pattern.compile("\\b((http|https)://)?android\\.com+\\b");
         TextView textView = new TextView(mContext);
@@ -428,7 +451,8 @@
         assertEquals("http://android.com", spans[1].getURL());
     }
 
-    @SmallTest
+    @UiThreadTest
+    @Test
     public void testAddLinks_withTextView_prependsDefaultSchemeToBeginingOfLink() {
         Pattern pattern = Pattern.compile("\\b((http|https)://)?android\\.com+\\b");
         TextView textView = new TextView(mContext);
@@ -442,7 +466,8 @@
         assertEquals("http://android.com", spans[0].getURL());
     }
 
-    @SmallTest
+    @UiThreadTest
+    @Test
     public void testAddLinks_withTextView_doesNotPrependSchemeIfSchemeExists() {
         Pattern pattern = Pattern.compile("\\b((http|https)://)?android\\.com+\\b");
         TextView textView = new TextView(mContext);
@@ -458,182 +483,183 @@
 
     // WEB_URLS Related Tests
 
-    @SmallTest
+    @Test
     public void testAddLinks_doesNotAddLinksForUrlWithoutProtocolAndWithoutKnownTld()
-            throws Exception {
+            {
         Spannable spannable = new SpannableString("hey man.its me");
         boolean linksAdded = Linkify.addLinks(spannable, Linkify.ALL);
         assertFalse("Should not add link with unknown TLD", linksAdded);
     }
 
-    @SmallTest
-    public void testAddLinks_shouldNotAddEmailAddressAsUrl() throws Exception {
+    @Test
+    public void testAddLinks_shouldNotAddEmailAddressAsUrl() {
         String url = "name@gmail.com";
-        assertAddLinksWithWebUrlFails("Should not recognize email address as URL", url);
+        verifyAddLinksWithWebUrlFails("Should not recognize email address as URL", url);
     }
 
-    public void testAddLinks_acceptsUrlsWithCommasInRequestParameterValues() throws Exception {
+    @Test
+    public void testAddLinks_acceptsUrlsWithCommasInRequestParameterValues() {
         String url = "https://android.com/path?ll=37.4221,-122.0836&z=17&pll=37.4221,-122.0836";
-        assertAddLinksWithWebUrlSucceeds("Should accept commas", url);
+        verifyAddLinksWithWebUrlSucceeds("Should accept commas", url);
     }
 
-    @SmallTest
-    public void testAddLinks_addsLinksForUrlWithProtocolWithoutTld() throws Exception {
+    @Test
+    public void testAddLinks_addsLinksForUrlWithProtocolWithoutTld() {
         String url = "http://android/#notld///a/n/d/r/o/i/d&p1=1&p2=2";
-        assertAddLinksWithWebUrlSucceeds("Should accept URL starting with protocol but does not" +
+        verifyAddLinksWithWebUrlSucceeds("Should accept URL starting with protocol but does not" +
                 " have TLD", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesProtocolCaseInsensitive() throws Exception {
+    @Test
+    public void testAddLinks_matchesProtocolCaseInsensitive() {
         String url = "hTtP://android.com";
-        assertAddLinksWithWebUrlSucceeds("Protocol matching should be case insensitive", url);
+        verifyAddLinksWithWebUrlSucceeds("Protocol matching should be case insensitive", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesValidUrlWithSchemeAndHostname() throws Exception {
+    @Test
+    public void testAddLinks_matchesValidUrlWithSchemeAndHostname() {
         String url = "http://www.android.com";
-        assertAddLinksWithWebUrlSucceeds("Should match valid URL with scheme and hostname", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match valid URL with scheme and hostname", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesValidUrlWithSchemeHostnameAndNewTld() throws Exception {
+    @Test
+    public void testAddLinks_matchesValidUrlWithSchemeHostnameAndNewTld() {
         String url = "http://www.android.me";
-        assertAddLinksWithWebUrlSucceeds("Should match valid URL with scheme hostname and new TLD",
+        verifyAddLinksWithWebUrlSucceeds("Should match valid URL with scheme hostname and new TLD",
                 url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesValidUrlWithHostnameAndNewTld() throws Exception {
+    @Test
+    public void testAddLinks_matchesValidUrlWithHostnameAndNewTld() {
         String url = "android.camera";
-        assertAddLinksWithWebUrlSucceeds("Should match valid URL with hostname and new TLD", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match valid URL with hostname and new TLD", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesPunycodeUrl() throws Exception {
+    @Test
+    public void testAddLinks_matchesPunycodeUrl() {
         String url = "http://xn--fsqu00a.xn--unup4y";
-        assertAddLinksWithWebUrlSucceeds("Should match Punycode URL", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match Punycode URL", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesPunycodeUrlWithoutProtocol() throws Exception {
+    @Test
+    public void testAddLinks_matchesPunycodeUrlWithoutProtocol() {
         String url = "xn--fsqu00a.xn--unup4y";
-        assertAddLinksWithWebUrlSucceeds("Should match Punycode URL without protocol", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match Punycode URL without protocol", url);
     }
 
-    @SmallTest
-    public void testAddLinks_doesNotMatchPunycodeTldThatStartsWithDash() throws Exception {
+    @Test
+    public void testAddLinks_doesNotMatchPunycodeTldThatStartsWithDash() {
         String url = "xn--fsqu00a.-xn--unup4y";
-        assertAddLinksWithWebUrlFails("Should not match Punycode TLD that starts with dash", url);
+        verifyAddLinksWithWebUrlFails("Should not match Punycode TLD that starts with dash", url);
     }
 
-    @SmallTest
-    public void testAddLinks_partiallyMatchesPunycodeTldThatEndsWithDash() throws Exception {
+    @Test
+    public void testAddLinks_partiallyMatchesPunycodeTldThatEndsWithDash() {
         String url = "http://xn--fsqu00a.xn--unup4y-";
-        assertAddLinksWithWebUrlPartiallyMatches("Should partially match Punycode TLD that ends " +
+        verifyAddLinksWithWebUrlPartiallyMatches("Should partially match Punycode TLD that ends " +
                 "with dash", "http://xn--fsqu00a.xn--unup4y", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithUnicodeDomainName() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithUnicodeDomainName() {
         String url = "http://\uD604\uAE08\uC601\uC218\uC99D.kr";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with Unicode domain name", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with Unicode domain name", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithUnicodeDomainNameWithoutProtocol() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithUnicodeDomainNameWithoutProtocol() {
         String url = "\uD604\uAE08\uC601\uC218\uC99D.kr";
-        assertAddLinksWithWebUrlSucceeds("Should match URL without protocol and with Unicode " +
+        verifyAddLinksWithWebUrlSucceeds("Should match URL without protocol and with Unicode " +
                 "domain name", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithUnicodeDomainNameAndTld() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithUnicodeDomainNameAndTld() {
         String url = "\uB3C4\uBA54\uC778.\uD55C\uAD6D";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with Unicode domain name and TLD", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with Unicode domain name and TLD", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithUnicodePath() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithUnicodePath() {
         String url = "http://android.com/\u2019/a";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with Unicode path", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with Unicode path", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesValidUrlWithPort() throws Exception {
+    @Test
+    public void testAddLinks_matchesValidUrlWithPort() {
         String url = "http://www.example.com:8080";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with port", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with port", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithPortAndQuery() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithPortAndQuery() {
         String url = "http://www.example.com:8080/?foo=bar";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with port and query", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with port and query", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlWithTilde() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlWithTilde() {
         String url = "http://www.example.com:8080/~user/?foo=bar";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with tilde", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with tilde", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesUrlStartingWithHttpAndDoesNotHaveTld() throws Exception {
+    @Test
+    public void testAddLinks_matchesUrlStartingWithHttpAndDoesNotHaveTld() {
         String url = "http://android/#notld///a/n/d/r/o/i/d&p1=1&p2=2";
-        assertAddLinksWithWebUrlSucceeds("Should match URL without a TLD and starting with http",
+        verifyAddLinksWithWebUrlSucceeds("Should match URL without a TLD and starting with http",
                 url);
     }
 
-    @SmallTest
-    public void testAddLinks_doesNotMatchUrlsWithoutProtocolAndWithUnknownTld() throws Exception {
+    @Test
+    public void testAddLinks_doesNotMatchUrlsWithoutProtocolAndWithUnknownTld() {
         String url = "thank.you";
-        assertAddLinksWithWebUrlFails("Should not match URL that does not start with a protocol " +
+        verifyAddLinksWithWebUrlFails("Should not match URL that does not start with a protocol " +
                 "and does not contain a known TLD", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesValidUrlWithEmoji() throws Exception {
+    @Test
+    public void testAddLinks_matchesValidUrlWithEmoji() {
         String url = "Thank\u263A.com";
-        assertAddLinksWithWebUrlSucceeds("Should match URL with emoji", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match URL with emoji", url);
     }
 
-    @SmallTest
+    @Test
     public void testAddLinks_doesNotMatchUrlsWithEmojiWithoutProtocolAndWithoutKnownTld()
-            throws Exception {
+            {
         String url = "Thank\u263A.you";
-        assertAddLinksWithWebUrlFails("Should not match URLs containing emoji and with unknown " +
+        verifyAddLinksWithWebUrlFails("Should not match URLs containing emoji and with unknown " +
                 "TLD", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesDomainNameWithSurrogatePairs() throws Exception {
+    @Test
+    public void testAddLinks_matchesDomainNameWithSurrogatePairs() {
         String url = "android\uD83C\uDF38.com";
-        assertAddLinksWithWebUrlSucceeds("Should match domain name with Unicode surrogate pairs",
+        verifyAddLinksWithWebUrlSucceeds("Should match domain name with Unicode surrogate pairs",
                 url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesTldWithSurrogatePairs() throws Exception {
+    @Test
+    public void testAddLinks_matchesTldWithSurrogatePairs() {
         String url = "http://android.\uD83C\uDF38com";
-        assertAddLinksWithWebUrlSucceeds("Should match TLD with Unicode surrogate pairs", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match TLD with Unicode surrogate pairs", url);
     }
 
-    @SmallTest
-    public void testAddLinks_doesNotMatchUrlWithExcludedSurrogate() throws Exception {
+    @Test
+    public void testAddLinks_doesNotMatchUrlWithExcludedSurrogate() {
         String url = "android\uD83F\uDFFE.com";
-        assertAddLinksWithWebUrlFails("Should not match URL with excluded Unicode surrogate" +
+        verifyAddLinksWithWebUrlFails("Should not match URL with excluded Unicode surrogate" +
                 " pair",  url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesPathWithSurrogatePairs() throws Exception {
+    @Test
+    public void testAddLinks_matchesPathWithSurrogatePairs() {
         String url = "http://android.com/path-with-\uD83C\uDF38?v=\uD83C\uDF38f";
-        assertAddLinksWithWebUrlSucceeds("Should match path and query with Unicode surrogate pairs",
+        verifyAddLinksWithWebUrlSucceeds("Should match path and query with Unicode surrogate pairs",
                 url);
     }
 
-    @SmallTest
-    public void testAddLinks__doesNotMatchUnicodeSpaces() throws Exception {
+    @Test
+    public void testAddLinks__doesNotMatchUnicodeSpaces() {
         String part1 = "http://and";
         String part2 = "roid.com";
         String[] emptySpaces = new String[]{
@@ -657,238 +683,269 @@
 
         for (String emptySpace : emptySpaces) {
             String url = part1 + emptySpace + part2;
-            assertAddLinksWithWebUrlPartiallyMatches("Should not include empty space with code: " +
+            verifyAddLinksWithWebUrlPartiallyMatches("Should not include empty space with code: " +
                     emptySpace.codePointAt(0), part1, url);
         }
     }
 
-    @SmallTest
-    public void testAddLinks_matchesDomainNameWithDash() throws Exception {
+    @Test
+    public void testAddLinks_matchesDomainNameWithDash() {
         String url = "http://a-nd.r-oid.com";
-        assertAddLinksWithWebUrlSucceeds("Should match domain name with '-'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match domain name with '-'", url);
 
         url = "a-nd.r-oid.com";
-        assertAddLinksWithWebUrlSucceeds("Should match domain name with '-'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match domain name with '-'", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesDomainNameWithUnderscore() throws Exception {
+    @Test
+    public void testAddLinks_matchesDomainNameWithUnderscore() {
         String url = "http://a_nd.r_oid.com";
-        assertAddLinksWithWebUrlSucceeds("Should match domain name with '_'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match domain name with '_'", url);
 
         url = "a_nd.r_oid.com";
-        assertAddLinksWithWebUrlSucceeds("Should match domain name with '_'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match domain name with '_'", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesPathAndQueryWithDollarSign() throws Exception {
+    @Test
+    public void testAddLinks_matchesPathAndQueryWithDollarSign() {
         String url = "http://android.com/path$?v=$val";
-        assertAddLinksWithWebUrlSucceeds("Should match path and query with '$'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match path and query with '$'", url);
 
         url = "android.com/path$?v=$val";
-        assertAddLinksWithWebUrlSucceeds("Should match path and query with '$'", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match path and query with '$'", url);
     }
 
-    @SmallTest
-    public void testAddLinks_matchesEmptyPathWithQueryParams() throws Exception {
+    @Test
+    public void testAddLinks_matchesEmptyPathWithQueryParams() {
         String url = "http://android.com?q=v";
-        assertAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
 
         url = "android.com?q=v";
-        assertAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
 
         url = "http://android.com/?q=v";
-        assertAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
 
         url = "android.com/?q=v";
-        assertAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
+        verifyAddLinksWithWebUrlSucceeds("Should match empty path with query params", url);
     }
 
     // EMAIL_ADDRESSES Related Tests
 
-    public void testAddLinks_email_matchesShortValidEmail() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesShortValidEmail() {
         String email = "a@a.co";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesRegularEmail() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesRegularEmail() {
         String email = "email@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesEmailWithMultipleSubdomains() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesEmailWithMultipleSubdomains() {
         String email = "email@e.somelongdomainnameforandroid.abc.uk";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithDot() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithDot() {
         String email = "e.mail@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithPlus() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithPlus() {
         String email = "e+mail@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithUnderscore() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithUnderscore() {
         String email = "e_mail@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithDash() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithDash() {
         String email = "e-mail@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithApostrophe() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithApostrophe() {
         String email = "e'mail@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithDigits() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithDigits() {
         String email = "123@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesUnicodeLocalPart() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesUnicodeLocalPart() {
         String email = "\uD604\uAE08\uC601\uC218\uC99D@android.kr";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartWithEmoji() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartWithEmoji() {
         String email = "smiley\u263A@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_matchesLocalPartWithSurrogatePairs()
-            throws Exception {
+            {
         String email = "a\uD83C\uDF38a@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesDomainWithDash() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesDomainWithDash() {
         String email = "email@an-droid.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesUnicodeDomain() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesUnicodeDomain() {
         String email = "email@\uD604\uAE08\uC601\uC218\uC99D.kr";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_matchesUnicodeLocalPartAndDomain()
-            throws Exception {
+            {
         String email = "\uD604\uAE08\uC601\uC218\uC99D@\uD604\uAE08\uC601\uC218\uC99D.kr";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesDomainWithEmoji() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesDomainWithEmoji() {
         String email = "smiley@\u263Aandroid.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_matchesDomainWithSurrogatePairs()
-            throws Exception {
+            {
         String email = "email@\uD83C\uDF38android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_matchesLocalPartAndDomainWithSurrogatePairs()
-            throws Exception {
+            {
         String email = "a\uD83C\uDF38a@\uD83C\uDF38android.com";
-        assertAddLinksWithEmailSucceeds("Should match email: " + email, email);
+        verifyAddLinksWithEmailSucceeds("Should match email: " + email, email);
     }
 
-    public void testAddLinks_partiallyMatchesEmailEndingWithDot() throws Exception {
+    @Test
+    public void testAddLinks_partiallyMatchesEmailEndingWithDot() {
         String email = "email@android.co.uk.";
-        assertAddLinksWithEmailPartiallyMatches("Should partially match email ending with dot",
+        verifyAddLinksWithEmailPartiallyMatches("Should partially match email ending with dot",
                 "mailto:email@android.co.uk", email);
     }
 
+    @Test
     public void testAddLinks_email_partiallyMatchesLocalPartStartingWithDot()
-            throws Exception {
+            {
         String email = ".email@android.com";
-        assertAddLinksWithEmailPartiallyMatches("Should partially match email starting " +
+        verifyAddLinksWithEmailPartiallyMatches("Should partially match email starting " +
                 "with dot", "mailto:email@android.com", email);
     }
 
-    public void testAddLinks_email_doesNotMatchStringWithoutAtSign() throws Exception {
+    @Test
+    public void testAddLinks_email_doesNotMatchStringWithoutAtSign() {
         String email = "android.com";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
-    public void testAddLinks_email_doesNotMatchPlainString() throws Exception {
+    @Test
+    public void testAddLinks_email_doesNotMatchPlainString() {
         String email = "email";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
-    public void testAddLinks_email_doesNotMatchEmailWithoutTld() throws Exception {
+    @Test
+    public void testAddLinks_email_doesNotMatchEmailWithoutTld() {
         String email = "email@android";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_doesNotMatchLocalPartEndingWithDot()
-            throws Exception {
+            {
         String email = "email.@android.com";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_doesNotMatchDomainStartingWithDash()
-            throws Exception {
+            {
         String email = "email@-android.com";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_doesNotMatchDomainWithConsecutiveDots()
-            throws Exception {
+            {
         String email = "email@android..com";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
-    public void testAddLinks_email_doesNotMatchEmailWithIp() throws Exception {
+    @Test
+    public void testAddLinks_email_doesNotMatchEmailWithIp() {
         String email = "email@127.0.0.1";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
+    @Test
     public void testAddLinks_email_doesNotMatchEmailWithInvalidTld()
-            throws Exception {
+            {
         String email = "email@android.c";
-        assertAddLinksWithEmailFails("Should not match email: " + email, email);
+        verifyAddLinksWithEmailFails("Should not match email: " + email, email);
     }
 
-    public void testAddLinks_email_matchesLocalPartUpTo64Chars() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesLocalPartUpTo64Chars() {
         String localPart = "";
         for (int i = 0; i < 64; i++) {
             localPart += "a";
         }
         String email = localPart + "@android.com";
-        assertAddLinksWithEmailSucceeds("Should match email local part of length: " +
+        verifyAddLinksWithEmailSucceeds("Should match email local part of length: " +
                 localPart.length(), email);
 
         email = localPart + "a@android.com";
-        assertAddLinksWithEmailFails("Should not match email local part of length:" +
+        verifyAddLinksWithEmailFails("Should not match email local part of length:" +
                 localPart.length(), email);
     }
 
-    public void testAddLinks_email_matchesSubdomainUpTo63Chars() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesSubdomainUpTo63Chars() {
         String subdomain = "";
         for (int i = 0; i < 63; i++) {
             subdomain += "a";
         }
         String email = "email@" + subdomain + ".com";
 
-        assertAddLinksWithEmailSucceeds("Should match email subdomain of length: " +
+        verifyAddLinksWithEmailSucceeds("Should match email subdomain of length: " +
                 subdomain.length(), email);
 
         subdomain += "a";
         email = "email@" + subdomain + ".com";
 
-        assertAddLinksWithEmailFails("Should not match email subdomain of length:" +
+        verifyAddLinksWithEmailFails("Should not match email subdomain of length:" +
                 subdomain.length(), email);
     }
 
-    public void testAddLinks_email_matchesDomainUpTo255Chars() throws Exception {
+    @Test
+    public void testAddLinks_email_matchesDomainUpTo255Chars() {
         String domain = "";
         while (domain.length() <= 250) {
             domain += "d.";
@@ -896,42 +953,42 @@
         domain += "com";
         assertEquals(255, domain.length());
         String email = "a@" + domain;
-        assertAddLinksWithEmailSucceeds("Should match email domain of length: " +
+        verifyAddLinksWithEmailSucceeds("Should match email domain of length: " +
                 domain.length(), email);
 
         email = email + "m";
-        assertAddLinksWithEmailFails("Should not match email domain of length:" +
+        verifyAddLinksWithEmailFails("Should not match email domain of length:" +
                 domain.length(), email);
     }
 
     // Utility functions
-    private static void assertAddLinksWithWebUrlSucceeds(String msg, String url) {
-        assertAddLinksSucceeds(msg, url, Linkify.WEB_URLS);
+    private static void verifyAddLinksWithWebUrlSucceeds(String msg, String url) {
+        verifyAddLinksSucceeds(msg, url, Linkify.WEB_URLS);
     }
 
-    private static void assertAddLinksWithWebUrlFails(String msg, String url) {
-        assertAddLinksFails(msg, url, Linkify.WEB_URLS);
+    private static void verifyAddLinksWithWebUrlFails(String msg, String url) {
+        verifyAddLinksFails(msg, url, Linkify.WEB_URLS);
     }
 
-    private static void assertAddLinksWithWebUrlPartiallyMatches(String msg, String expected,
+    private static void verifyAddLinksWithWebUrlPartiallyMatches(String msg, String expected,
             String url) {
-        assertAddLinksPartiallyMatches(msg, expected, url, Linkify.WEB_URLS);
+        verifyAddLinksPartiallyMatches(msg, expected, url, Linkify.WEB_URLS);
     }
 
-    private static void assertAddLinksWithEmailSucceeds(String msg, String url) {
-        assertAddLinksSucceeds(msg, url, Linkify.EMAIL_ADDRESSES);
+    private static void verifyAddLinksWithEmailSucceeds(String msg, String url) {
+        verifyAddLinksSucceeds(msg, url, Linkify.EMAIL_ADDRESSES);
     }
 
-    private static void assertAddLinksWithEmailFails(String msg, String url) {
-        assertAddLinksFails(msg, url, Linkify.EMAIL_ADDRESSES);
+    private static void verifyAddLinksWithEmailFails(String msg, String url) {
+        verifyAddLinksFails(msg, url, Linkify.EMAIL_ADDRESSES);
     }
 
-    private static void assertAddLinksWithEmailPartiallyMatches(String msg, String expected,
+    private static void verifyAddLinksWithEmailPartiallyMatches(String msg, String expected,
             String url) {
-        assertAddLinksPartiallyMatches(msg, expected, url, Linkify.EMAIL_ADDRESSES);
+        verifyAddLinksPartiallyMatches(msg, expected, url, Linkify.EMAIL_ADDRESSES);
     }
 
-    private static void assertAddLinksSucceeds(String msg, String string, int type) {
+    private static void verifyAddLinksSucceeds(String msg, String string, int type) {
         String str = "start " + string + " end";
         Spannable spannable = new SpannableString(str);
 
@@ -945,14 +1002,14 @@
                 str.length() - " end".length(), spannable.getSpanEnd(spans[0]));
     }
 
-    private static void assertAddLinksFails(String msg, String string, int type) {
+    private static void verifyAddLinksFails(String msg, String string, int type) {
         Spannable spannable = new SpannableString("start " + string + " end");
         boolean linksAdded = Linkify.addLinks(spannable, type);
         assertFalse(msg, linksAdded);
     }
 
-    private static void assertAddLinksPartiallyMatches(String msg, String expected,
-                                                       String string, int type) {
+    private static void verifyAddLinksPartiallyMatches(String msg, String expected,
+            String string, int type) {
         Spannable spannable = new SpannableString("start " + string + " end");
         boolean linksAdded = Linkify.addLinks(spannable, type);
         URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
diff --git a/tests/tests/text/src/android/text/util/cts/Rfc822TokenTest.java b/tests/tests/text/src/android/text/util/cts/Rfc822TokenTest.java
index fc826df..47c4544 100644
--- a/tests/tests/text/src/android/text/util/cts/Rfc822TokenTest.java
+++ b/tests/tests/text/src/android/text/util/cts/Rfc822TokenTest.java
@@ -16,14 +16,23 @@
 
 package android.text.util.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
-import android.test.AndroidTestCase;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.util.Rfc822Token;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Test {@link Rfc822Token}.
  */
-public class Rfc822TokenTest extends AndroidTestCase {
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class Rfc822TokenTest {
+    @Test
     public void testConstructor() {
         final String name = "John Doe";
         final String address = "jdoe@example.net";
@@ -49,6 +58,7 @@
         assertNull(rfc822Token4.getComment());
     }
 
+    @Test
     public void testAccessName() {
         String name = "John Doe";
         final String address = "jdoe@example.net";
@@ -68,19 +78,19 @@
         assertNull(rfc822Token.getName());
     }
 
+    @Test
     public void testQuoteComment() {
         assertEquals("work", Rfc822Token.quoteComment("work"));
 
         assertEquals("\\\\\\(work\\)", Rfc822Token.quoteComment("\\(work)"));
-
-        try {
-            Rfc822Token.quoteComment(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed to happen if comment is null.
-        }
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testQuoteCommentNull() {
+        Rfc822Token.quoteComment(null);
+    }
+
+    @Test
     public void testAccessComment() {
         final String name = "John Doe";
         final String address = "jdoe@example.net";
@@ -100,6 +110,7 @@
         assertNull(rfc822Token.getComment());
     }
 
+    @Test
     public void testAccessAddress() {
         final String name = "John Doe";
         String address = "jdoe@example.net";
@@ -119,6 +130,7 @@
         assertNull(rfc822Token.getAddress());
     }
 
+    @Test
     public void testToString() {
         Rfc822Token rfc822Token1 = new Rfc822Token("John Doe", "jdoe@example.net", "work");
         assertEquals("John Doe (work) <jdoe@example.net>", rfc822Token1.toString());
@@ -141,32 +153,30 @@
         assertEquals("", rfc822Token6.toString());
     }
 
+    @Test
     public void testQuoteNameIfNecessary() {
         assertEquals("UPPERlower space 0123456789",
                 Rfc822Token.quoteNameIfNecessary("UPPERlower space 0123456789"));
         assertEquals("\"jdoe@example.net\"", Rfc822Token.quoteNameIfNecessary("jdoe@example.net"));
         assertEquals("\"*name\"", Rfc822Token.quoteNameIfNecessary("*name"));
 
-        try {
-            Rfc822Token.quoteNameIfNecessary(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed to happen if name is null.
-        }
-
         assertEquals("", Rfc822Token.quoteNameIfNecessary(""));
     }
 
+    @Test(expected=NullPointerException.class)
+    public void testQuoteNameIfNecessaryNull() {
+        Rfc822Token.quoteNameIfNecessary(null);
+    }
+
+    @Test
     public void testQuoteName() {
         assertEquals("John Doe", Rfc822Token.quoteName("John Doe"));
         assertEquals("\\\"John Doe\\\"", Rfc822Token.quoteName("\"John Doe\""));
         assertEquals("\\\\\\\"John Doe\\\"", Rfc822Token.quoteName("\\\"John Doe\""));
+    }
 
-        try {
-            Rfc822Token.quoteName(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed to happen if name is null.
-        }
+    @Test(expected=NullPointerException.class)
+    public void testQuoteNameNull() {
+        Rfc822Token.quoteName(null);
     }
 }
diff --git a/tests/tests/text/src/android/text/util/cts/Rfc822TokenizerTest.java b/tests/tests/text/src/android/text/util/cts/Rfc822TokenizerTest.java
index 2c118d0..c8b81f4 100644
--- a/tests/tests/text/src/android/text/util/cts/Rfc822TokenizerTest.java
+++ b/tests/tests/text/src/android/text/util/cts/Rfc822TokenizerTest.java
@@ -16,26 +16,32 @@
 
 package android.text.util.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.util.Rfc822Token;
 import android.text.util.Rfc822Tokenizer;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Test {@link Rfc822Tokenizer}.
  */
-public class Rfc822TokenizerTest extends AndroidTestCase {
-
-    @SmallTest
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class Rfc822TokenizerTest {
+    @Test
     public void testConstructor() {
         new Rfc822Tokenizer();
     }
 
-    @SmallTest
+    @Test
     public void testFindTokenStart() {
         Rfc822Tokenizer rfc822Tokenizer = new Rfc822Tokenizer();
 
@@ -68,7 +74,7 @@
         }
     }
 
-    @SmallTest
+    @Test
     public void testFindTokenEnd() {
         Rfc822Tokenizer rfc822Tokenizer = new Rfc822Tokenizer();
 
@@ -95,16 +101,16 @@
         final int TOKEN_END_POS_4 = text2.indexOf(token4) + token4.length();
         assertEquals(TOKEN_END_POS_2, rfc822Tokenizer.findTokenEnd(text2, 0));
         assertEquals(TOKEN_END_POS_4, rfc822Tokenizer.findTokenEnd(text2, TOKEN_END_POS_2 + 1));
-
-        try {
-            rfc822Tokenizer.findTokenEnd(null, 0);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed to happen if text is null.
-        }
     }
 
-    @SmallTest
+    @Test(expected=NullPointerException.class)
+    public void testFindTokenEndNull() {
+        Rfc822Tokenizer rfc822Tokenizer = new Rfc822Tokenizer();
+
+        rfc822Tokenizer.findTokenEnd(null, 0);
+    }
+
+    @Test
     public void testTerminateToken() {
         Rfc822Tokenizer rfc822Tokenizer = new Rfc822Tokenizer();
 
@@ -119,7 +125,7 @@
         assertEquals(text + comma + space, rfc822Tokenizer.terminateToken(null));
     }
 
-    @SmallTest
+    @Test
     public void testTokenize() {
         Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("");
         assertEquals(0, tokens.length);
@@ -127,24 +133,22 @@
         String text = "\"Berg\" (home) <berg\\@example.com>, tom\\@example.com (work)";
         tokens = Rfc822Tokenizer.tokenize(text);
         assertEquals(2, tokens.length);
-        localAssertEquals(tokens[0], "Berg", "berg\\@example.com", "home");
-        localAssertEquals(tokens[1], null, "tom\\@example.com", "work");
+        verifyLocalAssertEquals(tokens[0], "Berg", "berg\\@example.com", "home");
+        verifyLocalAssertEquals(tokens[1], null, "tom\\@example.com", "work");
 
         text = "Foo Bar (something) <foo\\@example.com>, blah\\@example.com (something)";
         tokens = Rfc822Tokenizer.tokenize(text);
         assertEquals(2, tokens.length);
-        localAssertEquals(tokens[0], "Foo Bar", "foo\\@example.com", "something");
-        localAssertEquals(tokens[1], null, "blah\\@example.com", "something");
-
-        try {
-            Rfc822Tokenizer.tokenize(null);
-            fail("Should throw NullPointerException!");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed result if text is null
-        }
+        verifyLocalAssertEquals(tokens[0], "Foo Bar", "foo\\@example.com", "something");
+        verifyLocalAssertEquals(tokens[1], null, "blah\\@example.com", "something");
     }
 
-    @SmallTest
+    @Test(expected=NullPointerException.class)
+    public void testTokenizeNull() {
+        Rfc822Tokenizer.tokenize(null);
+    }
+
+    @Test
     public void testTokenize_withListParam() {
         final List<Rfc822Token> list = new ArrayList<>();
         Rfc822Tokenizer.tokenize("", list);
@@ -153,21 +157,21 @@
         String text = "\"Berg\" (home) <berg\\@example.com>, tom\\@example.com (work)";
         Rfc822Tokenizer.tokenize(text, list);
         assertEquals(2, list.size());
-        localAssertEquals(list.get(0), "Berg", "berg\\@example.com", "home");
-        localAssertEquals(list.get(1), null, "tom\\@example.com", "work");
+        verifyLocalAssertEquals(list.get(0), "Berg", "berg\\@example.com", "home");
+        verifyLocalAssertEquals(list.get(1), null, "tom\\@example.com", "work");
 
         text = "Foo Bar (something) <foo\\@example.com>, blah\\@example.com (something)";
         list.clear();
         Rfc822Tokenizer.tokenize(text, list);
         assertEquals(2, list.size());
-        localAssertEquals(list.get(0), "Foo Bar", "foo\\@example.com", "something");
-        localAssertEquals(list.get(1), null, "blah\\@example.com", "something");
+        verifyLocalAssertEquals(list.get(0), "Foo Bar", "foo\\@example.com", "something");
+        verifyLocalAssertEquals(list.get(1), null, "blah\\@example.com", "something");
+    }
 
-        try {
-            Rfc822Tokenizer.tokenize(null);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-        }
+
+    @Test(expected=NullPointerException.class)
+    public void testTokenize_withListParamNull() {
+        Rfc822Tokenizer.tokenize(null);
     }
 
     /**
@@ -177,7 +181,7 @@
      * @param address expected address.
      * @param comment expected comment.
      */
-    private void localAssertEquals(Rfc822Token token, String name,
+    private void verifyLocalAssertEquals(Rfc822Token token, String name,
             String address, String comment) {
         assertEquals(name, token.getName());
         assertEquals(address, token.getAddress());
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
index 62a97e3..0073c1a 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
@@ -20,6 +20,8 @@
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.graphics.Point;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.VirtualDisplay;
 import android.media.MediaPlayer;
@@ -65,6 +67,12 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        mOnWatch = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+        if (mOnWatch) {
+            // Don't try and set up test/capture infrastructure - they're not supported
+            return;
+        }
+
         getWindow().getDecorView().setSystemUiVisibility(
                 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
 
@@ -75,8 +83,6 @@
 
         mMediaPlayer = MediaPlayer.create(this, R.raw.colors_video);
         mMediaPlayer.setLooping(true);
-
-        mOnWatch = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
     }
 
     /**
@@ -98,6 +104,8 @@
 
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (mOnWatch) return;
+
         if (requestCode != PERMISSION_CODE) {
             throw new IllegalStateException("Unknown request code: " + requestCode);
         }
@@ -144,6 +152,7 @@
             display.getRealSize(size);
             display.getMetrics(metrics);
 
+
             mSurfacePixelValidator = new SurfacePixelValidator(CapturedActivity.this,
                     size, animationTestCase.getChecker());
             Log.d("MediaProjection", "Size is " + size.toString());
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 36849a7..b80d283 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -204,7 +204,6 @@
         mInstrumentation.waitForIdleSync();
     }
 
-    @UiThreadTest
     @Test
     public void testConstructor() {
         new TextView(mActivity);