Search in sources :

Example 1 with IsolatedContext

use of android.test.IsolatedContext in project Etar-Calendar by Etar-Group.

the class AlarmSchedulerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockProvider = new MockProvider();
    mMockAlarmManager = new MockAlarmManager(mContext);
    MockContentResolver mockResolver = new MockContentResolver();
    mockResolver.addProvider(CalendarContract.AUTHORITY, mMockProvider);
    mIsolatedContext = new IsolatedContext(mockResolver, mContext);
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) IsolatedContext(android.test.IsolatedContext)

Example 2 with IsolatedContext

use of android.test.IsolatedContext in project Etar-Calendar by Etar-Group.

the class AsyncQueryServiceTest method buildTestContext.

private Context buildTestContext(final OperationInfo[] work) {
    MockContext context = new MockContext() {

        MockContentResolver mResolver;

        @Override
        public ContentResolver getContentResolver() {
            if (mResolver == null) {
                mResolver = new MockContentResolver();
                final String filenamePrefix = "test.";
                RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(new MockContext2(), getContext(), filenamePrefix);
                IsolatedContext providerContext = new IsolatedContext(mResolver, targetContextWrapper);
                ContentProvider provider = new TestProvider(work);
                provider.attachInfo(providerContext, null);
                mResolver.addProvider(AUTHORITY, provider);
            }
            return mResolver;
        }

        @Override
        public String getPackageName() {
            return AsyncQueryServiceTest.class.getPackage().getName();
        }

        @Override
        public ComponentName startService(Intent service) {
            AsyncQueryServiceTest.this.startService(service);
            return service.getComponent();
        }
    };
    return context;
}
Also used : RenamingDelegatingContext(android.test.RenamingDelegatingContext) MockContext(android.test.mock.MockContext) ContentProvider(android.content.ContentProvider) Intent(android.content.Intent) MockContentResolver(android.test.mock.MockContentResolver) IsolatedContext(android.test.IsolatedContext)

Example 3 with IsolatedContext

use of android.test.IsolatedContext in project tray by grandcentrix.

the class TrayProviderHelperTest method testClearBut.

public void testClearBut() throws Exception {
    // We need a package name in this test, thus creating our own mock context
    final IsolatedContext context = getProviderMockContext();
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
    assertTrue(mProviderHelper.persist(MODULE_B, KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(MODULE_B, KEY_B, STRING_B));
    assertTrue(mProviderHelper.persist(MODULE_C, KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(MODULE_C, KEY_B, STRING_B));
    assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_B, STRING_B));
    assertUserDatabaseSize(8);
    mProviderHelper.clearBut(new AppPreferences(context), new TestTrayModulePreferences(context, MODULE_A), new TestTrayModulePreferences(context, MODULE_B));
    assertUserDatabaseSize(6);
    mProviderHelper.clearBut(new TestTrayModulePreferences(context, MODULE_A), new TestTrayModulePreferences(context, MODULE_B));
    assertUserDatabaseSize(4);
    mProviderHelper.clearBut(new TestTrayModulePreferences(context, MODULE_A));
    assertUserDatabaseSize(2);
    mProviderHelper.clearBut((TrayPreferences) null);
    assertUserDatabaseSize(0);
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
    assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_B, STRING_B));
    mProviderHelper.clearBut(new AppPreferences(context));
    assertUserDatabaseSize(2);
    // Also test empty values (= clear everything)
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
    mProviderHelper.clearBut((TrayPreferences) null);
    assertUserDatabaseSize(0);
}
Also used : TestTrayModulePreferences(net.grandcentrix.tray.mock.TestTrayModulePreferences) AppPreferences(net.grandcentrix.tray.AppPreferences) IsolatedContext(android.test.IsolatedContext)

Example 4 with IsolatedContext

use of android.test.IsolatedContext in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerServiceTest method setUp.

@Override
protected void setUp() throws Exception {
    final String filenamePrefix = "test.";
    MockContentResolver resolver = new MockContentResolver();
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
    new MyMockContext(), // The context that file methods are delegated to
    getContext(), filenamePrefix);
    Context context = new IsolatedContext(resolver, targetContextWrapper);
    setContext(context);
    mAms = new MyAccountManagerService(getContext(), new MyMockPackageManager(), new MockAccountAuthenticatorCache());
}
Also used : Context(android.content.Context) IsolatedContext(android.test.IsolatedContext) RenamingDelegatingContext(android.test.RenamingDelegatingContext) MockContext(android.test.mock.MockContext) RenamingDelegatingContext(android.test.RenamingDelegatingContext) MockContentResolver(android.test.mock.MockContentResolver) IsolatedContext(android.test.IsolatedContext)

Aggregations

IsolatedContext (android.test.IsolatedContext)4 MockContentResolver (android.test.mock.MockContentResolver)3 RenamingDelegatingContext (android.test.RenamingDelegatingContext)2 MockContext (android.test.mock.MockContext)2 ContentProvider (android.content.ContentProvider)1 Context (android.content.Context)1 Intent (android.content.Intent)1 AppPreferences (net.grandcentrix.tray.AppPreferences)1 TestTrayModulePreferences (net.grandcentrix.tray.mock.TestTrayModulePreferences)1