diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-06 10:54:00 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-03-12 15:08:34 -0800 |
commit | 13825f0533ec175928406f5e9b79c54305e8c5b0 (patch) | |
tree | 2aa2cfc8ec4fee9f2c6eff4988bbb6c7890dc906 /tests/src/com/android | |
parent | f93604f330b592f6e572ce7631f779f1f05de731 (diff) |
Adding sharedPref for blocked number migration
+ Users are shown a dialog when they're running on an SDK which
supports the framework blocking solution, but they haven't yet
migrated. In order to determine whether the user has migrated or not,
a SharedPreference value is used. In a later CL which performs the
migration, this value will be updated as the final step.
Bug: 26664600
Change-Id: I5a12be643d0fb3b52ef408215779423bf0a2ddc7
Diffstat (limited to 'tests/src/com/android')
-rw-r--r-- | tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java index b9eb21424..a57e1c29c 100644 --- a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java +++ b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java @@ -16,19 +16,30 @@ package com.android.dialer.compat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + import android.content.ContentUris; import android.content.ContentValues; +import android.content.Context; +import android.content.SharedPreferences; import android.net.Uri; import android.provider.BlockedNumberContract.BlockedNumbers; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import com.android.contacts.common.compat.CompatUtils; +import com.android.dialer.DialerApplication; import com.android.dialer.database.FilteredNumberContract.FilteredNumber; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + import java.util.Arrays; @SmallTest @@ -41,27 +52,52 @@ public class FilteredNumberCompatTest extends AndroidTestCase { private static final Uri EXPECTED_BASE_URI = CompatUtils.isNCompatible() ? BlockedNumbers.CONTENT_URI : FilteredNumber.CONTENT_URI; + @Mock private Context mContext; + @Mock private SharedPreferences mSharedPreferences; + @Override public void setUp() throws Exception { super.setUp(); + MockitoAnnotations.initMocks(this); + DialerApplication.setContextForTest(mContext); + when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mSharedPreferences); FilteredNumberCompat.setIsEnabledForTest(true); } public void testIsNewFilteringEnabled_TestValueFalse() { FilteredNumberCompat.setIsEnabledForTest(false); - assertFalse(FilteredNumberCompat.useNewFiltering()); + assertFalse(FilteredNumberCompat.canUseNewFiltering()); } public void testIsNewFilteringEnabled_TestValueTrue() { FilteredNumberCompat.setIsEnabledForTest(true); - assertEquals(CompatUtils.isNCompatible(), FilteredNumberCompat.useNewFiltering()); + assertEquals(CompatUtils.isNCompatible(), FilteredNumberCompat.canUseNewFiltering()); + } + + public void testHasMigratedToNewBlocking_False() { + assertFalse(FilteredNumberCompat.hasMigratedToNewBlocking()); + } + + public void testHasMigratedToNewBlocking_Migrated() { + when(mSharedPreferences + .getBoolean(FilteredNumberCompat.HAS_MIGRATED_TO_NEW_BLOCKING_KEY, false)) + .thenReturn(true); + assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); } public void testGetContentUri_NullId() { - assertEquals(EXPECTED_BASE_URI, FilteredNumberCompat.getContentUri(null)); + assertEquals(FilteredNumber.CONTENT_URI, FilteredNumberCompat.getContentUri(null)); } - public void testGetContentUri() { + public void testGetContentUri_NotMigrated() { + assertEquals(ContentUris.withAppendedId(FilteredNumber.CONTENT_URI, 1), + FilteredNumberCompat.getContentUri(1)); + } + + public void testGetContentUri_Migrated() { + when(mSharedPreferences + .getBoolean(FilteredNumberCompat.HAS_MIGRATED_TO_NEW_BLOCKING_KEY, false)) + .thenReturn(true); assertEquals(ContentUris.withAppendedId(EXPECTED_BASE_URI, 1), FilteredNumberCompat.getContentUri(1)); } @@ -87,12 +123,23 @@ public class FilteredNumberCompatTest extends AndroidTestCase { } catch (NullPointerException e) {} } - public void testNewBlockNumberContentValues_N() { + public void testNewBlockNumberContentValues_N_NotMigrated() { + if (!CompatUtils.isNCompatible()) { + return; + } + assertEquals(newExpectedContentValuesM(NON_E164_NUMBER, null, null), + FilteredNumberCompat.newBlockNumberContentValues(NON_E164_NUMBER, null, null)); + } + + public void testNewBlockNumberContentValues_N_Migrated() { if (!CompatUtils.isNCompatible()) { return; } ContentValues contentValues = new ContentValues(); contentValues.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, NON_E164_NUMBER); + when(mSharedPreferences + .getBoolean(FilteredNumberCompat.HAS_MIGRATED_TO_NEW_BLOCKING_KEY, false)) + .thenReturn(true); assertEquals(contentValues, FilteredNumberCompat.newBlockNumberContentValues( NON_E164_NUMBER, null, null)); |