diff --git a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java index 1db839506..ba3951ffa 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. 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 @@ public class AdditionalSubtypeUtilsTests extends AndroidTestCase { ",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 @@ public class AdditionalSubtypeUtilsTests extends AndroidTestCase { 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 c214b5fd0..f30f6661b 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 @@ public class AsyncResultHolderTests extends AndroidTestCase { }).start(); } + @Test public void testGetWithoutSet() { final AsyncResultHolder holder = new AsyncResultHolder<>("Test"); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(DEFAULT_VALUE, resultValue); } + @Test public void testGetBeforeSet() { final AsyncResultHolder holder = new AsyncResultHolder<>("Test"); setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS); @@ -57,6 +65,7 @@ public class AsyncResultHolderTests extends AndroidTestCase { assertEquals(DEFAULT_VALUE, resultValue); } + @Test public void testGetAfterSet() { final AsyncResultHolder holder = new AsyncResultHolder<>("Test"); holder.set(SET_VALUE); @@ -64,6 +73,7 @@ public class AsyncResultHolderTests extends AndroidTestCase { assertEquals(SET_VALUE, resultValue); } + @Test public void testGetBeforeTimeout() { final AsyncResultHolder 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 9680d85b3..3a452e4ba 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 @@ public class CapsModeUtilsTests extends AndroidTestCase { 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 @@ public class CapsModeUtilsTests extends AndroidTestCase { 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 0cbb02c4f..96dfa36c2 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.HashMap; 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 @@ public class CollectionUtilsTests extends AndroidTestCase { * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} gives the expected * results for a few valid inputs. */ + @Test public void testArrayAsList() { final ArrayList empty = new ArrayList<>(); assertEquals(empty, CollectionUtils.arrayAsList(new String[] {}, 0, 0)); @@ -81,6 +92,7 @@ public class CollectionUtilsTests extends AndroidTestCase { * Tests that {@link CollectionUtils#isNullOrEmpty(java.util.Collection)} gives the expected * results for a few cases. */ + @Test public void testIsNullOrEmpty() { assertTrue(CollectionUtils.isNullOrEmpty((List) null)); assertTrue(CollectionUtils.isNullOrEmpty((Map) null)); diff --git a/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java index 812353cc4..e24707aa6 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 job = new RunInLocale() { @Override @@ -34,7 +44,7 @@ public class DictionaryInfoUtilsTests extends AndroidTestCase { 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 @@ public class DictionaryInfoUtilsTests extends AndroidTestCase { 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 86923059b..6118ad812 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 df0180729..8c004bf8a 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 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { } } - @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 194112070..e0a2b8116 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 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 e4b6a668c..972b78345 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 @@ package com.android.inputmethod.latin.utils; 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 java.util.Locale; 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { } + @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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 @@ public class LanguageOnSpacebarUtilsTests extends AndroidTestCase { 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 9b826839f..8224272a6 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 @@ public class RecapitalizeStatusTests extends AndroidTestCase { 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 8e764e40f..ac05d3c31 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 anyKeyValue = new HashMap<>(); anyKeyValue.put("anyKey", "anyValue"); @@ -69,6 +78,7 @@ public class ResourceUtilsTests extends AndroidTestCase { assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, array)); } + @Test public void testFindConstantForKeyValuePairsCombined() { final String HARDWARE_KEY = "HARDWARE"; final String MODEL_KEY = "MODEL"; @@ -113,6 +123,7 @@ public class ResourceUtilsTests extends AndroidTestCase { 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 665d81ccd..9a6b8629c 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.SpannableStringBuilder; 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 @@ public class SpannableStringUtilsTests extends AndroidTestCase { assertTrue(false); } + @Test public void testSplitCharSequenceWithSpan() { // text: " a bcd efg hij " // span1: ^^^^^^^ @@ -182,6 +198,7 @@ public class SpannableStringUtilsTests extends AndroidTestCase { 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 2297cacf8..8e47f3ae4 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 com.android.inputmethod.latin.RichInputMethodSubtype; 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 mSubtypesList = new ArrayList<>(); @@ -64,10 +76,9 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { 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 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { } } - @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 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { } } + @Test public void testKeyboardLayoutSetName() { assertEquals("en_US", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US)); assertEquals("en_GB", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_GB)); @@ -223,6 +235,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // sr_ZZ qwerty T Serbian (QWERTY) exception // zz pc T Alphabet (PC) + @Test public void testPredefinedSubtypesInEnglishSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -264,6 +277,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { tests.runInLocale(mRes, Locale.ENGLISH); } + @Test public void testAdditionalSubtypesInEnglishSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -323,6 +337,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // sr_ZZ qwerty T Serbe (QWERTY) exception // zz pc T Alphabet latin (PC) + @Test public void testPredefinedSubtypesInFrenchSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -364,6 +379,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { tests.runInLocale(mRes, Locale.FRENCH); } + @Test public void testAdditionalSubtypesInFrenchSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -405,6 +421,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // hi_ZZ qwerty F हिंग्लिश // hi_ZZ dvorak T हिंग्लिश (Dvorak) + @Test public void testHinglishSubtypesInHindiSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -432,6 +449,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // sr_ZZ serbian_qwertz F Српски (латиница) // sr_ZZ qwerty T Српски (QWERTY) + @Test public void testSerbianLatinSubtypesInSerbianSystemLocale() { final RunInLocale tests = new RunInLocale() { @Override @@ -451,6 +469,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { tests.runInLocale(mRes, new Locale("sr")); } + @Test public void testIsRtlLanguage() { // Known Right-to-Left language subtypes. final InputMethodSubtype ARABIC = mRichImm