use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesInTables.
@Test
public void observeChangesInTables() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).build();
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
Set<String> tables = new HashSet<String>(2);
tables.add("table1");
tables.add("table2");
storIOSQLite.observeChangesInTables(tables).subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes1 = Changes.newInstance("table1");
storIOSQLite.lowLevel().notifyAboutChanges(changes1);
testSubscriber.assertValue(changes1);
Changes changes2 = Changes.newInstance("table2");
storIOSQLite.lowLevel().notifyAboutChanges(changes2);
testSubscriber.assertValues(changes1, changes2);
Changes changes3 = Changes.newInstance("table3");
storIOSQLite.lowLevel().notifyAboutChanges(changes3);
// changes3 or any other changes are not expected here
testSubscriber.assertValues(changes1, changes2);
testSubscriber.assertNoErrors();
testSubscriber.unsubscribe();
}
use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesShouldThrowIfRxJavaNotInClassPath.
@Test
public void observeChangesShouldThrowIfRxJavaNotInClassPath() throws NoSuchFieldException, IllegalAccessException {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
DefaultStorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
//noinspection unchecked
ChangesBus<Changes> changesBus = mock(ChangesBus.class);
setChangesBus(storIOSQLite, changesBus);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(equalTo("Observing changes in StorIOSQLite requires RxJava"));
expectedException.expectCause(nullValue(Throwable.class));
storIOSQLite.observeChanges();
}
use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesInTable.
@Test
public void observeChangesInTable() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).build();
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChangesInTable("table1").subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes1 = Changes.newInstance("table2");
storIOSQLite.lowLevel().notifyAboutChanges(changes1);
testSubscriber.assertNoValues();
Changes changes2 = Changes.newInstance("table1");
storIOSQLite.lowLevel().notifyAboutChanges(changes2);
testSubscriber.assertValue(changes2);
Changes changes3 = Changes.newInstance("table3");
storIOSQLite.lowLevel().notifyAboutChanges(changes3);
// Subscriber should not see changes of table2 and table3
testSubscriber.assertValue(changes2);
testSubscriber.assertNoErrors();
testSubscriber.unsubscribe();
}
use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.
the class ObserveChangesTest method insertEmission.
@Test
public void insertEmission() {
final List<User> users = TestFactory.newUsers(10);
final Queue<Changes> expectedChanges = new LinkedList<Changes>();
expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE));
final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
final Subscription subscription = emissionChecker.subscribe();
putUsersBlocking(users);
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
subscription.unsubscribe();
}
use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.
the class ObserveChangesTest method deleteEmission.
@Test
public void deleteEmission() {
final List<User> users = putUsersBlocking(10);
final Queue<Changes> expectedChanges = new LinkedList<Changes>();
expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE));
final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
final Subscription subscription = emissionChecker.subscribe();
deleteUsersBlocking(users);
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
subscription.unsubscribe();
}
Aggregations