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);
}
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;
}
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);
}
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());
}
Aggregations