Search in sources :

Example 1 with Changes

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();
}
Also used : Changes(com.pushtorefresh.storio.sqlite.Changes) TestSubscriber(rx.observers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Changes

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();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) Changes(com.pushtorefresh.storio.sqlite.Changes) Test(org.junit.Test)

Example 3 with Changes

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();
}
Also used : Changes(com.pushtorefresh.storio.sqlite.Changes) TestSubscriber(rx.observers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 4 with Changes

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();
}
Also used : Changes(com.pushtorefresh.storio.sqlite.Changes) AbstractEmissionChecker(com.pushtorefresh.storio.test.AbstractEmissionChecker) Subscription(rx.Subscription) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with Changes

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();
}
Also used : Changes(com.pushtorefresh.storio.sqlite.Changes) AbstractEmissionChecker(com.pushtorefresh.storio.test.AbstractEmissionChecker) Subscription(rx.Subscription) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Changes (com.pushtorefresh.storio.sqlite.Changes)12 Test (org.junit.Test)12 TestSubscriber (rx.observers.TestSubscriber)8 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AbstractEmissionChecker (com.pushtorefresh.storio.test.AbstractEmissionChecker)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Subscription (rx.Subscription)3 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)2 ArrayList (java.util.ArrayList)2