diff options
author | 2018-07-06 10:10:54 -0700 | |
---|---|---|
committer | 2018-07-06 10:10:54 -0700 | |
commit | d3b93cc95061ada6a162d7989e313f818e6d4e15 (patch) | |
tree | a4e3eaee6b84d20817d82b2a263e0e47bcc98753 /tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | |
parent | a497886dda70bbd401652560d11d8f4010985e96 (diff) | |
download | latinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.tar.gz latinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.tar.xz latinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.zip |
Migrate to Android Testing Support Lib (part 5/N)
This CL converts 19 test classes under com.android.inputmethod.latin
to Android Testing Support Library.
Bug: 110805255
Test: verified as follows. No new test failures.
tapas adb LatinIME LatinIMETests arm64 userdebug && \
DISABLE_PROGUARD=true make -j LatinIME && \
adb install -r $OUT/system/app/LatinIME/LatinIME.apk && \
atest LatinIMETests:com.android.inputmethod.latin
Change-Id: I878fcae0126f57c43a644af341e5a0a8ac8f5cc9
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | 46 |
1 files changed, 32 insertions, 14 deletions
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( |