diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-02-22 21:07:50 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-02-23 17:38:40 -0800 |
commit | 0c832119d05dcfccbc52bcce841b306ccebc56e9 (patch) | |
tree | c1e19fd57d220a5fc79034daa753b239f009da45 /tests/src/com/android/dialer/database | |
parent | f7d748077c3ef424eab2c7740e6868ba6ad3e4b9 (diff) |
Adding tests for blockNumber
+ The ContactsCommon MockContentProvider now supports mocking the
insert method, added necessary tests.
+ Updating tests with changes to MockContentProvider
+ No longer need to call attachInfo on provider
+ Need to explicitly pass null for vararg query parameters when a
null values are expected.
Bug=26664600
Change-Id: I5316f8ee8bb442aa36d807781124a936f09e0a9c
Diffstat (limited to 'tests/src/com/android/dialer/database')
-rw-r--r-- | tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java | 77 |
1 files changed, 65 insertions, 12 deletions
diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java index fd60d731a..6bb478e2a 100644 --- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java +++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java @@ -16,16 +16,18 @@ package com.android.dialer.database; -import android.content.pm.ProviderInfo; +import android.content.ContentValues; import android.net.Uri; import android.test.InstrumentationTestCase; import android.test.mock.MockContentResolver; import com.android.contacts.common.test.mocks.MockContentProvider; import com.android.contacts.common.test.mocks.MockContentProvider.Query; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnBlockNumberListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; +import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; import java.util.concurrent.CountDownLatch; @@ -39,6 +41,7 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase private static final Integer ID = 1; private static final Uri BLOCKED_NUMBER_URI = Uri.withAppendedPath(FilteredNumberContract.AUTHORITY_URI, "filtered_numbers_table"); + private static final Uri EXPECTED_URI = Uri.fromParts("android", "google", "dialer"); private final MockContentResolver mContentResolver = new MockContentResolver(); private final MockContentProvider mContentProvider = new MockContentProvider(); @@ -46,16 +49,7 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase @Override public void setUp() throws Exception { super.setUp(); - setUpProviderForAuthority(mContentProvider, FilteredNumberContract.AUTHORITY, - mContentResolver); - } - - private void setUpProviderForAuthority(MockContentProvider provider, String authority, - MockContentResolver contentResolver) { - ProviderInfo providerInfo = new ProviderInfo(); - providerInfo.authority = authority; - provider.attachInfo(null, providerInfo); - contentResolver.addProvider(authority, provider); + mContentResolver.addProvider(FilteredNumberContract.AUTHORITY, mContentProvider); } public void testIsBlockedNumber_NoResults() throws Throwable { @@ -123,7 +117,51 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return mContentProvider.expectQuery(BLOCKED_NUMBER_URI).withProjection( FilteredNumberColumns._ID) .withSelection(FilteredNumberColumns.TYPE + "=" - + FilteredNumberTypes.BLOCKED_NUMBER); + + FilteredNumberTypes.BLOCKED_NUMBER, null); + } + + public void testBlockNumber() throws Throwable { + mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(), + EXPECTED_URI); + final BlockingArgumentCaptorOnBlockNumberListener listener = + new BlockingArgumentCaptorOnBlockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).blockNumber(listener, + E164_NUMBER, NUMBER, COUNTRY_ISO); + } + }); + assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)); + assertSame(EXPECTED_URI, listener.uri); + mContentProvider.verify(); + } + + public void testBlockNumber_NullNormalizedNumber() throws Throwable { + mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(), + EXPECTED_URI); + final BlockingArgumentCaptorOnBlockNumberListener listener = + new BlockingArgumentCaptorOnBlockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).blockNumber(listener, + NUMBER, COUNTRY_ISO); + } + }); + assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)); + assertSame(EXPECTED_URI, listener.uri); + mContentProvider.verify(); + } + + private ContentValues newBlockNumberContentValues() { + ContentValues contentValues = new ContentValues(); + contentValues.put(FilteredNumberColumns.NORMALIZED_NUMBER, E164_NUMBER); + contentValues.put(FilteredNumberColumns.NUMBER, NUMBER); + contentValues.put(FilteredNumberColumns.COUNTRY_ISO, COUNTRY_ISO); + contentValues.put(FilteredNumberColumns.TYPE, FilteredNumberTypes.BLOCKED_NUMBER); + contentValues.put(FilteredNumberColumns.SOURCE, FilteredNumberSources.USER); + return contentValues; } private class CheckBlockedListener implements OnCheckBlockedListener { @@ -169,4 +207,19 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return hasBlockedNumbers; } } + + private class BlockingArgumentCaptorOnBlockNumberListener implements OnBlockNumberListener { + public final CountDownLatch onBlockCompleteCalled; + public Uri uri; + + public BlockingArgumentCaptorOnBlockNumberListener() { + onBlockCompleteCalled = new CountDownLatch(1); + } + + @Override + public void onBlockComplete(Uri uri) { + this.uri = uri; + onBlockCompleteCalled.countDown(); + } + } } |