Merge "Migrate to Android Testing Support Lib (part 2/N)"
diff --git a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
index 1db8395..ba3951f 100644
--- a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
@@ -22,19 +22,28 @@
 import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE;
 import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
 import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import android.content.Context;
 import android.os.Build;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
 
 import java.util.Locale;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class AdditionalSubtypeUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class AdditionalSubtypeUtilsTests {
 
     /**
      * Predictable subtype ID for en_US dvorak layout. This is actually a hash code calculated as
@@ -98,10 +107,9 @@
             ",EmojiCapable" +
             ",isAdditionalSubtype";
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        final Context context = getContext();
+    @Before
+    public void setUp() throws Exception {
+        final Context context = InstrumentationRegistry.getTargetContext();
         SubtypeLocaleUtils.init(context);
     }
 
@@ -149,6 +157,7 @@
         assertEquals(SUBTYPE_ID_ZZ_AZERTY, subtype.hashCode());
     }
 
+    @Test
     public void testRestorable() {
         final InputMethodSubtype EN_US_DVORAK =
                 AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
diff --git a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
index c214b5f..f30f666 100644
--- a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
@@ -16,12 +16,18 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.util.Log;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @MediumTest
-public class AsyncResultHolderTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class AsyncResultHolderTests {
     static final String TAG = AsyncResultHolderTests.class.getSimpleName();
 
     private static final int TIMEOUT_IN_MILLISECONDS = 500;
@@ -44,12 +50,14 @@
         }).start();
     }
 
+    @Test
     public void testGetWithoutSet() {
         final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
         final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
         assertEquals(DEFAULT_VALUE, resultValue);
     }
 
+    @Test
     public void testGetBeforeSet() {
         final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
         setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS);
@@ -57,6 +65,7 @@
         assertEquals(DEFAULT_VALUE, resultValue);
     }
 
+    @Test
     public void testGetAfterSet() {
         final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
         holder.set(SET_VALUE);
@@ -64,6 +73,7 @@
         assertEquals(SET_VALUE, resultValue);
     }
 
+    @Test
     public void testGetBeforeTimeout() {
         final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
         setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS);
diff --git a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
index 9680d85..3a452e4 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
@@ -16,18 +16,26 @@
 
 package com.android.inputmethod.latin.utils;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import android.content.res.Resources;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.TextUtils;
 
 import com.android.inputmethod.latin.common.LocaleUtils;
 import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import java.util.Locale;
 
 @SmallTest
-public class CapsModeUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class CapsModeUtilsTests {
     private static void onePathForCaps(final CharSequence cs, final int expectedResult,
             final int mask, final SpacingAndPunctuations sp, final boolean hasSpaceBefore) {
         final int oneTimeResult = expectedResult & mask;
@@ -49,6 +57,7 @@
         onePathForCaps(cs, expectedResult, s, sp, hasSpaceBefore);
     }
 
+    @Test
     public void testGetCapsMode() {
         final int c = TextUtils.CAP_MODE_CHARACTERS;
         final int w = TextUtils.CAP_MODE_WORDS;
@@ -59,7 +68,7 @@
                 return new SpacingAndPunctuations(res);
             }
         };
-        final Resources res = getContext().getResources();
+        final Resources res = InstrumentationRegistry.getTargetContext().getResources();
         SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
         allPathsForCaps("", c | w | s, sp, false);
         allPathsForCaps("Word", c, sp, false);
diff --git a/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
index 0cbb02c..96dfa36 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
@@ -16,11 +16,16 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+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 com.android.inputmethod.latin.common.CollectionUtils;
 
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -28,15 +33,20 @@
 import java.util.List;
 import java.util.Map;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Tests for {@link CollectionUtils}.
  */
 @SmallTest
-public class CollectionUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class CollectionUtilsTests {
     /**
      * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} fails as expected
      * with some invalid inputs.
      */
+    @Test
     public void testArrayAsListFailure() {
         final String[] array = { "0", "1" };
         // Negative start
@@ -66,6 +76,7 @@
      * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} gives the expected
      * results for a few valid inputs.
      */
+    @Test
     public void testArrayAsList() {
         final ArrayList<String> empty = new ArrayList<>();
         assertEquals(empty, CollectionUtils.arrayAsList(new String[] {}, 0, 0));
@@ -81,6 +92,7 @@
      * Tests that {@link CollectionUtils#isNullOrEmpty(java.util.Collection)} gives the expected
      * results for a few cases.
      */
+    @Test
     public void testIsNullOrEmpty() {
         assertTrue(CollectionUtils.isNullOrEmpty((List<String>) null));
         assertTrue(CollectionUtils.isNullOrEmpty((Map<String, String>) null));
diff --git a/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java
index 812353c..e24707a 100644
--- a/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java
@@ -16,17 +16,27 @@
 
 package com.android.inputmethod.latin.utils;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import android.content.res.Resources;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 
 import com.android.inputmethod.latin.common.LocaleUtils;
 import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
 
 import java.util.Locale;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class DictionaryInfoUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class DictionaryInfoUtilsTests {
+    @Test
     public void testLooksValidForDictionaryInsertion() {
         final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
             @Override
@@ -34,7 +44,7 @@
                 return new SpacingAndPunctuations(res);
             }
         };
-        final Resources res = getContext().getResources();
+        final Resources res = InstrumentationRegistry.getTargetContext().getResources();
         final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
         assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("aochaueo", sp));
         assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("", sp));
@@ -46,6 +56,7 @@
         assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp));
     }
 
