Migrate to Android Testing Support Lib (part 1/N)

This CL converts tests under com.android.inputmethod.latin.utils to
Android Testing Support Library.

Bug: 110805255
Test: verified as follows. No new test failures.
        tapas adb LatinIME LatinIMETests arm64 userdebug && \
        DISABLE_PROGUARD=true make -j LatinIME && \
        adb install -r $OUT/system/app/LatinIME/LatinIME.apk && \
        atest LatinIMETests:com.android.inputmethod.latin.utils
Change-Id: I5cc2ddbc4116003ab6407432ab521b6b560052ae
This commit is contained in:
Yohei Yukawa 2018-07-05 13:45:04 -07:00
parent 2802250415
commit 9c49581eeb
13 changed files with 206 additions and 65 deletions

View file

@ -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(

View file

@ -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<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 @@ public class AsyncResultHolderTests extends AndroidTestCase {
assertEquals(DEFAULT_VALUE, resultValue);
}
@Test
public void testGetAfterSet() {
final AsyncResultHolder<Integer> 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<Integer> holder = new AsyncResultHolder<>("Test");
setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS);

View file

@ -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);

View file

@ -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<String> 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<String>) null));
assertTrue(CollectionUtils.isNullOrEmpty((Map<String, String>) null));

View file

@ -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 @@ 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")));

View file

@ -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);

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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 @@ 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";

View file

@ -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);

View file

@ -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<RichInputMethodSubtype> 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<Void> tests = new RunInLocale<Void>() {
@Override
@ -264,6 +277,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
tests.runInLocale(mRes, Locale.ENGLISH);
}
@Test
public void testAdditionalSubtypesInEnglishSystemLocale() {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@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<Void> tests = new RunInLocale<Void>() {
@Override
@ -364,6 +379,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
tests.runInLocale(mRes, Locale.FRENCH);
}
@Test
public void testAdditionalSubtypesInFrenchSystemLocale() {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@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<Void> tests = new RunInLocale<Void>() {
@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<Void> tests = new RunInLocale<Void>() {
@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