Search in sources :

Example 31 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by crdroidandroid.

the class TestContext method createStorageTestContext.

/**
     * Returns a Context configured with test provider for authority.
     */
static Context createStorageTestContext(Context context, String authority) {
    final MockContentResolver testResolver = new MockContentResolver();
    TestContentProvider provider = new TestContentProvider();
    testResolver.addProvider(authority, provider);
    return new ContextWrapper(context) {

        @Override
        public ContentResolver getContentResolver() {
            return testResolver;
        }
    };
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) ContextWrapper(android.content.ContextWrapper)

Example 32 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by crdroidandroid.

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 33 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by crdroidandroid.

the class FakeSettingsProviderTest method setUp.

@Override
public void setUp() throws Exception {
    mCr = new MockContentResolver();
    mCr.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
}
Also used : MockContentResolver(android.test.mock.MockContentResolver)

Example 34 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by AOSPA.

the class TestContext method createStorageTestContext.

/**
     * Returns a Context configured with test provider for authority.
     */
static Context createStorageTestContext(Context context, String authority) {
    final MockContentResolver testResolver = new MockContentResolver();
    TestContentProvider provider = new TestContentProvider();
    testResolver.addProvider(authority, provider);
    return new ContextWrapper(context) {

        @Override
        public ContentResolver getContentResolver() {
            return testResolver;
        }
    };
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) ContextWrapper(android.content.ContextWrapper)

Example 35 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by AOSPA.

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)

Aggregations

MockContentResolver (android.test.mock.MockContentResolver)69 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 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Context (android.content.Context)11 ContextWrapper (android.content.ContextWrapper)10 Bundle (android.os.Bundle)7 ContentResolver (android.content.ContentResolver)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Before (org.junit.Before)5 ComponentName (android.content.ComponentName)4 PeriodicSync (android.content.PeriodicSync)3 IsolatedContext (android.test.IsolatedContext)3 ProviderInfo (android.content.pm.ProviderInfo)2 RenamingDelegatingContext (android.test.RenamingDelegatingContext)2 GitHubProvider (io.reark.rxgithubapp.advanced.data.schematicProvider.generated.GitHubProvider)2 ContentProvider (android.content.ContentProvider)1