Search in sources :

Example 11 with Changes

use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.

the class ObserveChangesTest method updateEmission.

@Test
public void updateEmission() {
    final List<User> users = putUsersBlocking(10);
    final List<User> updated = new ArrayList<User>(users.size());
    for (User user : users) {
        updated.add(User.newInstance(user.id(), user.email()));
    }
    final Queue<Changes> expectedChanges = new LinkedList<Changes>();
    expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE));
    final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
    final Subscription subscription = emissionChecker.subscribe();
    storIOSQLite.put().objects(updated).prepare().executeAsBlocking();
    // 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) ArrayList(java.util.ArrayList) Subscription(rx.Subscription) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 12 with Changes

use of com.pushtorefresh.storio.sqlite.Changes in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method observeChangesAndNotifyAboutChangesShouldWorkCorrectly.

@Test
public void observeChangesAndNotifyAboutChangesShouldWorkCorrectly() {
    SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
    TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
    storIOSQLite.observeChanges().subscribe(testSubscriber);
    testSubscriber.assertNoValues();
    Changes changes = Changes.newInstance("test_table");
    storIOSQLite.lowLevel().notifyAboutChanges(changes);
    testSubscriber.assertValue(changes);
    testSubscriber.assertNoErrors();
    testSubscriber.unsubscribe();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) Changes(com.pushtorefresh.storio.sqlite.Changes) TestSubscriber(rx.observers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) 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