use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.
the class ProviderTestCase method newResolverWithContentProviderFromSql.
public static <T extends ContentProvider> ContentResolver newResolverWithContentProviderFromSql(Context targetContext, Class<T> providerClass, String authority, String databaseName, int databaseVersion, String sql) throws IllegalAccessException, InstantiationException {
final String filenamePrefix = "test.";
MockContentResolver resolver = new MockContentResolver();
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
new MockContext(), // The context that file methods are delegated to
targetContext, filenamePrefix);
Context context = new IsolatedContext(resolver, targetContextWrapper);
DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql);
T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority);
resolver.addProvider(authority, provider);
return resolver;
}
use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.
the class ProviderTestCase2 method setUp.
/**
* Sets up the environment for the test fixture.
* <p>
* Creates a new
* {@link android.test.mock.MockContentResolver}, a new IsolatedContext
* that isolates the provider's file operations, and a new instance of
* the provider under test within the isolated environment.
* </p>
*
* @throws Exception
*/
@Override
protected void setUp() throws Exception {
super.setUp();
mResolver = new MockContentResolver();
final String filenamePrefix = "test.";
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are
new MockContext2(), // The context that file methods are delegated to
getContext(), filenamePrefix);
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
mProvider = createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority);
mResolver.addProvider(mProviderAuthority, getProvider());
}
use of android.test.mock.MockContentResolver in project android_frameworks_base by crdroidandroid.
the class ModelTest method setupTestContext.
private void setupTestContext() {
final MockContentResolver resolver = new MockContentResolver();
context = new ContextWrapper(getContext()) {
@Override
public ContentResolver getContentResolver() {
return resolver;
}
};
provider = new TestContentProvider();
resolver.addProvider(AUTHORITY, provider);
}
use of android.test.mock.MockContentResolver in project android_packages_apps_Dialer by MoKee.
the class FilteredNumberAsyncQueryHandlerTest method testUnblockNumber_Disabled.
public void testUnblockNumber_Disabled() throws Throwable {
if (!CompatUtils.isNCompatible()) {
return;
}
FilteredNumberCompat.setIsEnabledForTest(false);
final MockContentResolver resolver = new MockContentResolver();
MockContentProvider disabledProvider = new MockContentProvider();
resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider);
Uri uriWithId = ContentUris.withAppendedId(BLOCKED_NUMBER_URI_M, ID);
disabledProvider.expectQuery(uriWithId).withProjection(null).withDefaultProjection(FilteredNumberCompat.getIdColumnName()).withSelection(null, null).withSortOrder(null).returnRow(ID);
disabledProvider.expectDelete(uriWithId).returnRowsAffected(1);
final UnblockNumberListener listener = new UnblockNumberListener();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
new FilteredNumberAsyncQueryHandler(resolver).unblock(listener, ID);
}
});
assertNotNull(listener.waitForCallback());
disabledProvider.verify();
}
use of android.test.mock.MockContentResolver in project android_packages_apps_Dialer by MoKee.
the class FilteredNumberAsyncQueryHandlerTest method testHasBlockedNumbers_Disabled.
public void testHasBlockedNumbers_Disabled() throws Throwable {
if (!CompatUtils.isNCompatible()) {
return;
}
FilteredNumberCompat.setIsEnabledForTest(false);
final MockContentResolver resolver = new MockContentResolver();
MockContentProvider disabledProvider = new MockContentProvider();
resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider);
disabledProvider.expectQuery(BLOCKED_NUMBER_URI_M).withProjection(FilteredNumberColumns._ID).withSelection(FilteredNumberColumns.TYPE + "=" + FilteredNumberTypes.BLOCKED_NUMBER, null).returnRow(ID);
final HasBlockedNumbersListener listener = new HasBlockedNumbersListener();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
new FilteredNumberAsyncQueryHandler(resolver).hasBlockedNumbers(listener);
}
});
assertTrue(listener.waitForCallback());
disabledProvider.verify();
}
Aggregations