Search in sources :

Example 26 with MockContentResolver

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

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

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

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)

Example 28 with MockContentResolver

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

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

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

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

use of android.test.mock.MockContentResolver in project boxing by Bilibili.

the class PickerPresenterTest method setupMockAndViews.

@Before
public void setupMockAndViews() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(BoxingManager.class);
    PowerMockito.mockStatic(TextUtils.class);
    PowerMockito.when(BoxingManager.getInstance()).thenReturn(mPickerManager);
    mPresenter = new PickerPresenter(mView);
    MockContentResolver contentResolver = new MockContentResolver();
    Mockito.when(mView.getAppCr()).thenReturn(contentResolver);
    PowerMockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            CharSequence charSequence = (CharSequence) invocation.getArguments()[0];
            return !(charSequence != null && charSequence.length() > 0);
        }
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) PickerPresenter(com.bilibili.boxing.presenter.PickerPresenter) MockContentResolver(android.test.mock.MockContentResolver) Before(org.junit.Before)

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