Search in sources :

Example 11 with Query

use of com.squareup.sqlbrite.SqlBrite.Query in project sqlbrite by square.

the class QueryObservableTest method mapToListThrowsFromMapFunction.

@Test
public void mapToListThrowsFromMapFunction() {
    TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
    new QueryObservable(new OnSubscribe<Query>() {

        @Override
        public void call(Subscriber<? super Query> subscriber) {
            subscriber.onNext(new Query() {

                @Override
                public Cursor run() {
                    MatrixCursor cursor = new MatrixCursor(new String[] { "col1" });
                    cursor.addRow(new Object[] { "value1" });
                    return cursor;
                }
            });
        }
    }).mapToList(new Func1<Cursor, Object>() {

        @Override
        public Object call(Cursor cursor) {
            throw new IllegalStateException("test exception");
        }
    }).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoValues();
    assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    IllegalStateException expected = (IllegalStateException) testSubscriber.getOnErrorEvents().get(0);
    assertThat(expected).hasMessage("test exception");
}
Also used : Query(com.squareup.sqlbrite.SqlBrite.Query) TestSubscriber(rx.observers.TestSubscriber) Func1(rx.functions.Func1) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 12 with Query

use of com.squareup.sqlbrite.SqlBrite.Query in project sqlbrite by square.

the class QueryTest method mapToOneIgnoresNullCursor.

@Test
public void mapToOneIgnoresNullCursor() {
    Query nully = new Query() {

        @Nullable
        @Override
        public Cursor run() {
            return null;
        }
    };
    TestSubscriber<Employee> subscriber = new TestSubscriber<>();
    Observable.just(nully).lift(Query.mapToOne(Employee.MAPPER)).subscribe(subscriber);
    subscriber.assertNoValues();
    subscriber.assertCompleted();
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Query(com.squareup.sqlbrite.SqlBrite.Query) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Aggregations

Query (com.squareup.sqlbrite.SqlBrite.Query)12 Test (org.junit.Test)10 Cursor (android.database.Cursor)5 MatrixCursor (android.database.MatrixCursor)5 TestSubscriber (rx.observers.TestSubscriber)5 Func1 (rx.functions.Func1)3 Transaction (com.squareup.sqlbrite.BriteDatabase.Transaction)2 Employee (com.squareup.sqlbrite.TestDb.Employee)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ContentObserver (android.database.ContentObserver)1 CheckResult (android.support.annotation.CheckResult)1 NonNull (android.support.annotation.NonNull)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OnSubscribe (rx.Observable.OnSubscribe)1 Subscriber (rx.Subscriber)1 Action0 (rx.functions.Action0)1 Action1 (rx.functions.Action1)1 Func2 (rx.functions.Func2)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1