diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index e96c934cb..29542730c 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -16,8 +16,14 @@ package com.android.inputmethod.latin; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; +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 android.support.test.InstrumentationRegistry; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; import android.text.TextUtils; import android.util.Pair; @@ -38,27 +44,31 @@ import java.util.HashSet; import java.util.Locale; import java.util.Random; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + @LargeTest -public class BinaryDictionaryTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class BinaryDictionaryTests { private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_LOCALE = "test"; private static final String DICTIONARY_ID = "TestBinaryDictionary"; private HashSet mDictFilesToBeDeleted = new HashSet<>(); - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { mDictFilesToBeDeleted.clear(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { for (final File dictFile : mDictFilesToBeDeleted) { dictFile.delete(); } mDictFilesToBeDeleted.clear(); - super.tearDown(); } private File createEmptyDictionaryAndGetFile(final int formatVersion) { @@ -82,7 +92,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { private File createEmptyVer4DictionaryAndGetFile(final int formatVersion, final HashMap attributeMap) throws IOException { final File file = File.createTempFile(DICTIONARY_ID, TEST_DICT_FILE_EXTENSION, - getContext().getCacheDir()); + InstrumentationRegistry.getTargetContext().getCacheDir()); file.delete(); file.mkdir(); if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion, @@ -106,6 +116,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); } + @Test public void testIsValidDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -121,6 +132,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testConstructingDictionaryOnMemory() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); FileUtils.deleteRecursively(dictFile); @@ -142,6 +154,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testAddTooLongWord() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final StringBuffer stringBuilder = new StringBuffer(); @@ -209,6 +222,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2); } + @Test public void testAddUnigramWord() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int probability = 100; @@ -236,6 +250,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals(updatedProbability, binaryDictionary.getFrequency("aaa")); } + @Test public void testRandomlyAddUnigramWord() { final int wordCount = 1000; final int codePointSetSize = 50; @@ -258,6 +273,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddBigramWords() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); @@ -311,6 +327,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { getBigramProbability(binaryDictionary, "abcde", "fghij")); } + @Test public void testRandomlyAddBigramWords() { final int wordCount = 100; final int bigramCount = 1000; @@ -357,6 +374,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddTrigramWords() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int unigramProbability = 100; @@ -383,6 +401,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); } + @Test public void testFlushDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -417,6 +436,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testFlushWithGCDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -447,6 +467,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testAddBigramWordsAndFlashWithGC() { final int wordCount = 100; final int bigramCount = 1000; @@ -499,6 +520,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testRandomOperationsAndFlashWithGC() { final int maxUnigramCount = 5000; final int maxBigramCount = 10000; @@ -593,6 +615,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddManyUnigramsAndFlushWithGC() { final int flashWithGCIterationCount = 3; final int codePointSetSize = 50; @@ -628,6 +651,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testUnigramAndBigramCount() { final int maxUnigramCount = 5000; final int maxBigramCount = 10000; @@ -684,6 +708,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testGetWordProperties() { final long seed = System.currentTimeMillis(); final Random random = new Random(seed); @@ -769,6 +794,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testIterateAllWords() { final long seed = System.currentTimeMillis(); final Random random = new Random(seed); @@ -852,6 +878,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertTrue(bigramSet.isEmpty()); } + @Test public void testPossiblyOffensiveAttributeMaintained() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); @@ -860,6 +887,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals(true, wordProperty.mIsPossiblyOffensive); } + @Test public void testBeginningOfSentence() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int dummyProbability = 0; diff --git a/tests/src/com/android/inputmethod/latin/ContactsManagerTest.java b/tests/src/com/android/inputmethod/latin/ContactsManagerTest.java index f987e0c05..1cc289a27 100644 --- a/tests/src/com/android/inputmethod/latin/ContactsManagerTest.java +++ b/tests/src/com/android/inputmethod/latin/ContactsManagerTest.java @@ -16,6 +16,10 @@ package com.android.inputmethod.latin; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; @@ -23,34 +27,38 @@ import android.database.MatrixCursor; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; -import android.test.AndroidTestCase; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import android.test.RenamingDelegatingContext; import android.test.mock.MockContentProvider; import android.test.mock.MockContentResolver; -import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.latin.ContactsDictionaryConstants; import com.android.inputmethod.latin.ContactsManager; -import org.junit.Before; -import org.junit.Test; - import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.TimeUnit; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Tests for {@link ContactsManager} */ @SmallTest -public class ContactsManagerTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class ContactsManagerTest { private ContactsManager mManager; private FakeContactsContentProvider mFakeContactsContentProvider; private MatrixCursor mMatrixCursor; + private final static float EPSILON = 0.00001f; + @Before - @Override public void setUp() throws Exception { // Fake content provider mFakeContactsContentProvider = new FakeContactsContentProvider(); @@ -59,7 +67,8 @@ public class ContactsManagerTest extends AndroidTestCase { final MockContentResolver contentResolver = new MockContentResolver(); contentResolver.addProvider(ContactsContract.AUTHORITY, mFakeContactsContentProvider); // Add the fake content resolver to a fake context. - final ContextWithMockContentResolver context = new ContextWithMockContentResolver(mContext); + final ContextWithMockContentResolver context = + new ContextWithMockContentResolver(InstrumentationRegistry.getTargetContext()); context.setContentResolver(contentResolver); mManager = new ContactsManager(context); @@ -113,9 +122,10 @@ public class ContactsManagerTest extends AndroidTestCase { cursor.moveToFirst(); ContactsManager.RankedContact contact = new ContactsManager.RankedContact(cursor); contact.computeAffinity(1, month_ago); - assertEquals(contact.getAffinity(), 1.0f); + assertEquals(contact.getAffinity(), 1.0f, EPSILON); contact.computeAffinity(2, now); - assertEquals(contact.getAffinity(), (2.0f/3.0f + (float)Math.pow(0.5, 3) + 1.0f) / 3); + assertEquals(contact.getAffinity(), (2.0f/3.0f + (float)Math.pow(0.5, 3) + 1.0f) / 3, + EPSILON); } @Test diff --git a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java index 6b0bbc279..cdb5b8e72 100644 --- a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java +++ b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java @@ -16,16 +16,26 @@ package com.android.inputmethod.latin; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.Locale; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; @LargeTest -public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class DictionaryFacilitatorLruCacheTests { + + @Test public void testGetFacilitator() { final DictionaryFacilitatorLruCache cache = - new DictionaryFacilitatorLruCache(getContext(), ""); + new DictionaryFacilitatorLruCache(InstrumentationRegistry.getTargetContext(), ""); final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US); assertNotNull(dictionaryFacilitatorEnUs); diff --git a/tests/src/com/android/inputmethod/latin/NgramContextTests.java b/tests/src/com/android/inputmethod/latin/NgramContextTests.java index 0a662db82..6fa8a5a47 100644 --- a/tests/src/com/android/inputmethod/latin/NgramContextTests.java +++ b/tests/src/com/android/inputmethod/latin/NgramContextTests.java @@ -16,15 +16,26 @@ package com.android.inputmethod.latin; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import com.android.inputmethod.latin.utils.NgramContextUtils; -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 org.junit.Test; +import org.junit.runner.RunWith; @SmallTest -public class NgramContextTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class NgramContextTests { + + @Test public void testConstruct() { assertEquals(new NgramContext(new WordInfo("a")), new NgramContext(new WordInfo("a"))); assertEquals(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO), @@ -35,6 +46,7 @@ public class NgramContextTests extends AndroidTestCase { new NgramContext(WordInfo.EMPTY_WORD_INFO)); } + @Test public void testIsBeginningOfSentenceContext() { assertFalse(new NgramContext().isBeginningOfSentenceContext()); assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO) @@ -52,6 +64,7 @@ public class NgramContextTests extends AndroidTestCase { .isBeginningOfSentenceContext()); } + @Test public void testGetNextNgramContext() { final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); final NgramContext ngramContext_b_a = @@ -67,6 +80,7 @@ public class NgramContextTests extends AndroidTestCase { assertEquals("c", ngramContext_c_bos.getNthPrevWord(1)); } + @Test public void testExtractPrevWordsContextTest() { final NgramContext ngramContext_bos = new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); @@ -92,6 +106,7 @@ public class NgramContextTests extends AndroidTestCase { assertEquals("a", ngramContext_a_empty.extractPrevWordsContext()); } + @Test public void testExtractPrevWordsContextArray() { final NgramContext ngramContext_bos = new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); @@ -123,9 +138,10 @@ public class NgramContextTests extends AndroidTestCase { assertEquals("a", ngramContext_a_empty.extractPrevWordsContextArray()[0]); } + @Test public void testGetNgramContextFromNthPreviousWord() { SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations( - mContext.getResources()); + InstrumentationRegistry.getTargetContext().getResources()); assertEquals("", NgramContextUtils.getNgramContextFromNthPreviousWord("", spacingAndPunctuations, 1).extractPrevWordsContext()); assertEquals(" b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ", diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java index 128f9f7db..51a217b4d 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java @@ -16,12 +16,16 @@ package com.android.inputmethod.latin; +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.inputmethodservice.InputMethodService; import android.os.Parcel; -import android.test.AndroidTestCase; -import android.test.MoreAsserts; -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.SpannableString; import android.text.TextUtils; import android.text.style.SuggestionSpan; @@ -40,23 +44,27 @@ import com.android.inputmethod.latin.utils.TextRange; import java.util.Locale; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class RichInputConnectionAndTextRangeTests { // The following is meant to be a reasonable default for // the "word_separators" resource. private SpacingAndPunctuations mSpacingAndPunctuations; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { final RunInLocale job = new RunInLocale() { @Override protected SpacingAndPunctuations job(final Resources res) { return new SpacingAndPunctuations(res); } }; - final Resources res = getContext().getResources(); + final Resources res = InstrumentationRegistry.getTargetContext().getResources(); mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH); } @@ -156,6 +164,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { /** * Test for getting previous word (for bigram suggestions) */ + @Test public void testGetPreviousWord() { // If one of the following cases breaks, the bigram suggestions won't work. assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( @@ -218,6 +227,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { "abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); } + @Test public void testGetWordRangeAtCursor() { /** * Test logic in getting the word range at the cursor. @@ -282,6 +292,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { /** * Test logic in getting the word range at the cursor. */ + @Test public void testGetSuggestionSpansAtWord() { helpTestGetSuggestionSpansAtWord(10); helpTestGetSuggestionSpansAtWord(12); @@ -309,7 +320,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test the case with 2 suggestion spans in the same place. text = new SpannableString("This is a string for test"); @@ -321,8 +332,8 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 2); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); - MoreAsserts.assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); // Test a case with overlapping spans, 2nd extending past the start of the word text = new SpannableString("This is a string for test"); @@ -334,7 +345,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, 2nd extending past the end of the word text = new SpannableString("This is a string for test"); @@ -346,7 +357,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, 2nd extending past both ends of the word text = new SpannableString("This is a string for test"); @@ -358,7 +369,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, none right on the word text = new SpannableString("This is a string for test"); @@ -372,6 +383,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { assertEquals(suggestions.length, 0); } + @Test public void testCursorTouchingWord() { final MockInputMethodService ims = new MockInputMethodService(); final RichInputConnection ic = new RichInputConnection(ims); diff --git a/tests/src/com/android/inputmethod/latin/RichInputMethodSubtypeTests.java b/tests/src/com/android/inputmethod/latin/RichInputMethodSubtypeTests.java index af94be664..2b787ea32 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputMethodSubtypeTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputMethodSubtypeTests.java @@ -16,12 +16,18 @@ package com.android.inputmethod.latin; +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.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; @@ -33,8 +39,14 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; 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 RichInputMethodSubtypeTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class RichInputMethodSubtypeTests { // All input method subtypes of LatinIME. private final ArrayList mSubtypesList = new ArrayList<>(); @@ -67,10 +79,9 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase { RichInputMethodSubtype HI_LATN_DVORAK; RichInputMethodSubtype SR_LATN_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(); @@ -152,13 +163,13 @@ public class RichInputMethodSubtypeTests 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 testAllFullDisplayNameForSpacebar() { for (final RichInputMethodSubtype subtype : mSubtypesList) { final String subtypeName = SubtypeLocaleUtils @@ -174,7 +185,8 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase { } } - public void testAllMiddleDisplayNameForSpacebar() { + @Test + public void testAllMiddleDisplayNameForSpacebar() { for (final RichInputMethodSubtype subtype : mSubtypesList) { final String subtypeName = SubtypeLocaleUtils .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); @@ -293,22 +305,27 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase { } }; + @Test public void testPredefinedSubtypesForSpacebarInEnglish() { testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); } + @Test public void testAdditionalSubtypeForSpacebarInEnglish() { testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); } + @Test public void testPredefinedSubtypesForSpacebarInFrench() { testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); } + @Test public void testAdditionalSubtypeForSpacebarInFrench() { testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); } + @Test public void testRichInputMethodSubtypeForNullInputMethodSubtype() { RichInputMethodSubtype subtype = RichInputMethodSubtype.getRichInputMethodSubtype(null); assertNotNull(subtype); diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java index d465ce674..967b17f09 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java +++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java @@ -16,16 +16,24 @@ package com.android.inputmethod.latin; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.util.ArrayList; import java.util.Locale; @SmallTest -public class SuggestedWordsTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class SuggestedWordsTests { /** * Helper method to create a dummy {@link SuggestedWordInfo} with specifying @@ -80,30 +88,35 @@ public class SuggestedWordsTests extends AndroidTestCase { return returnedWordInfo; } + @Test public void testRemoveDupesNoDupes() { final ArrayList infos = createCorrectionWordInfos("a", "c"); assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(2, infos.size()); } + @Test public void testRemoveDupesTypedWordNotDupe() { final ArrayList infos = createCorrectionWordInfos("a", "a", "c"); assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(2, infos.size()); } + @Test public void testRemoveDupesTypedWordOnlyDupe() { final ArrayList infos = createCorrectionWordInfos("a", "b", "c"); assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(2, infos.size()); } + @Test public void testRemoveDupesTypedWordNotOnlyDupe() { final ArrayList infos = createCorrectionWordInfos("a", "b", "b", "c"); assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(2, infos.size()); } + @Test public void testGetTransformedSuggestedWordInfo() { SuggestedWordInfo result = transformWordInfo("word", 0); assertEquals(result.mWord, "word"); @@ -119,6 +132,7 @@ public class SuggestedWordsTests extends AndroidTestCase { assertEquals(result.mWord, "didn't''"); } + @Test public void testGetTypedWordInfoOrNull() { final String TYPED_WORD = "typed"; final SuggestedWordInfo TYPED_WORD_INFO = createTypedWordInfo(TYPED_WORD); diff --git a/tests/src/com/android/inputmethod/latin/WordComposerTests.java b/tests/src/com/android/inputmethod/latin/WordComposerTests.java index 8ae475f7e..25e57eee6 100644 --- a/tests/src/com/android/inputmethod/latin/WordComposerTests.java +++ b/tests/src/com/android/inputmethod/latin/WordComposerTests.java @@ -16,18 +16,29 @@ package com.android.inputmethod.latin; -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 android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.CoordinateUtils; import com.android.inputmethod.latin.common.StringUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Unit tests for WordComposer. */ @SmallTest -public class WordComposerTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class WordComposerTests { + + @Test public void testMoveCursor() { final WordComposer wc = new WordComposer(); // BMP is the Basic Multilingual Plane, as defined by Unicode. This includes diff --git a/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java index 832817967..aa2a5c2cf 100644 --- a/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java +++ b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java @@ -16,40 +16,54 @@ package com.android.inputmethod.latin.accounts; +import static org.junit.Assert.assertEquals; + import android.accounts.AccountManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.test.AndroidTestCase; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.settings.LocalSettingsConstants; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Tests for {@link AccountsChangedReceiver}. */ -public class AccountsChangedReceiverTests extends AndroidTestCase { +@SmallTest +@RunWith(AndroidJUnit4.class) +public class AccountsChangedReceiverTests { private static final String ACCOUNT_1 = "account1@example.com"; private static final String ACCOUNT_2 = "account2@example.com"; private SharedPreferences mPrefs; private String mLastKnownAccount = null; - @Override - protected void setUp() throws Exception { - super.setUp(); + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + @Before + public void setUp() throws Exception { mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); // Keep track of the current account so that we restore it when the test finishes. mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { // Restore the account that was present before running the test. updateAccountName(mLastKnownAccount); } + @Test public void testUnknownIntent() { updateAccountName(ACCOUNT_1); AccountsChangedReceiver reciever = new AccountsChangedReceiver(); @@ -58,6 +72,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase { assertAccountName(ACCOUNT_1); } + @Test public void testAccountRemoved() { updateAccountName(ACCOUNT_1); AccountsChangedReceiver reciever = new AccountsChangedReceiver() { @@ -71,6 +86,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase { assertAccountName(null); } + @Test public void testAccountRemoved_noAccounts() { updateAccountName(ACCOUNT_2); AccountsChangedReceiver reciever = new AccountsChangedReceiver() { @@ -84,6 +100,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase { assertAccountName(null); } + @Test public void testAccountNotRemoved() { updateAccountName(ACCOUNT_2); AccountsChangedReceiver reciever = new AccountsChangedReceiver() { diff --git a/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java b/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java index 6b3490de8..9ead0ae25 100644 --- a/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java +++ b/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java @@ -16,15 +16,27 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.Arrays; @SmallTest -public class InputPointersTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class InputPointersTests { private static final int DEFAULT_CAPACITY = 48; + @Test public void testNewInstance() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); assertEquals("new instance size", 0, src.getPointerSize()); @@ -34,6 +46,7 @@ public class InputPointersTests extends AndroidTestCase { assertNotNull("new instance times", src.getTimes()); } + @Test public void testReset() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int[] xCoordinates = src.getXCoordinates(); @@ -49,6 +62,7 @@ public class InputPointersTests extends AndroidTestCase { assertNotSame("times after reset", times, src.getTimes()); } + @Test public void testAdd() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = src.getXCoordinates().length * 2 + 10; @@ -72,6 +86,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testAddAt() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 1000, step = 100; @@ -95,6 +110,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testSet() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = src.getXCoordinates().length * 2 + 10; @@ -114,6 +130,7 @@ public class InputPointersTests extends AndroidTestCase { assertSame("times after set", dst.getTimes(), src.getTimes()); } + @Test public void testCopy() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 100; @@ -142,6 +159,7 @@ public class InputPointersTests extends AndroidTestCase { dst.getTimes(), 0, src.getTimes(), 0, size); } + @Test public void testAppend() { final int dstLength = 50; final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); @@ -211,6 +229,7 @@ public class InputPointersTests extends AndroidTestCase { srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength); } + @Test public void testAppendResizableIntArray() { final int dstLength = 50; final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); @@ -296,6 +315,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testShift() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 100; diff --git a/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java b/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java index bd1629faf..d9b6bad75 100644 --- a/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java +++ b/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java @@ -16,15 +16,27 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import java.util.Arrays; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class ResizableIntArrayTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class ResizableIntArrayTests { private static final int DEFAULT_CAPACITY = 48; + @Test public void testNewInstance() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -33,6 +45,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { assertEquals("new instance array length", DEFAULT_CAPACITY, array.length); } + @Test public void testAdd() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -62,6 +75,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testAddAt() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2; @@ -76,6 +90,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testGet() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); try { @@ -105,6 +120,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testReset() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -136,6 +152,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testSetLength() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -172,6 +189,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testSet() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 2 + 10; @@ -186,6 +204,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray()); } + @Test public void testCopy() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); for (int i = 0; i < DEFAULT_CAPACITY; i++) { @@ -214,6 +233,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength()); } + @Test public void testAppend() { final int srcLength = DEFAULT_CAPACITY; final ResizableIntArray src = new ResizableIntArray(srcLength); @@ -264,6 +284,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { srcLength); } + @Test public void testFill() { final int srcLength = DEFAULT_CAPACITY; final ResizableIntArray src = new ResizableIntArray(srcLength); @@ -359,6 +380,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testShift() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 10; diff --git a/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java index ec9d4be92..393efe6eb 100644 --- a/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java @@ -16,13 +16,21 @@ package com.android.inputmethod.latin.common; -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 android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import java.util.Locale; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class StringUtilsTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class StringUtilsTests { private static final Locale US = Locale.US; private static final Locale GERMAN = Locale.GERMAN; private static final Locale TURKEY = new Locale("tr", "TR"); @@ -34,6 +42,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale)); } + @Test public void test_toTitleCaseOfKeyLabel() { assert_toTitleCaseOfKeyLabel(US, null, null); assert_toTitleCaseOfKeyLabel(US, "", ""); @@ -116,6 +125,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toTitleCaseOfKeyCode(lowerCase, locale)); } + @Test public void test_toTitleCaseOfKeyCode() { assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER); assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE); @@ -148,6 +158,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstCodePoint(text, locale)); } + @Test public void test_capitalizeFirstCodePoint() { assert_capitalizeFirstCodePoint(US, "", ""); assert_capitalizeFirstCodePoint(US, "a", "A"); @@ -167,6 +178,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstAndDowncaseRest(text, locale)); } + @Test public void test_capitalizeFirstAndDowncaseRest() { assert_capitalizeFirstAndDowncaseRest(US, "", ""); assert_capitalizeFirstAndDowncaseRest(US, "a", "A"); @@ -185,6 +197,7 @@ public class StringUtilsTests extends AndroidTestCase { assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση"); } + @Test public void testContainsInArray() { assertFalse("empty array", StringUtils.containsInArray("key", new String[0])); assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] { @@ -202,6 +215,7 @@ public class StringUtilsTests extends AndroidTestCase { })); } + @Test public void testContainsInCommaSplittableText() { assertFalse("null", StringUtils.containsInCommaSplittableText("key", null)); assertFalse("empty", StringUtils.containsInCommaSplittableText("key", "")); @@ -214,6 +228,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key")); } + @Test public void testRemoveFromCommaSplittableTextIfExists() { assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null)); assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", "")); @@ -239,7 +254,7 @@ public class StringUtilsTests extends AndroidTestCase { "key", "key1,key,key3,key,key5")); } - + @Test public void testCapitalizeFirstCodePoint() { assertEquals("SSaa", StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN)); @@ -259,6 +274,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH)); } + @Test public void testCapitalizeFirstAndDowncaseRest() { assertEquals("SSaa", StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN)); @@ -278,6 +294,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH)); } + @Test public void testGetCapitalizationType() { assertEquals(StringUtils.CAPITALIZE_NONE, StringUtils.getCapitalizationType("capitalize")); @@ -301,6 +318,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.getCapitalizationType("")); } + @Test public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() { assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize")); assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize")); @@ -337,6 +355,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toSortedCodePointArray(" \n.!?*()&"); private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&"); + @Test public void testCapitalizeEachWord() { checkCapitalize("", "", SPACE, Locale.ENGLISH); checkCapitalize("test", "Test", SPACE, Locale.ENGLISH); @@ -367,6 +386,7 @@ public class StringUtilsTests extends AndroidTestCase { WORD_SEPARATORS, Locale.ENGLISH); } + @Test public void testLooksLikeURL() { assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google.")); assertFalse(StringUtils.lastPartLooksLikeURL("word wo")); @@ -389,6 +409,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def")); } + @Test public void testHexStringUtils() { final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33, (byte)0x55, (byte)0x88, (byte)0xEE }; @@ -401,6 +422,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue(bytesStr.equals(bytesStr2)); } + @Test public void testToCodePointArray() { final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx"; final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h', @@ -414,6 +436,7 @@ public class StringUtilsTests extends AndroidTestCase { } } + @Test public void testCopyCodePointsAndReturnCodePointCount() { final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx"; final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7, @@ -465,6 +488,7 @@ public class StringUtilsTests extends AndroidTestCase { exceptionHappened); } + @Test public void testGetTrailingSingleQuotesCount() { assertEquals(0, StringUtils.getTrailingSingleQuotesCount("")); assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'")); diff --git a/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java index 59bb08292..43fdeec96 100644 --- a/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java +++ b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java @@ -16,18 +16,28 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; @SmallTest -public class UnicodeSurrogateTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class UnicodeSurrogateTests { + @Test public void testIsLowSurrogate() { assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF')); assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D')); assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00')); } + @Test public void testIsHighSurrogate() { assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF')); assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25')); diff --git a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java index 8f24cdb44..bdbbaf2e6 100644 --- a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java +++ b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java @@ -16,13 +16,16 @@ package com.android.inputmethod.latin.network; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor; @@ -40,19 +43,24 @@ import java.net.HttpURLConnection; import java.util.Arrays; import java.util.Random; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Tests for {@link BlockingHttpClient}. */ @SmallTest -public class BlockingHttpClientTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class BlockingHttpClientTests { @Mock HttpURLConnection mMockHttpConnection; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } + @Test public void testError_badGateway() throws IOException, AuthException { when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY); final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); @@ -67,6 +75,7 @@ public class BlockingHttpClientTests extends AndroidTestCase { } } + @Test public void testError_clientTimeout() throws Exception { when(mMockHttpConnection.getResponseCode()).thenReturn( HttpURLConnection.HTTP_CLIENT_TIMEOUT); @@ -82,6 +91,7 @@ public class BlockingHttpClientTests extends AndroidTestCase { } } + @Test public void testError_forbiddenWithRequest() throws Exception { final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN); @@ -98,6 +108,7 @@ public class BlockingHttpClientTests extends AndroidTestCase { verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100)); } + @Test public void testSuccess_emptyRequest() throws Exception { final Random rand = new Random(); byte[] response = new byte[100]; @@ -112,6 +123,7 @@ public class BlockingHttpClientTests extends AndroidTestCase { assertTrue("ResponseProcessor was not invoked", processor.mInvoked); } + @Test public void testSuccess() throws Exception { final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); final Random rand = new Random(); diff --git a/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java index 5b3e78eaf..fce812ea7 100644 --- a/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java +++ b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java @@ -20,25 +20,28 @@ import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MOD import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_DOWNLOAD_ONLY; import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_UPLOAD_ONLY; -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 android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import org.junit.Test; +import org.junit.runner.RunWith; /** * Tests for {@link HttpUrlConnectionBuilder}. */ @SmallTest -public class HttpUrlConnectionBuilderTests extends AndroidTestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - +@RunWith(AndroidJUnit4.class) +public class HttpUrlConnectionBuilderTests { + @Test public void testSetUrl_malformed() { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); try { @@ -49,6 +52,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { } } + @Test public void testSetConnectTimeout_invalid() { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); try { @@ -59,6 +63,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { } } + @Test public void testSetConnectTimeout() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("https://www.example.com"); @@ -67,6 +72,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertEquals(8765, connection.getConnectTimeout()); } + @Test public void testSetReadTimeout_invalid() { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); try { @@ -77,6 +83,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { } } + @Test public void testSetReadTimeout() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("https://www.example.com"); @@ -85,6 +92,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertEquals(8765, connection.getReadTimeout()); } + @Test public void testAddHeader() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("http://www.example.com"); @@ -93,6 +101,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertEquals("some-random-value", connection.getRequestProperty("some-random-key")); } + @Test public void testSetUseCache_notSet() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("http://www.example.com"); @@ -100,6 +109,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertFalse(connection.getUseCaches()); } + @Test public void testSetUseCache_false() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("http://www.example.com"); @@ -108,6 +118,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertFalse(connection.getUseCaches()); } + @Test public void testSetUseCache_true() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("http://www.example.com"); @@ -116,6 +127,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertTrue(connection.getUseCaches()); } + @Test public void testSetMode_uploadOnly() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("http://www.example.com"); @@ -125,6 +137,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertFalse(connection.getDoOutput()); } + @Test public void testSetMode_downloadOnly() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("https://www.example.com"); @@ -134,6 +147,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertTrue(connection.getDoOutput()); } + @Test public void testSetMode_bidirectional() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("https://www.example.com"); @@ -143,6 +157,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase { assertTrue(connection.getDoOutput()); } + @Test public void testSetAuthToken() throws IOException { HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); builder.setUrl("https://www.example.com"); diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index 559f28642..8f786d57b 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -16,8 +16,12 @@ package com.android.inputmethod.latin.personalization; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; import android.util.Log; import com.android.inputmethod.latin.ExpandableBinaryDictionary; @@ -27,17 +31,27 @@ import java.io.File; import java.util.Locale; import java.util.Random; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Unit tests for UserHistoryDictionary */ @LargeTest -public class UserHistoryDictionaryTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class UserHistoryDictionaryTests { private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName(); private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000; private static final String TEST_ACCOUNT = "account@example.com"; private int mCurrentTime = 0; + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + private static void printAllFiles(final File dir) { Log.d(TAG, dir.getAbsolutePath()); for (final File file : dir.listFiles()) { @@ -62,20 +76,18 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { assertTrue("Following dictionary file doesn't exist: " + dictFile, dictFile.exists()); } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { resetCurrentTimeForTestMode(); UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( - UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); + UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext()); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( - UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); + UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext()); stopTestModeInNativeCode(); - super.tearDown(); } private void resetCurrentTimeForTestMode() { @@ -111,7 +123,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { null /* dictFile */, testAccount /* account */); final File dictFile = ExpandableBinaryDictionary.getDictFile( - mContext, dictName, null /* dictFile */); + getContext(), dictName, null /* dictFile */); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( getContext(), dummyLocale, testAccount); clearHistory(dict); @@ -123,18 +135,22 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { assertDictionaryExists(dict, dictFile); } + @Test public void testRandomWords_NullAccount() { doTestRandomWords(null /* testAccount */); } + @Test public void testRandomWords() { doTestRandomWords(TEST_ACCOUNT); } + @Test public void testStressTestForSwitchingLanguagesAndAddingWords() { doTestStressTestForSwitchingLanguagesAndAddingWords(TEST_ACCOUNT); } + @Test public void testStressTestForSwitchingLanguagesAndAddingWords_NullAccount() { doTestStressTestForSwitchingLanguagesAndAddingWords(null /* testAccount */); } @@ -158,7 +174,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, testAccount /* account */); dictFiles[i] = ExpandableBinaryDictionary.getDictFile( - mContext, dictName, null /* dictFile */); + getContext(), dictName, null /* dictFile */); dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale, testAccount); clearHistory(dicts[i]); @@ -186,10 +202,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddManyWords() { doTestAddManyWords(TEST_ACCOUNT); } + @Test public void testAddManyWords_NullAccount() { doTestAddManyWords(null /* testAccount */); } @@ -200,7 +218,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final String dictName = UserHistoryDictionary.getUserHistoryDictName( UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, testAccount); final File dictFile = ExpandableBinaryDictionary.getDictFile( - mContext, dictName, null /* dictFile */); + getContext(), dictName, null /* dictFile */); final int numberOfWords = 10000; final Random random = new Random(123456); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( diff --git a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java index ed632db68..52ed2ae10 100644 --- a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java +++ b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java @@ -16,9 +16,16 @@ package com.android.inputmethod.latin.settings; +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 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 com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.common.Constants; @@ -28,13 +35,22 @@ import junit.framework.AssertionFailedError; import java.util.Locale; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class SpacingAndPunctuationsTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class SpacingAndPunctuationsTests { private static final int ARMENIAN_FULL_STOP = '\u0589'; private static final int ARMENIAN_COMMA = '\u055D'; private int mScreenMetrics; + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + private boolean isPhone() { return Constants.isPhone(mScreenMetrics); } @@ -63,10 +79,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { private SpacingAndPunctuations CAMBODIA_KHMER; private SpacingAndPunctuations LAOS_LAO; - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { mScreenMetrics = Settings.readScreenMetrics(getContext().getResources()); // Language only @@ -140,6 +154,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse("Tilde", sp.isWordSeparator('~')); } + @Test public void testWordSeparator() { testingStandardWordSeparator(ENGLISH); testingStandardWordSeparator(FRENCH); @@ -192,6 +207,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { } + @Test public void testWordConnector() { testingStandardWordConnector(ENGLISH); testingStandardWordConnector(FRENCH); @@ -245,6 +261,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); } + @Test public void testIsUsuallyPrecededBySpace() { testingStandardPrecededBySpace(ENGLISH); testingCommonPrecededBySpace(FRENCH); @@ -298,6 +315,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); } + @Test public void testIsUsuallyFollowedBySpace() { testingStandardFollowedBySpace(ENGLISH); testingStandardFollowedBySpace(FRENCH); @@ -345,7 +363,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); } - public void isSentenceSeparator() { + @Test + public void testIsSentenceSeparator() { testingStandardSentenceSeparator(ENGLISH); try { testingStandardSentenceSeparator(ARMENIA_ARMENIAN); @@ -357,6 +376,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_COMMA)); } + @Test public void testLanguageHasSpace() { assertTrue(ENGLISH.mCurrentLanguageHasSpaces); assertTrue(FRENCH.mCurrentLanguageHasSpaces); @@ -369,6 +389,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertTrue(LAO.mCurrentLanguageHasSpaces); } + @Test public void testUsesAmericanTypography() { assertTrue(ENGLISH.mUsesAmericanTypography); assertTrue(UNITED_STATES.mUsesAmericanTypography); @@ -379,6 +400,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertFalse(SWISS_GERMAN.mUsesAmericanTypography); } + @Test public void testUsesGermanRules() { assertFalse(ENGLISH.mUsesGermanRules); assertFalse(FRENCH.mUsesGermanRules); @@ -436,6 +458,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { } } + @Test public void testPhonePunctuationSuggestions() { if (!isPhone()) { return; @@ -454,6 +477,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW); } + @Test public void testTabletPunctuationSuggestions() { if (!isTablet()) { return; diff --git a/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java b/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java index f3273a2d1..b44a9290b 100644 --- a/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java +++ b/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java @@ -16,13 +16,22 @@ package com.android.inputmethod.latin.suggestions; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static junit.framework.TestCase.assertEquals; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import com.android.inputmethod.latin.SuggestedWords; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class SuggestionStripLayoutHelperTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class SuggestionStripLayoutHelperTests { private static void confirmShowTypedWord(final String message, final int inputType) { assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( inputType, @@ -42,6 +51,7 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase { true /* shouldShowUiToAcceptTypedWord */)); } + @Test public void testShouldShowTypedWord() { confirmShowTypedWord("no input style", SuggestedWords.INPUT_STYLE_NONE); @@ -51,7 +61,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase { SuggestedWords.INPUT_STYLE_RECORRECTION); } - public void testshouldOmitTypedWordWhileTyping() { + @Test + public void testShouldOmitTypedWordWhileTyping() { assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( SuggestedWords.INPUT_STYLE_TYPING, false /* gestureFloatingPreviewTextEnabled */, @@ -70,7 +81,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase { true /* shouldShowUiToAcceptTypedWord */)); } - public void testshouldOmitTypedWordWhileGesturing() { + @Test + public void testShouldOmitTypedWordWhileGesturing() { assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( SuggestedWords.INPUT_STYLE_UPDATE_BATCH, false /* gestureFloatingPreviewTextEnabled */, @@ -89,7 +101,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase { true /* shouldShowUiToAcceptTypedWord */)); } - public void testshouldOmitTypedWordWhenGestured() { + @Test + public void testShouldOmitTypedWordWhenGestured() { assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( SuggestedWords.INPUT_STYLE_TAIL_BATCH, false /* gestureFloatingPreviewTextEnabled */, @@ -115,6 +128,7 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase { private static final int POSITION_CENTER = 1; private static final int POSITION_RIGHT = 2; + @Test public void testGetPositionInSuggestionStrip() { assertEquals("1st word without auto correction", POSITION_CENTER, SuggestionStripLayoutHelper.getPositionInSuggestionStrip( diff --git a/tests/src/com/android/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java b/tests/src/com/android/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java index ad6bcc3c4..d508f3667 100644 --- a/tests/src/com/android/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java +++ b/tests/src/com/android/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java @@ -16,18 +16,26 @@ package com.android.inputmethod.latin.touchinputconsumer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; /** * Tests for GestureConsumer.NULL_GESTURE_CONSUMER. */ @SmallTest -public class NullGestureConsumerTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class NullGestureConsumerTests { /** * Tests that GestureConsumer.NULL_GESTURE_CONSUMER indicates that it won't consume gesture data * and that its methods don't raise exceptions even for invalid data. */ + @Test public void testNullGestureConsumer() { assertFalse(GestureConsumer.NULL_GESTURE_CONSUMER.willConsume()); GestureConsumer.NULL_GESTURE_CONSUMER.onInit(null, null); @@ -40,6 +48,7 @@ public class NullGestureConsumerTests extends AndroidTestCase { /** * Tests that newInstance returns NULL_GESTURE_CONSUMER for invalid input. */ + @Test public void testNewInstanceGivesNullGestureConsumerForInvalidInputs() { assertSame(GestureConsumer.NULL_GESTURE_CONSUMER, GestureConsumer.newInstance(null, null, null, null));