diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-09-27 22:17:48 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-09-27 22:17:48 +0000 |
commit | c0774967193892aa2cd84bdc6bcd13168f2a02d0 (patch) | |
tree | ef8853195e8a534c28df5118b80cf59b0349d4f9 /tests | |
parent | 9d70f53e0d2eda1356af27b2a083c96257ff872e (diff) | |
parent | a2286cca9eb5e5e31a2803345438145b3f0641d1 (diff) | |
download | ContactsProvider-c0774967193892aa2cd84bdc6bcd13168f2a02d0.tar.gz |
Merge "Removing mimetype and package cache"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java index ff6a7a2c..10cd2fb4 100644 --- a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java +++ b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java @@ -156,13 +156,9 @@ public class ContactsDatabaseHelperTest extends BaseContactsProvider2Test { } /** - * Test for {@link ContactsDatabaseHelper#getPackageId(String)} and - * {@link ContactsDatabaseHelper#getMimeTypeId(String)}. - * - * We test them at the same time here, to make sure they're not mixing up the caches. + * Test for {@link ContactsDatabaseHelper#getPackageId(String)} */ - public void testGetPackageId_getMimeTypeId() { - + public void testGetPackageId() { // Test for getPackageId. final long packageId1 = mDbHelper.getPackageId("value1"); final long packageId2 = mDbHelper.getPackageId("value2"); @@ -173,44 +169,51 @@ public class ContactsDatabaseHelperTest extends BaseContactsProvider2Test { set.add(packageId1); set.add(packageId2); set.add(packageId3); - assertEquals(3, set.size()); + // Make sure that repeated calls return the same value + assertEquals(packageId1, mDbHelper.getPackageId("value1")); + } + + /** + * Test for {@link ContactsDatabaseHelper#getMimeTypeId(String)} + */ + public void testGetMimeTypeId() { // Test for getMimeTypeId. final long mimetypeId1 = mDbHelper.getMimeTypeId("value1"); final long mimetypeId2 = mDbHelper.getMimeTypeId("value2"); final long mimetypeId3 = mDbHelper.getMimeTypeId("value3"); // Make sure they're all different. + final HashSet<Long> set = new HashSet<>(); set.clear(); set.add(mimetypeId1); set.add(mimetypeId2); set.add(mimetypeId3); - assertEquals(3, set.size()); - // Call with the same values and make sure they return the cached value. - final long packageId1b = mDbHelper.getPackageId("value1"); - final long mimetypeId1b = mDbHelper.getMimeTypeId("value1"); - - assertEquals(packageId1, packageId1b); - assertEquals(mimetypeId1, mimetypeId1b); - - // Make sure the caches are also updated. - assertEquals(packageId2, (long) mDbHelper.mPackageCache.get("value2")); - assertEquals(mimetypeId2, (long) mDbHelper.mMimetypeCache.get("value2")); - - // Clear the cache, but they should still return the values, selecting from the database. - mDbHelper.mPackageCache.clear(); - mDbHelper.mMimetypeCache.clear(); - assertEquals(packageId1, mDbHelper.getPackageId("value1")); + // Make sure repeated calls return the same value assertEquals(mimetypeId1, mDbHelper.getMimeTypeId("value1")); + } + + /** + * Test for cache {@link ContactsDatabaseHelper#mCommonMimeTypeIdsCache} which stores ids for + * common mime types for faster access. + */ + public void testGetCommonMimeTypeIds() { + // getMimeTypeId should return the same value as the value stored in the cache + for (String commonMimeType : ContactsDatabaseHelper.COMMON_MIME_TYPES) { + assertEquals(mDbHelper.mCommonMimeTypeIdsCache.get(commonMimeType).longValue(), + mDbHelper.getMimeTypeId(commonMimeType)); + } - // Empty the table - mDb.execSQL("DELETE FROM " + Tables.MIMETYPES); + // The ids should be available even after deleting them from the table + mDb.execSQL("DELETE FROM " + Tables.MIMETYPES + ";"); - // We should still have the cached value. - assertEquals(mimetypeId1, mDbHelper.getMimeTypeId("value1")); + for (String commonMimeType : ContactsDatabaseHelper.COMMON_MIME_TYPES) { + assertEquals(mDbHelper.mCommonMimeTypeIdsCache.get(commonMimeType).longValue(), + mDbHelper.getMimeTypeId(commonMimeType)); + } } /** |