use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesInTables_shouldReceiveIfTableWasChanged.
@Test
public void observeChangesInTables_shouldReceiveIfTableWasChanged() {
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
Set<String> tables = new HashSet<String>(2);
tables.add("table1");
tables.add("table2");
storIOSQLite.observeChangesInTables(tables, LATEST).subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes = Changes.newInstance("table2");
storIOSQLite.lowLevel().notifyAboutChanges(changes);
testSubscriber.assertValues(changes);
testSubscriber.assertNoErrors();
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class RxChangesObserverTest method shouldEmitChangesOnSdkVersionLowerThan16.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Test
public void shouldEmitChangesOnSdkVersionLowerThan16() {
for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < 16; sdkVersion++) {
ContentResolver contentResolver = mock(ContentResolver.class);
final Map<Uri, ContentObserver> contentObservers = new HashMap<Uri, ContentObserver>(3);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
contentObservers.put((Uri) invocation.getArguments()[0], (ContentObserver) invocation.getArguments()[2]);
return null;
}
}).when(contentResolver).registerContentObserver(any(Uri.class), eq(true), any(ContentObserver.class));
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
Uri uri1 = mock(Uri.class);
Uri uri2 = mock(Uri.class);
Set<Uri> uris = new HashSet<Uri>(2);
uris.add(uri1);
uris.add(uri2);
RxChangesObserver.observeChanges(contentResolver, uris, mock(Handler.class), sdkVersion, BackpressureStrategy.MISSING).subscribe(testSubscriber);
testSubscriber.assertNotTerminated();
testSubscriber.assertNoValues();
// Emulate change of Uris, Flowable should react and emit Changes objects
contentObservers.get(uri1).onChange(false);
contentObservers.get(uri2).onChange(false);
testSubscriber.assertValues(Changes.newInstance(uri1), Changes.newInstance(uri2));
testSubscriber.dispose();
testSubscriber.assertNoErrors();
}
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class GetOperationTest method getCursorExecuteAsBlocking.
@Test
public void getCursorExecuteAsBlocking() {
final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
TestItem testItemToInsert = TestItem.create(null, "value");
contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
Cursor cursor = storIOContentResolver.get().cursor().withQuery(Query.builder().uri(TestItem.CONTENT_URI).build()).prepare().executeAsBlocking();
Assertions.assertThat(cursor).hasCount(1);
cursor.moveToFirst();
assertThat(testItemToInsert.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
Aggregations