+    @Test
     public void testGetMainDictId() {
         assertEquals("main:en",
                 DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en")));
diff --git a/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java
index 8692305..6118ad8 100644
--- a/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java
@@ -16,24 +16,31 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.util.Log;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 /**
  * Unit tests for {@link ExecutorUtils}.
  */
 @MediumTest
-public class ExecutorUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class ExecutorUtilsTests {
     private static final String TAG = ExecutorUtilsTests.class.getSimpleName();
 
     private static final int NUM_OF_TASKS = 10;
     private static final int DELAY_FOR_WAITING_TASKS_MILLISECONDS = 500;
 
+    @Test
     public void testExecute() {
         final ExecutorService executor =
                 ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD);
diff --git a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
index df01807..8c004bf 100644
--- a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
@@ -17,32 +17,39 @@
 package com.android.inputmethod.latin.utils;
 
 import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_CONTACTS_NOTICE;
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
 import android.content.SharedPreferences;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.text.TextUtils;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
 
 import com.android.inputmethod.latin.settings.SettingsValues;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import java.util.concurrent.TimeUnit;
-
 @MediumTest
-public class ImportantNoticeUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class ImportantNoticeUtilsTests {
 
     private ImportantNoticePreferences mImportantNoticePreferences;
 
     @Mock private SettingsValues mMockSettingsValues;
 
+    private Context getContext() {
+        return InstrumentationRegistry.getTargetContext();
+    }
+
     private static class ImportantNoticePreferences {
         private final SharedPreferences mPref;
 
-        private Integer mVersion;
         private Long mLastTime;
 
         public ImportantNoticePreferences(final Context context) {
@@ -96,21 +103,20 @@
         }
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         mImportantNoticePreferences = new ImportantNoticePreferences(getContext());
         mImportantNoticePreferences.save();
         when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
+    @After
+    public void tearDown() throws Exception {
         mImportantNoticePreferences.restore();
     }
 
+    @Test
     public void testPersonalizationSetting() {
         mImportantNoticePreferences.clear();
 
diff --git a/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java
index 1941120..e0a2b81 100644
--- a/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java
@@ -16,14 +16,23 @@
 
 package com.android.inputmethod.latin.utils;
 
+import static org.junit.Assert.assertEquals;
+
 import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 
 import java.util.Arrays;
 import java.util.List;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class JsonUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class JsonUtilsTests {
+    @Test
     public void testJsonUtils() {
         final Object[] objs = new Object[] { 1, "aaa", "bbb", 3 };
         final List<Object> objArray = Arrays.asList(objs);
diff --git a/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java
index e4b6a66..972b783 100644
--- a/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java
@@ -19,10 +19,12 @@
 import static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_FULL_LOCALE;
 import static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_LANGUAGE_ONLY;
 import static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_NONE;
+import static org.junit.Assert.assertEquals;
 
 import android.content.Context;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.latin.RichInputMethodManager;
@@ -36,8 +38,13 @@
 
 import javax.annotation.Nonnull;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class LanguageOnSpacebarUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class LanguageOnSpacebarUtilsTests {
     private RichInputMethodManager mRichImm;
 
     RichInputMethodSubtype EN_US_QWERTY;
@@ -50,10 +57,9 @@
     RichInputMethodSubtype IW_HEBREW;
     RichInputMethodSubtype ZZ_QWERTY;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        final Context context = getContext();
+    @Before
+    public void setUp() throws Exception {
+        final Context context = InstrumentationRegistry.getTargetContext();
         RichInputMethodManager.init(context);
         mRichImm = RichInputMethodManager.getInstance();
 
@@ -99,6 +105,7 @@
                 LanguageOnSpacebarUtils.getLanguageOnSpacebarFormatType(subtype));
     }
 
+    @Test
     public void testOneSubtypeImplicitlyEnabled() {
         enableSubtypes(EN_US_QWERTY);
         assertFormatType(EN_US_QWERTY, true, Locale.US,            FORMAT_TYPE_NONE);
@@ -113,6 +120,7 @@
         assertFormatType(FR_CA_QWERTY, true, Locale.CANADA_FRENCH, FORMAT_TYPE_NONE);
     }
 
+    @Test
     public void testOneSubtypeExplicitlyEnabled() {
         enableSubtypes(EN_US_QWERTY);
         assertFormatType(EN_US_QWERTY, false, Locale.UK,     FORMAT_TYPE_LANGUAGE_ONLY);
@@ -131,6 +139,7 @@
         assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE,        FORMAT_TYPE_LANGUAGE_ONLY);
     }
 
+    @Test
     public void testOneSubtypeImplicitlyEnabledWithNoLanguageSubtype() {
         final Locale Locale_IW = new Locale("iw");
         enableSubtypes(IW_HEBREW, ZZ_QWERTY);
@@ -140,6 +149,7 @@
         assertFormatType(ZZ_QWERTY,    true, Locale_IW, FORMAT_TYPE_FULL_LOCALE);
     }
 
+    @Test
     public void testTwoSubtypesExplicitlyEnabled() {
         enableSubtypes(EN_US_QWERTY, FR_AZERTY);
         assertFormatType(EN_US_QWERTY, false, Locale.US,     FORMAT_TYPE_LANGUAGE_ONLY);
@@ -157,6 +167,7 @@
 
     }
 
+    @Test
     public void testMultiSubtypeWithSameLanuageAndSameLayout() {
         // Explicitly enable en_US, en_GB, fr_FR, and no language keyboards.
         enableSubtypes(EN_US_QWERTY, EN_GB_QWERTY, FR_CA_QWERTY, ZZ_QWERTY);
@@ -172,6 +183,7 @@
         assertFormatType(ZZ_QWERTY,    false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
     }
 
+    @Test
     public void testMultiSubtypesWithSameLanguageButHaveDifferentLayout() {
         enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTZ);
 
@@ -191,6 +203,7 @@
         assertFormatType(FR_CH_QWERTZ, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
     }
 
+    @Test
     public void testMultiSubtypesWithSameLanguageAndMayHaveSameLayout() {
         enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTY, FR_CH_QWERTZ);
 
diff --git a/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java b/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
index 9b82683..8224272 100644
--- a/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
@@ -16,17 +16,24 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 
 import com.android.inputmethod.latin.common.Constants;
 
 import java.util.Locale;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class RecapitalizeStatusTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class RecapitalizeStatusTests {
     private static final int[] SPACE = { Constants.CODE_SPACE };
 
+    @Test
     public void testTrim() {
         final RecapitalizeStatus status = new RecapitalizeStatus();
         status.start(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
@@ -54,6 +61,7 @@
         assertEquals(43, status.getNewCursorEnd());
     }
 
+    @Test
     public void testRotate() {
         final RecapitalizeStatus status = new RecapitalizeStatus();
         status.start(29, 40, "abcd efghij", Locale.ENGLISH, SPACE);
diff --git a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
index 8e764e4..ac05d3c 100644
--- a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
@@ -16,13 +16,22 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 
 import java.util.HashMap;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class ResourceUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class ResourceUtilsTests {
+    @Test
     public void testFindConstantForKeyValuePairsSimple() {
         final HashMap<String,String> anyKeyValue = new HashMap<>();
         anyKeyValue.put("anyKey", "anyValue");
@@ -69,6 +78,7 @@
         assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, array));
     }
 
+    @Test
     public void testFindConstantForKeyValuePairsCombined() {
         final String HARDWARE_KEY = "HARDWARE";
         final String MODEL_KEY = "MODEL";
@@ -113,6 +123,7 @@
         assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray));
     }
 
+    @Test
     public void testFindConstantForKeyValuePairsRegexp() {
         final String HARDWARE_KEY = "HARDWARE";
         final String MODEL_KEY = "MODEL";
diff --git a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
index 665d81c..9a6b862 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
@@ -16,8 +16,13 @@
 
 package com.android.inputmethod.latin.utils;
 
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.text.style.SuggestionSpan;
 import android.text.style.URLSpan;
 import android.text.SpannableString;
@@ -25,8 +30,18 @@
 import android.text.Spanned;
 import android.text.SpannedString;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class SpannableStringUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class SpannableStringUtilsTests {
+
+    private Context getContext() {
+        return InstrumentationRegistry.getTargetContext();
+    }
+
+    @Test
     public void testConcatWithSuggestionSpansOnly() {
         SpannableStringBuilder s = new SpannableStringBuilder("test string\ntest string\n"
                 + "test string\ntest string\ntest string\ntest string\ntest string\ntest string\n"
@@ -87,6 +102,7 @@
         assertTrue(false);
     }
 
+    @Test
     public void testSplitCharSequenceWithSpan() {
         // text:  " a bcd efg hij  "
         // span1:  ^^^^^^^
@@ -182,6 +198,7 @@
         assertSpanCount(0, charSequencesFromSpanned[6]);
     }
 
+    @Test
     public void testSplitCharSequencePreserveTrailingEmptySegmengs() {
         assertEquals(1, SpannableStringUtils.split("", " ",
                 false /* preserveTrailingEmptySegmengs */).length);
diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
index 2297cac..8e47f3a 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
@@ -16,10 +16,16 @@
 
 package com.android.inputmethod.latin.utils;
 
+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.content.res.Resources;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodSubtype;
 
@@ -30,8 +36,14 @@
 import java.util.ArrayList;
 import java.util.Locale;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 @SmallTest
-public class SubtypeLocaleUtilsTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class SubtypeLocaleUtilsTests {
     // All input method subtypes of LatinIME.
     private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>();
 
@@ -64,10 +76,9 @@
     InputMethodSubtype HI_LATN_DVORAK; // Hinglis Dvorak
     InputMethodSubtype SR_LATN_QWERTY; // Serbian Latin Qwerty
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        final Context context = getContext();
+    @Before
+    public void setUp() throws Exception {
+        final Context context = InstrumentationRegistry.getTargetContext();
         mRes = context.getResources();
         RichInputMethodManager.init(context);
         mRichImm = RichInputMethodManager.getInstance();
@@ -136,13 +147,13 @@
         }
     }
 
-    @Override
-    protected void tearDown() throws Exception {
+    @After
+    public void tearDown() throws Exception {
         // Restore additional subtypes.
         mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
-        super.tearDown();
     }
 
+    @Test
     public void testAllFullDisplayName() {
         for (final RichInputMethodSubtype subtype : mSubtypesList) {
             final String subtypeName = SubtypeLocaleUtils
@@ -159,6 +170,7 @@
         }
     }
 
+    @Test
     public void testKeyboardLayoutSetName() {
         assertEquals("en_US", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US));
         assertEquals("en_GB", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_GB));
@@ -223,6 +235,7 @@
     //  sr_ZZ qwerty         T  Serbian (QWERTY)        exception
     //  zz    pc             T  Alphabet (PC)
 
+    @Test
     public void testPredefinedSubtypesInEnglishSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -264,6 +277,7 @@
         tests.runInLocale(mRes, Locale.ENGLISH);
     }
 
+    @Test
     public void testAdditionalSubtypesInEnglishSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -323,6 +337,7 @@
     //  sr_ZZ qwerty         T  Serbe (QWERTY)                   exception
     //  zz    pc             T  Alphabet latin (PC)
 
+    @Test
     public void testPredefinedSubtypesInFrenchSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -364,6 +379,7 @@
         tests.runInLocale(mRes, Locale.FRENCH);
     }
 
+    @Test
     public void testAdditionalSubtypesInFrenchSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -405,6 +421,7 @@
     //  hi_ZZ qwerty  F  हिंग्लिश
     //  hi_ZZ dvorak  T  हिंग्लिश (Dvorak)
 
+    @Test
     public void testHinglishSubtypesInHindiSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -432,6 +449,7 @@
     //  sr_ZZ serbian_qwertz F  Српски (латиница)
     //  sr_ZZ qwerty         T  Српски (QWERTY)
 
+    @Test
     public void testSerbianLatinSubtypesInSerbianSystemLocale() {
         final RunInLocale<Void> tests = new RunInLocale<Void>() {
             @Override
@@ -451,6 +469,7 @@
         tests.runInLocale(mRes, new Locale("sr"));
     }
 
+    @Test
     public void testIsRtlLanguage() {
         // Known Right-to-Left language subtypes.
         final InputMethodSubtype ARABIC = mRichImm