本文整理汇总了Java中org.robolectric.shadows.ShadowContentResolver类的典型用法代码示例。如果您正苦于以下问题:Java ShadowContentResolver类的具体用法?Java ShadowContentResolver怎么用?Java ShadowContentResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShadowContentResolver类属于org.robolectric.shadows包,在下文中一共展示了ShadowContentResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testObserversRegistered
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void testObserversRegistered() {
Uri uri = Uri.parse("doist.com");
ShadowContentResolver contentResolver = shadowOf(context.getContentResolver());
assertEquals(0, contentResolver.getContentObservers(uri).size());
jobStore.add(JobStatus.createFromJobInfo(
JobCreator.create(context, 0)
.addTriggerContentUri(new JobInfo.TriggerContentUri(uri, 0))
.build(),
AlarmScheduler.TAG));
service.startCommand(0, 0);
assertEquals(1, contentResolver.getContentObservers(uri).size());
assertThat(contentResolver.getContentObservers(uri), hasItem(isA(ContentObserverService.Observer.class)));
}
示例2: testObserversFire
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void testObserversFire() {
Uri[] uris = new Uri[]{Uri.parse("doist.com"), Uri.parse("todoist.com"), Uri.parse("twistapp.com")};
for (int i = 0; i < uris.length; i++) {
jobStore.add(JobStatus.createFromJobInfo(
JobCreator.create(context, i, 5000)
.addTriggerContentUri(new JobInfo.TriggerContentUri(uris[i], 0))
.build(),
AlarmScheduler.TAG));
}
service.startCommand(0, 0);
ShadowApplication application = ShadowApplication.getInstance();
ShadowContentResolver contentResolver = shadowOf(context.getContentResolver());
for (Uri uri : uris) {
assertEquals(0, application.getBoundServiceConnections().size());
assertEquals(1, contentResolver.getContentObservers(uri).size());
contentResolver.notifyChange(uri, null);
DeviceTestUtils.advanceTime(JobStatus.DEFAULT_TRIGGER_MAX_DELAY);
assertEquals(1, contentResolver.getContentObservers(uri).size());
assertEquals(AlarmJobService.class.getCanonicalName(),
application.getNextStartedService().getComponent().getClassName());
}
}
示例3: assertIsInstalledVersionInDb
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
public static void assertIsInstalledVersionInDb(ShadowContentResolver resolver,
String appId, int versionCode, String versionName) {
Uri uri = InstalledAppProvider.getAppUri(appId);
String[] projection = {
InstalledAppTable.Cols.Package.NAME,
InstalledAppTable.Cols.VERSION_CODE,
InstalledAppTable.Cols.VERSION_NAME,
InstalledAppTable.Cols.APPLICATION_LABEL,
};
Cursor cursor = resolver.query(uri, projection, null, null, null);
assertNotNull(cursor);
assertEquals("App \"" + appId + "\" not installed", 1, cursor.getCount());
cursor.moveToFirst();
assertEquals(appId, cursor.getString(cursor.getColumnIndex(InstalledAppTable.Cols.Package.NAME)));
assertEquals(versionCode, cursor.getInt(cursor.getColumnIndex(InstalledAppTable.Cols.VERSION_CODE)));
assertEquals(versionName, cursor.getString(cursor.getColumnIndex(InstalledAppTable.Cols.VERSION_NAME)));
cursor.close();
}
示例4: testWifiChange
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void testWifiChange() {
setNetworkType(ConnectivityManager.TYPE_MOBILE);
new ItemSyncWifiReceiver()
.onReceive(service, new Intent(ConnectivityManager.CONNECTIVITY_ACTION));
assertFalse(ShadowContentResolver.isSyncActive(createSyncAccount(),
MaterialisticProvider.PROVIDER_AUTHORITY));
setNetworkType(ConnectivityManager.TYPE_WIFI);
new ItemSyncWifiReceiver().onReceive(service, new Intent());
assertFalse(ShadowContentResolver.isSyncActive(createSyncAccount(),
MaterialisticProvider.PROVIDER_AUTHORITY));
setNetworkType(ConnectivityManager.TYPE_WIFI);
new ItemSyncWifiReceiver()
.onReceive(service, new Intent(ConnectivityManager.CONNECTIVITY_ACTION));
assertTrue(ShadowContentResolver.isSyncActive(createSyncAccount(),
MaterialisticProvider.PROVIDER_AUTHORITY));
}
示例5: whenNoRemindersAreDeletedThenNoObserversAreNotified
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void whenNoRemindersAreDeletedThenNoObserversAreNotified() {
String testDescription = "test";
ContentValues values = new ReminderValuesBuilder().createDefaultReminderValues().withDescription(testDescription).build();
ShadowContentResolver contentResolver = Shadows.shadowOf(provider.getContext().getContentResolver());
provider.insert(ReminderContract.Reminders.CONTENT_URI, values);
List<ShadowContentResolver.NotifiedUri> notifiedUriList = contentResolver.getNotifiedUris();
assertEquals(1, notifiedUriList.size());
String selection = ReminderContract.Reminders.DESCRIPTION + " = ? ";
String[] selectionArgs = new String[] {"wrong name"};
provider.delete(ReminderContract.Reminders.CONTENT_URI, selection, selectionArgs);
notifiedUriList = contentResolver.getNotifiedUris();
assertEquals(1, notifiedUriList.size());
}
示例6: whenNoLocationsAreDeletedThenNoObserversAreNotified
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void whenNoLocationsAreDeletedThenNoObserversAreNotified() {
String testName = "test";
ContentValues values = locationValuesBuilder.createDefaultLocationValues().withName(testName).build();
ShadowContentResolver contentResolver = Shadows.shadowOf(provider.getContext().getContentResolver());
provider.insert(ReminderContract.Locations.CONTENT_URI, values);
List<ShadowContentResolver.NotifiedUri> notifiedUriList = contentResolver.getNotifiedUris();
assertEquals(1, notifiedUriList.size());
String selection = ReminderContract.Locations.NAME + " = ? ";
String[] selectionArgs = new String[] {"wrong name"};
provider.delete(ReminderContract.Locations.CONTENT_URI, selection, selectionArgs);
notifiedUriList = contentResolver.getNotifiedUris();
assertEquals(1, notifiedUriList.size());
}
示例7: onHandleIntentPerformsBulkInsertWithSyncToNetworkDirective
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void onHandleIntentPerformsBulkInsertWithSyncToNetworkDirective() {
VerifiableContentProvider provider = new VerifiableContentProvider();
ShadowContentResolver.registerProvider(PublicContract.CONTENT_AUTHORITY, provider);
provider.enqueue(new VerifiableContentProvider.ApplyBatchEvent() {
@NonNull
@Override
public ContentProviderResult[] onApplyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
assertThat(operations).hasSize(1);
assertThat(Contract.isSyncToNetwork(operations.get(0).getUri())).isTrue();
return new ContentProviderResult[0];
}
});
Intent intent = MenuItemDiffService.newIntent(Robolectric.application, new ContentValues[]{new ContentValues()});
MenuItemDiffService service = new MenuItemDiffService();
service.onHandleIntent(intent);
provider.assertThatCursorsAreClosed();
provider.assertThatQueuesAreEmpty();
}
示例8: setUp
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mProvider = new DatabaseProvider();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
ShadowContentResolver.registerProvider(DatabaseContract.CONTENT_AUTHORITY, mProvider);
mProvider.onCreate();
mShadowContentResolver = Shadows.shadowOf(mContentResolver);
deleteAllRecords(SeriesEntry.CONTENT_URI);
deleteAllRecords(EpisodesEntry.CONTENT_URI);
deleteAllRecords(FeedEntry.CONTENT_URI);
deleteAllRecords(FriendsEntry.CONTENT_URI);
}
示例9: setup
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Before
public void setup() {
background = ShadowApplication.getInstance().getBackgroundThreadScheduler();
resolver = RuntimeEnvironment.application.getContentResolver();
ShadowContentResolver shadowResolver = shadowOf(resolver);
MyRoboCursor cursor = new MyRoboCursor();
cursor.setNotificationUri(resolver, CONTENT_URI);
shadowResolver.setCursor(CONTENT_URI, cursor);
this.cursor = cursor;
}
示例10: setUp
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Before
public void setUp() {
final BacklogProvider backlogProvider = new BacklogProvider();
final ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
this.shadowContentResolver = Shadows.shadowOf(contentResolver);
backlogProvider.onCreate();
ShadowContentResolver.registerProvider(CONTENT_AUTHORITY, backlogProvider);
}
示例11: testSyncDisabled
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void testSyncDisabled() {
PreferenceManager.getDefaultSharedPreferences(service)
.edit().clear().apply();
syncScheduler.scheduleSync(service, "1");
assertNull(ShadowContentResolver.getStatus(createSyncAccount(),
MaterialisticProvider.PROVIDER_AUTHORITY));
}
示例12: testSyncDeferred
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void testSyncDeferred() throws IOException {
Call<HackerNewsItem> call = mock(Call.class);
when(call.execute()).thenThrow(IOException.class);
when(TestRestServiceFactory.hnRestService.cachedItem(any())).thenReturn(call);
when(TestRestServiceFactory.hnRestService.networkItem(any())).thenReturn(call);
syncPreferences.edit().putBoolean("1", true).putBoolean("2", true).apply();
syncScheduler.scheduleSync(service, null);
adapter.onPerformSync(mock(Account.class), getLastSyncExtras(), null, null, null);
ShadowContentResolver.Status syncStatus = ShadowContentResolver.getStatus(
new Account("Materialistic", BuildConfig.APPLICATION_ID),
MaterialisticProvider.PROVIDER_AUTHORITY);
assertThat(syncStatus.syncRequests).isEqualTo(3); // original + 2 deferred
}
示例13: testAdd
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Config(sdk = 18)
@Test
public void testAdd() {
PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application)
.edit()
.putBoolean(RuntimeEnvironment.application
.getString(R.string.pref_saved_item_sync), true)
.putBoolean(RuntimeEnvironment.application
.getString(R.string.pref_offline_article), true)
.apply();
shadowOf((ConnectivityManager) RuntimeEnvironment.application
.getSystemService(Context.CONNECTIVITY_SERVICE))
.setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null,
ConnectivityManager.TYPE_WIFI, 0, true, true));
manager.add(RuntimeEnvironment.application, new TestWebItem() {
@Override
public String getId() {
return "3";
}
@Override
public String getUrl() {
return "http://newitem.com";
}
@Override
public String getDisplayedTitle() {
return "new title";
}
});
assertThat(resolver.getNotifiedUris()).isNotEmpty();
assertTrue(ShadowContentResolver.isSyncActive(new Account("Materialistic", BuildConfig.APPLICATION_ID),
MaterialisticProvider.PROVIDER_AUTHORITY));
}
示例14: givenAReminderContentTypeAndContentValuesWhenARecordIsInsertedThenObserversAreNotified
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void givenAReminderContentTypeAndContentValuesWhenARecordIsInsertedThenObserversAreNotified()
{
ContentValues values = createDefaultReminderValues();
ShadowContentResolver contentResolver = Shadows.shadowOf(provider.getContext().getContentResolver());
Uri expectedUri = provider.insert(ReminderContract.Reminders.CONTENT_URI, values);
List<ShadowContentResolver.NotifiedUri> notifiedUriList = contentResolver.getNotifiedUris();
assertThat(notifiedUriList.get(0).uri, is(expectedUri));
}
示例15: whenAReminderIsDeletedThenObserversAreNotified
import org.robolectric.shadows.ShadowContentResolver; //导入依赖的package包/类
@Test
public void whenAReminderIsDeletedThenObserversAreNotified() {
ContentValues values = createDefaultReminderValues();
Uri expectedUri = provider.insert(ReminderContract.Reminders.CONTENT_URI, values);
ShadowContentResolver contentResolver = Shadows.shadowOf(provider.getContext().getContentResolver());
provider.delete(expectedUri, "", null);
List<ShadowContentResolver.NotifiedUri> notifiedUriList = contentResolver.getNotifiedUris();
assertThat(notifiedUriList.get(1).uri, is(expectedUri));
}