Merge "Migrate to Android Testing Support Lib (part 2/N)"

main
TreeHugger Robot 2018-07-06 03:02:05 +00:00 committed by Android (Google) Code Review
commit 231a28a3f7
3 changed files with 46 additions and 9 deletions

View File

@ -16,18 +16,29 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Build; import android.os.Build;
import android.test.AndroidTestCase; import android.support.test.filters.SmallTest;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.runner.AndroidJUnit4;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import java.util.Locale; import java.util.Locale;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class LocaleSpanCompatUtilsTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class LocaleSpanCompatUtilsTests {
@Test
public void testInstantiatable() { public void testInstantiatable() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
// LocaleSpan isn't yet available. // LocaleSpan isn't yet available.
@ -61,6 +72,7 @@ public class LocaleSpanCompatUtilsTests extends AndroidTestCase {
assertEquals(expectedCount, spans.length); assertEquals(expectedCount, spans.length);
} }
@Test
public void testUpdateLocaleSpan() { public void testUpdateLocaleSpan() {
if (!LocaleSpanCompatUtils.isLocaleSpanAvailable()) { if (!LocaleSpanCompatUtils.isLocaleSpanAvailable()) {
return; return;

View File

@ -16,10 +16,15 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build; import android.os.Build;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.SuggestionSpan; import android.text.style.SuggestionSpan;
@ -33,8 +38,16 @@ import java.util.Locale;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class SuggestionSpanUtilsTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class SuggestionSpanUtilsTest {
private Context getContext() {
return InstrumentationRegistry.getTargetContext();
}
/** /**
* Helper method to create a dummy {@link SuggestedWordInfo}. * Helper method to create a dummy {@link SuggestedWordInfo}.
@ -91,6 +104,7 @@ public class SuggestionSpanUtilsTest extends AndroidTestCase {
} }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
@Test
public void testGetTextWithAutoCorrectionIndicatorUnderline() { public void testGetTextWithAutoCorrectionIndicatorUnderline() {
final String ORIGINAL_TEXT = "Hey!"; final String ORIGINAL_TEXT = "Hey!";
final Locale NONNULL_LOCALE = new Locale("en", "GB"); final Locale NONNULL_LOCALE = new Locale("en", "GB");
@ -107,6 +121,7 @@ public class SuggestionSpanUtilsTest extends AndroidTestCase {
} }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
@Test
public void testGetTextWithAutoCorrectionIndicatorUnderlineRootLocale() { public void testGetTextWithAutoCorrectionIndicatorUnderlineRootLocale() {
final String ORIGINAL_TEXT = "Hey!"; final String ORIGINAL_TEXT = "Hey!";
final CharSequence text = SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( final CharSequence text = SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
@ -121,6 +136,7 @@ public class SuggestionSpanUtilsTest extends AndroidTestCase {
new String[]{}, Locale.ROOT, text); new String[]{}, Locale.ROOT, text);
} }
@Test
public void testGetTextWithSuggestionSpan() { public void testGetTextWithSuggestionSpan() {
final SuggestedWordInfo prediction1 = final SuggestedWordInfo prediction1 =
createWordInfo("Quality", SuggestedWordInfo.KIND_PREDICTION); createWordInfo("Quality", SuggestedWordInfo.KIND_PREDICTION);
@ -218,6 +234,7 @@ public class SuggestionSpanUtilsTest extends AndroidTestCase {
} }
} }
@Test
public void testFindFirstLocaleFromSuggestionSpans() { public void testFindFirstLocaleFromSuggestionSpans() {
final String[] suggestions = new String[] {"Quality", "Speed", "Price"}; final String[] suggestions = new String[] {"Quality", "Speed", "Price"};
final SuggestionSpan nullLocaleSpan = new SuggestionSpan((Locale)null, suggestions, 0); final SuggestionSpan nullLocaleSpan = new SuggestionSpan((Locale)null, suggestions, 0);

View File

@ -16,10 +16,12 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import static org.junit.Assert.assertTrue;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Parcel; import android.os.Parcel;
import android.test.AndroidTestCase; import android.support.test.filters.SmallTest;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.runner.AndroidJUnit4;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
@ -29,8 +31,13 @@ import android.view.textservice.TextInfo;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class TextInfoCompatUtilsTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class TextInfoCompatUtilsTests {
final private static String TEST_TEXT = "0123456789"; final private static String TEST_TEXT = "0123456789";
final private static int TEST_COOKIE = 0x1234; final private static int TEST_COOKIE = 0x1234;
final private static int TEST_SEQUENCE_NUMBER = 0x4321; final private static int TEST_SEQUENCE_NUMBER = 0x4321;
@ -45,6 +52,7 @@ public class TextInfoCompatUtilsTests extends AndroidTestCase {
final private static int TEST_URL_SPAN_END = 7; final private static int TEST_URL_SPAN_END = 7;
final private static int TEST_URL_SPAN_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; final private static int TEST_URL_SPAN_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
@Test
public void testGetCharSequence() { public void testGetCharSequence() {
final SpannableString text = new SpannableString(TEST_TEXT); final SpannableString text = new SpannableString(TEST_TEXT);
text.setSpan(TEST_STYLE_SPAN, TEST_STYLE_SPAN_START, TEST_STYLE_SPAN_END, text.setSpan(TEST_STYLE_SPAN, TEST_STYLE_SPAN_START, TEST_STYLE_SPAN_END,