Migrate IME related tests to JUnit4

This CL cleans up remaining use of InstrumentationTestCase from
IME-related FrameworksCoreTests as it is already deprecated in favor of
testing-support-library.

There should be no behavior change in tests and their expectations.

Fixes: 70514197
Test: atest FrameworksCoreTests:com.android.internal.inputmethod.InputMethodSubtypeSwitchingControllerTest
Test: atest FrameworksCoreTests:com.android.internal.inputmethod.InputMethodUtilsTest
Test: atest FrameworksCoreTests:com.android.internal.inputmethod.LocaleUtilsTest
Test: atest FrameworksCoreTests:android.view.inputmethod.CursorAnchorInfoTest
Test: atest FrameworksCoreTests:android.view.inputmethod.InputMethodSubtypeArrayTest
Test: atest FrameworksCoreTests:android.view.inputmethod.InputMethodSubtypeTest
Test: atest FrameworksCoreTests:android.view.inputmethod.SparseRectFArrayTest
Change-Id: I28f073aacb6f77c62bd186c37cbdb5719475d4ba
This commit is contained in:
Yohei Yukawa
2017-12-11 15:09:28 -08:00
parent 1f397705eb
commit 8306fc4202
7 changed files with 177 additions and 115 deletions

View File

@@ -16,21 +16,33 @@
package android.view.inputmethod;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
import android.view.inputmethod.CursorAnchorInfo.Builder;
import java.util.Objects;
import static android.view.inputmethod.CursorAnchorInfo.FLAG_HAS_INVISIBLE_REGION;
import static android.view.inputmethod.CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION;
import static android.view.inputmethod.CursorAnchorInfo.FLAG_IS_RTL;
public class CursorAnchorInfoTest extends InstrumentationTestCase {
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.graphics.Matrix;
import android.graphics.RectF;
import android.os.Parcel;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.view.inputmethod.CursorAnchorInfo.Builder;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Objects;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class CursorAnchorInfoTest {
private static final float EPSILON = 0.0000001f;
private static final RectF[] MANY_BOUNDS = new RectF[] {
new RectF(101.0f, 201.0f, 301.0f, 401.0f),
new RectF(102.0f, 202.0f, 302.0f, 402.0f),
@@ -74,7 +86,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
FLAG_HAS_INVISIBLE_REGION | FLAG_IS_RTL,
};
@SmallTest
@Test
public void testBuilder() throws Exception {
final int SELECTION_START = 30;
final int SELECTION_END = 40;
@@ -109,10 +121,10 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(COMPOSING_TEXT_START, info.getComposingTextStart());
assertTrue(TextUtils.equals(COMPOSING_TEXT, info.getComposingText()));
assertEquals(INSERTION_MARKER_FLAGS, info.getInsertionMarkerFlags());
assertEquals(INSERTION_MARKER_HORIZONTAL, info.getInsertionMarkerHorizontal());
assertEquals(INSERTION_MARKER_TOP, info.getInsertionMarkerTop());
assertEquals(INSERTION_MARKER_BASELINE, info.getInsertionMarkerBaseline());
assertEquals(INSERTION_MARKER_BOTOM, info.getInsertionMarkerBottom());
assertEquals(INSERTION_MARKER_HORIZONTAL, info.getInsertionMarkerHorizontal(), EPSILON);
assertEquals(INSERTION_MARKER_TOP, info.getInsertionMarkerTop(), EPSILON);
assertEquals(INSERTION_MARKER_BASELINE, info.getInsertionMarkerBaseline(), EPSILON);
assertEquals(INSERTION_MARKER_BOTOM, info.getInsertionMarkerBottom(), EPSILON);
assertEquals(TRANSFORM_MATRIX, info.getMatrix());
for (int i = 0; i < MANY_BOUNDS.length; i++) {
final RectF expectedBounds = MANY_BOUNDS[i];
@@ -134,10 +146,10 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(COMPOSING_TEXT_START, info2.getComposingTextStart());
assertTrue(TextUtils.equals(COMPOSING_TEXT, info2.getComposingText()));
assertEquals(INSERTION_MARKER_FLAGS, info2.getInsertionMarkerFlags());
assertEquals(INSERTION_MARKER_HORIZONTAL, info2.getInsertionMarkerHorizontal());
assertEquals(INSERTION_MARKER_TOP, info2.getInsertionMarkerTop());
assertEquals(INSERTION_MARKER_BASELINE, info2.getInsertionMarkerBaseline());
assertEquals(INSERTION_MARKER_BOTOM, info2.getInsertionMarkerBottom());
assertEquals(INSERTION_MARKER_HORIZONTAL, info2.getInsertionMarkerHorizontal(), EPSILON);
assertEquals(INSERTION_MARKER_TOP, info2.getInsertionMarkerTop(), EPSILON);
assertEquals(INSERTION_MARKER_BASELINE, info2.getInsertionMarkerBaseline(), EPSILON);
assertEquals(INSERTION_MARKER_BOTOM, info2.getInsertionMarkerBottom(), EPSILON);
assertEquals(TRANSFORM_MATRIX, info2.getMatrix());
for (int i = 0; i < MANY_BOUNDS.length; i++) {
final RectF expectedBounds = MANY_BOUNDS[i];
@@ -161,10 +173,10 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(COMPOSING_TEXT_START, info3.getComposingTextStart());
assertTrue(TextUtils.equals(COMPOSING_TEXT, info3.getComposingText()));
assertEquals(INSERTION_MARKER_FLAGS, info3.getInsertionMarkerFlags());
assertEquals(INSERTION_MARKER_HORIZONTAL, info3.getInsertionMarkerHorizontal());
assertEquals(INSERTION_MARKER_TOP, info3.getInsertionMarkerTop());
assertEquals(INSERTION_MARKER_BASELINE, info3.getInsertionMarkerBaseline());
assertEquals(INSERTION_MARKER_BOTOM, info3.getInsertionMarkerBottom());
assertEquals(INSERTION_MARKER_HORIZONTAL, info3.getInsertionMarkerHorizontal(), EPSILON);
assertEquals(INSERTION_MARKER_TOP, info3.getInsertionMarkerTop(), EPSILON);
assertEquals(INSERTION_MARKER_BASELINE, info3.getInsertionMarkerBaseline(), EPSILON);
assertEquals(INSERTION_MARKER_BOTOM, info3.getInsertionMarkerBottom(), EPSILON);
assertEquals(TRANSFORM_MATRIX, info3.getMatrix());
for (int i = 0; i < MANY_BOUNDS.length; i++) {
final RectF expectedBounds = MANY_BOUNDS[i];
@@ -187,10 +199,10 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(-1, uninitializedInfo.getComposingTextStart());
assertNull(uninitializedInfo.getComposingText());
assertEquals(0, uninitializedInfo.getInsertionMarkerFlags());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerHorizontal());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerTop());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBaseline());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBottom());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerHorizontal(), EPSILON);
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerTop(), EPSILON);
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBaseline(), EPSILON);
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBottom(), EPSILON);
assertEquals(Matrix.IDENTITY_MATRIX, uninitializedInfo.getMatrix());
}
@@ -199,7 +211,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertFalse(Objects.equals(reference, actual));
}
@SmallTest
@Test
public void testEquality() throws Exception {
final Matrix MATRIX1 = new Matrix();
MATRIX1.setTranslate(10.0f, 20.0f);
@@ -357,7 +369,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
INSERTION_MARKER_FLAGS2).build());
}
@SmallTest
@Test
public void testMatrixIsCopied() throws Exception {
final Matrix MATRIX1 = new Matrix();
MATRIX1.setTranslate(10.0f, 20.0f);
@@ -385,7 +397,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(MATRIX2, secondInstance.getMatrix());
}
@SmallTest
@Test
public void testMatrixIsRequired() throws Exception {
final int SELECTION_START = 30;
final int SELECTION_END = 40;
@@ -434,7 +446,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testBuilderAddCharacterBounds() throws Exception {
// A negative index should be rejected.
try {

View File

@@ -16,16 +16,24 @@
package android.view.inputmethod;
import static org.junit.Assert.assertEquals;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
public class InputMethodSubtypeArrayTest extends InstrumentationTestCase {
@SmallTest
public void testInstanciate() throws Exception {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodSubtypeArrayTest {
@Test
public void testInstantiate() throws Exception {
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
subtypes.add(createDummySubtype(0, "en_US"));
subtypes.add(createDummySubtype(1, "en_US"));

View File

@@ -16,15 +16,26 @@
package android.view.inputmethod;
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.assertTrue;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Locale;
import java.util.Objects;
public class InputMethodSubtypeTest extends InstrumentationTestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodSubtypeTest {
public void verifyLocale(final String localeString) {
// InputMethodSubtype#getLocale() returns exactly the same string that is passed to the
@@ -48,7 +59,7 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
cloneViaParcel(cloneViaParcel(createDummySubtype(localeString))).hashCode());
}
@SmallTest
@Test
public void testLocaleObj_locale() {
final InputMethodSubtype usSubtype = createDummySubtype("en_US");
Locale localeObject = usSubtype.getLocaleObject();
@@ -59,7 +70,7 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
assertTrue(localeObject == usSubtype.getLocaleObject());
}
@SmallTest
@Test
public void testLocaleObj_languageTag() {
final InputMethodSubtype usSubtype = createDummySubtypeUsingLanguageTag("en-US");
Locale localeObject = usSubtype.getLocaleObject();
@@ -71,7 +82,7 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
assertTrue(localeObject == usSubtype.getLocaleObject());
}
@SmallTest
@Test
public void testLocaleObj_emptyLocale() {
final InputMethodSubtype emptyLocaleSubtype = createDummySubtype("");
assertNull(emptyLocaleSubtype.getLocaleObject());
@@ -80,7 +91,7 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
assertNull(emptyLocaleSubtype.getLocaleObject());
}
@SmallTest
@Test
public void testLocaleString() throws Exception {
// The locale string in InputMethodSubtype has accepted an arbitrary text actually,
// regardless of the validity of the text as a locale string.
@@ -95,7 +106,7 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
verifyLocale("fil_PH");
}
@SmallTest
@Test
public void testDeprecatedLocaleString() throws Exception {
// Make sure "iw" is not automatically replaced with "he".
final InputMethodSubtype subtypeIw = createDummySubtype("iw");

View File

@@ -16,15 +16,25 @@
package android.view.inputmethod;
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.graphics.RectF;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Objects;
public class SparseRectFArrayTest extends InstrumentationTestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class SparseRectFArrayTest {
// A test data for {@link SparseRectFArray}. null represents the gap of indices.
private static final RectF[] MANY_RECTS = new RectF[] {
null,
@@ -49,7 +59,7 @@ public class SparseRectFArrayTest extends InstrumentationTestCase {
new RectF(118.0f, 218.0f, 318.0f, 418.0f),
};
@SmallTest
@Test
public void testBuilder() throws Exception {
final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
final int TEMP_FLAGS = 0x1234;
@@ -128,7 +138,7 @@ public class SparseRectFArrayTest extends InstrumentationTestCase {
assertNull(builder.build().get(0));
}
@SmallTest
@Test
public void testEquality() throws Exception {
// Empty array should be equal.
assertEqualRects(new SparseRectFArrayBuilder().build(),
@@ -225,7 +235,7 @@ public class SparseRectFArrayTest extends InstrumentationTestCase {
.build());
}
@SmallTest
@Test
public void testBuilderAppend() throws Exception {
// Key should be appended in ascending order.
try {

View File

@@ -16,11 +16,15 @@
package com.android.internal.inputmethod;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
@@ -28,11 +32,16 @@ import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodSubtypeSwitchingControllerTest {
private static final String DUMMY_PACKAGE_NAME = "dummy package name";
private static final String DUMMY_IME_LABEL = "dummy ime label";
private static final String DUMMY_SETTING_ACTIVITY_NAME = "";
@@ -190,7 +199,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
controller.onUserActionLocked(subtypeListItem.mImi, subtype);
}
@SmallTest
@Test
public void testControllerImpl() throws Exception {
final List<ImeSubtypeListItem> disabledItems = createDisabledImeSubtypes();
final ImeSubtypeListItem disabledIme_en_US = disabledItems.get(0);
@@ -250,7 +259,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
disabledSubtypeUnawareIme, null, null);
}
@SmallTest
@Test
public void testControllerImplWithUserAction() throws Exception {
final List<ImeSubtypeListItem> enabledItems = createEnabledImeSubtypes();
final ImeSubtypeListItem latinIme_en_US = enabledItems.get(0);
@@ -331,7 +340,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
switchingUnawarelatinIme_en_UK, switchUnawareJapaneseIme_ja_JP);
}
@SmallTest
@Test
public void testImeSubtypeListItem() throws Exception {
final List<ImeSubtypeListItem> items = new ArrayList<>();
addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme",
@@ -360,7 +369,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
assertFalse(item_EN_US.mIsSystemLocale);
}
@SmallTest
@Test
public void testImeSubtypeListComparator() throws Exception {
{
final List<ImeSubtypeListItem> items = Arrays.asList(

View File

@@ -16,6 +16,15 @@
package com.android.internal.inputmethod;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.Is.is;
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.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
@@ -24,30 +33,31 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.LocaleList;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
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.util.ArrayMap;
import android.util.ArraySet;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.not;
public class InputMethodUtilsTest extends InstrumentationTestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodUtilsTest {
private static final boolean IS_AUX = true;
private static final boolean IS_DEFAULT = true;
private static final boolean IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE = true;
private static final boolean IS_ASCII_CAPABLE = true;
private static final boolean IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE = true;
private static final boolean IS_SYSTEM_READY = true;
private static final Locale LOCALE_EN = new Locale("en");
private static final Locale LOCALE_EN_US = new Locale("en", "US");
private static final Locale LOCALE_EN_GB = new Locale("en", "GB");
@@ -77,7 +87,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
private static final String EXTRA_VALUE_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE =
"EnabledWhenDefaultIsNotAsciiCapable";
@SmallTest
@Test
public void testVoiceImes() throws Exception {
// locale: en_US
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
@@ -101,7 +111,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
"DummyNonDefaultAutoVoiceIme1");
}
@SmallTest
@Test
public void testKeyboardImes() throws Exception {
// locale: en_US
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
@@ -136,7 +146,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
}
@SmallTest
@Test
public void testParcelable() throws Exception {
final ArrayList<InputMethodInfo> originalList = getSamplePreinstalledImes("en-rUS");
final List<InputMethodInfo> clonedList = cloneViaParcel(originalList);
@@ -153,7 +163,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testGetImplicitlyApplicableSubtypesLocked() throws Exception {
final InputMethodSubtype nonAutoEnUS = createDummyInputMethodSubtype("en_US",
SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE,
@@ -434,8 +444,8 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
InputMethodUtils.getImplicitlyApplicableSubtypesLocked(
getResourcesForLocales(Locale.forLanguageTag("sr-Latn-RS")), imi);
assertEquals(2, result.size());
assertThat(nonAutoSrLatn, isIn(result));
assertThat(nonAutoHandwritingSrLatn, isIn(result));
assertThat(nonAutoSrLatn, is(in(result)));
assertThat(nonAutoHandwritingSrLatn, is(in(result)));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
@@ -454,8 +464,8 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
InputMethodUtils.getImplicitlyApplicableSubtypesLocked(
getResourcesForLocales(Locale.forLanguageTag("sr-Cyrl-RS")), imi);
assertEquals(2, result.size());
assertThat(nonAutoSrCyrl, isIn(result));
assertThat(nonAutoHandwritingSrCyrl, isIn(result));
assertThat(nonAutoSrCyrl, is(in(result)));
assertThat(nonAutoHandwritingSrCyrl, is(in(result)));
}
// Make sure that secondary locales are taken into account to find the best matching
@@ -486,12 +496,12 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
Locale.forLanguageTag("en-US")),
imi);
assertEquals(6, result.size());
assertThat(nonAutoEnGB, isIn(result));
assertThat(nonAutoFr, isIn(result));
assertThat(nonAutoSrLatn, isIn(result));
assertThat(nonAutoHandwritingEn, isIn(result));
assertThat(nonAutoHandwritingFr, isIn(result));
assertThat(nonAutoHandwritingSrLatn, isIn(result));
assertThat(nonAutoEnGB, is(in(result)));
assertThat(nonAutoFr, is(in(result)));
assertThat(nonAutoSrLatn, is(in(result)));
assertThat(nonAutoHandwritingEn, is(in(result)));
assertThat(nonAutoHandwritingFr, is(in(result)));
assertThat(nonAutoHandwritingSrLatn, is(in(result)));
}
// Make sure that 3-letter language code can be handled.
@@ -604,16 +614,16 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
final ArrayList<InputMethodSubtype> result =
InputMethodUtils.getImplicitlyApplicableSubtypesLocked(
getResourcesForLocales(LOCALE_FR, LOCALE_EN_US, LOCALE_JA_JP), imi);
assertThat(nonAutoFrCA, isIn(result));
assertThat(nonAutoEnUS, isIn(result));
assertThat(nonAutoJa, isIn(result));
assertThat(nonAutoIn, not(isIn(result)));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
assertThat(nonAutoFrCA, is(in(result)));
assertThat(nonAutoEnUS, is(in(result)));
assertThat(nonAutoJa, is(in(result)));
assertThat(nonAutoIn, not(is(in(result))));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(is(in(result))));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(is(in(result))));
}
}
@SmallTest
@Test
public void testContainsSubtypeOf() throws Exception {
final InputMethodSubtype nonAutoEnUS = createDummyInputMethodSubtype("en_US",
SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE,
@@ -788,7 +798,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
private Context createTargetContextWithLocales(final LocaleList locales) {
final Configuration resourceConfiguration = new Configuration();
resourceConfiguration.setLocales(locales);
return getInstrumentation()
return InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.createConfigurationContext(resourceConfiguration);
}
@@ -1043,7 +1053,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
return preinstalledImes;
}
@SmallTest
@Test
public void testGetSuitableLocalesForSpellChecker() throws Exception {
{
final ArrayList<Locale> locales =
@@ -1138,7 +1148,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testParseInputMethodsAndSubtypesString() {
// Trivial cases.
{
@@ -1264,7 +1274,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testbuildInputMethodsAndSubtypesString() {
{
ArrayMap<String, ArraySet<String>> map = new ArrayMap<>();
@@ -1272,7 +1282,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
{
ArrayMap<String, ArraySet<String>> map = new ArrayMap<>();
map.put("ime0", new ArraySet<String>());
map.put("ime0", new ArraySet<>());
assertEquals("ime0", InputMethodUtils.buildInputMethodsAndSubtypesString(map));
}
{
@@ -1300,8 +1310,8 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
{
ArrayMap<String, ArraySet<String>> map = new ArrayMap<>();
map.put("ime0", new ArraySet<String>());
map.put("ime1", new ArraySet<String>());
map.put("ime0", new ArraySet<>());
map.put("ime1", new ArraySet<>());
ArraySet<String> validSequences = new ArraySet<>();
validSequences.add("ime0:ime1");
@@ -1314,7 +1324,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
ArraySet<String> subtypes1 = new ArraySet<>();
subtypes1.add("subtype0");
map.put("ime0", subtypes1);
map.put("ime1", new ArraySet<String>());
map.put("ime1", new ArraySet<>());
ArraySet<String> validSequences = new ArraySet<>();
validSequences.add("ime0;subtype0:ime1");
@@ -1328,7 +1338,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
subtypes1.add("subtype0");
subtypes1.add("subtype1");
map.put("ime0", subtypes1);
map.put("ime1", new ArraySet<String>());
map.put("ime1", new ArraySet<>());
ArraySet<String> validSequences = new ArraySet<>();
validSequences.add("ime0;subtype0;subtype1:ime1");
@@ -1380,7 +1390,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testConstructLocaleFromString() throws Exception {
assertEquals(new Locale("en"), InputMethodUtils.constructLocaleFromString("en"));
assertEquals(new Locale("en", "US"), InputMethodUtils.constructLocaleFromString("en_US"));

View File

@@ -16,24 +16,25 @@
package com.android.internal.inputmethod;
import static org.junit.Assert.assertEquals;
import android.os.LocaleList;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Locale;
public class LocaleUtilsTest extends InstrumentationTestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class LocaleUtilsTest {
private static final LocaleUtils.LocaleExtractor<Locale> sIdentityMapper =
new LocaleUtils.LocaleExtractor<Locale>() {
@Override
public Locale get(Locale source) {
return source;
}
};
private static final LocaleUtils.LocaleExtractor<Locale> sIdentityMapper = source -> source;
@SmallTest
@Test
public void testFilterByLanguageEmptyLanguageList() throws Exception {
final ArrayList<Locale> availableLocales = new ArrayList<>();
availableLocales.add(Locale.forLanguageTag("en-US"));
@@ -49,7 +50,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
assertEquals(0, dest.size());
}
@SmallTest
@Test
public void testFilterDoesNotMatchAnything() throws Exception {
final ArrayList<Locale> availableLocales = new ArrayList<>();
availableLocales.add(Locale.forLanguageTag("en-US"));
@@ -65,7 +66,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
assertEquals(0, dest.size());
}
@SmallTest
@Test
public void testFilterByLanguageEmptySource() throws Exception {
final ArrayList<Locale> availableLocales = new ArrayList<>();
@@ -76,7 +77,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
assertEquals(0, dest.size());
}
@SmallTest
@Test
public void testFilterByLanguageNullAvailableLocales() throws Exception {
{
final LocaleList preferredLocales =
@@ -138,7 +139,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testFilterByLanguage() throws Exception {
{
final ArrayList<Locale> availableLocales = new ArrayList<>();
@@ -172,7 +173,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testFilterByLanguageTheSameLanguage() throws Exception {
{
final LocaleList preferredLocales =
@@ -223,7 +224,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
}
}
@SmallTest
@Test
public void testFilterByLanguageFallbackRules() throws Exception {
{
final LocaleList preferredLocales = LocaleList.forLanguageTags("sr-Latn-RS");
@@ -355,6 +356,7 @@ public class LocaleUtilsTest extends InstrumentationTestCase {
}
}
@Test
public void testFilterKnownLimitation() throws Exception {
// Following test cases are not for intentional behavior but checks for preventing the
// behavior from becoming worse.