Search in sources :

Example 6 with MockContentResolver

use of android.test.mock.MockContentResolver in project reark by reark.

the class GitHubRepositoryStoreCoreTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    setContext(InstrumentationRegistry.getTargetContext());
    final ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.authority = GitHubProvider.AUTHORITY;
    contentProvider = new GitHubProvider();
    contentProvider.attachInfo(InstrumentationRegistry.getTargetContext(), providerInfo);
    contentProvider.delete(GITHUB_REPOSITORIES, null, null);
    Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
    final MockContentResolver contentResolver = new MockContentResolver();
    contentResolver.addProvider(GitHubProvider.AUTHORITY, contentProvider);
    gitHubRepositoryStoreCore = new GitHubRepositoryStoreCore(contentResolver, new Gson());
    super.setUp();
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) GitHubProvider(io.reark.rxgithubapp.advanced.data.schematicProvider.generated.GitHubProvider) Gson(com.google.gson.Gson) MockContentResolver(android.test.mock.MockContentResolver) Before(org.junit.Before)

Example 7 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

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

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

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

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

the class TestContext method testAuthorityRenaming.

@MediumTest
public void testAuthorityRenaming() throws Exception {
    final Account account1 = new Account("acc1", "type1");
    final Account account2 = new Account("acc2", "type2");
    final String authorityContacts = "contacts";
    final String authorityCalendar = "calendar";
    final String authorityOther = "other";
    final String authorityContactsNew = "com.android.contacts";
    final String authorityCalendarNew = "com.android.calendar";
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<authority id=\"0\" account=\"acc1\" type=\"type1\" authority=\"contacts\" />\n" + "<authority id=\"1\" account=\"acc1\" type=\"type1\" authority=\"calendar\" />\n" + "<authority id=\"2\" account=\"acc1\" type=\"type1\" authority=\"other\" />\n" + "<authority id=\"3\" account=\"acc2\" type=\"type2\" authority=\"contacts\" />\n" + "<authority id=\"4\" account=\"acc2\" type=\"type2\" authority=\"calendar\" />\n" + "<authority id=\"5\" account=\"acc2\" type=\"type2\" authority=\"other\" />\n" + "<authority id=\"6\" account=\"acc2\" type=\"type2\" enabled=\"false\"" + " authority=\"com.android.calendar\" />\n" + "<authority id=\"7\" account=\"acc2\" type=\"type2\" enabled=\"false\"" + " authority=\"com.android.contacts\" />\n" + "</accounts>\n").getBytes();
    File syncDir = new File(new File(testContext.getFilesDir(), "system"), "sync");
    syncDir.mkdirs();
    AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    FileOutputStream fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
    assertEquals(false, engine.getSyncAutomatically(account1, 0, authorityContacts));
    assertEquals(false, engine.getSyncAutomatically(account1, 0, authorityCalendar));
    assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityOther));
    assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityContactsNew));
    assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityCalendarNew));
    assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityContacts));
    assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityCalendar));
    assertEquals(true, engine.getSyncAutomatically(account2, 0, authorityOther));
    assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityContactsNew));
    assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityCalendarNew));
}
Also used : Account(android.accounts.Account) AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 10 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

the class ProviderTestCase method setUp.

@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 delegated to
    new MockContext(), // The context that file methods are delegated to
    getInstrumentation().getTargetContext(), filenamePrefix);
    mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
    mProvider = ProviderTestCase2.createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority);
    mResolver.addProvider(mProviderAuthority, getProvider());
}
Also used : MockContext(android.test.mock.MockContext) 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