Search in sources :

Example 71 with MockContentResolver

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;
}
Also used : Context(android.content.Context) MockContext(android.test.mock.MockContext) MockContext(android.test.mock.MockContext) MockContentResolver(android.test.mock.MockContentResolver)

Example 72 with MockContentResolver

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());
}
Also used : MockContentResolver(android.test.mock.MockContentResolver)

Example 73 with MockContentResolver

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);
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) ContextWrapper(android.content.ContextWrapper) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver)

Example 74 with MockContentResolver

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();
}
Also used : MockContentProvider(com.android.contacts.common.test.mocks.MockContentProvider) MockContentResolver(android.test.mock.MockContentResolver) OnUnblockNumberListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnUnblockNumberListener) Uri(android.net.Uri)

Example 75 with MockContentResolver

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();
}
Also used : MockContentProvider(com.android.contacts.common.test.mocks.MockContentProvider) OnHasBlockedNumbersListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener) MockContentResolver(android.test.mock.MockContentResolver)

Aggregations

MockContentResolver (android.test.mock.MockContentResolver)79 Account (android.accounts.Account)22 MockContext (android.test.mock.MockContext)17 AtomicFile (com.android.internal.os.AtomicFile)16 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)16 Context (android.content.Context)13 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 ContextWrapper (android.content.ContextWrapper)10 Bundle (android.os.Bundle)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 ComponentName (android.content.ComponentName)4 MockContentProvider (com.android.contacts.common.test.mocks.MockContentProvider)4 PeriodicSync (android.content.PeriodicSync)3 ProviderInfo (android.content.pm.ProviderInfo)3 IsolatedContext (android.test.IsolatedContext)3 Uri (android.net.Uri)2 RemoteException (android.os.RemoteException)2