当前位置: 首页>>代码示例>>Java>>正文


Java ShadowContentResolver类代码示例

本文整理汇总了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)));
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:18,代码来源:AlarmContentObserverServiceTest.java

示例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());
    }
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:26,代码来源:AlarmContentObserverServiceTest.java

示例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();
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:24,代码来源:Assert.java

示例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));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:20,代码来源:ItemSyncAdapterTest.java

示例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());
}
 
开发者ID:jameskbride,项目名称:grocery-reminder,代码行数:18,代码来源:ReminderContentProviderTest.java

示例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());
}
 
开发者ID:jameskbride,项目名称:grocery-reminder,代码行数:18,代码来源:GroceryStoreLocationContentProviderTest.java

示例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();
}
 
开发者ID:TruckMuncher,项目名称:TruckMuncher-Android,代码行数:22,代码来源:MenuItemDiffServiceTest.java

示例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);
}
 
开发者ID:Longi94,项目名称:spicio,代码行数:14,代码来源:DatabaseProviderTest.java

示例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;
}
 
开发者ID:evant,项目名称:loadie,代码行数:11,代码来源:CursorLoaderTest.java

示例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);
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:9,代码来源:BacklogProviderTest.java

示例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));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:9,代码来源:ItemSyncAdapterTest.java

示例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
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:16,代码来源:ItemSyncAdapterTest.java

示例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));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:35,代码来源:FavoriteManagerTest.java

示例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));
}
 
开发者ID:jameskbride,项目名称:grocery-reminder,代码行数:11,代码来源:ReminderContentProviderTest.java

示例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));
}
 
开发者ID:jameskbride,项目名称:grocery-reminder,代码行数:12,代码来源:ReminderContentProviderTest.java


注:本文中的org.robolectric.shadows.ShadowContentResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。