use of com.squareup.sqlbrite3.SqlBrite.Query in project sqlbrite by square.
the class QueryTest method mapToOneOrDefaultReturnsDefaultWhenNullCursor.
@Test
public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestObserver<Employee> observer = new TestObserver<>();
Observable.just(nully).lift(Query.mapToOneOrDefault(MAPPER, defaultEmployee)).subscribe(observer);
observer.assertValues(defaultEmployee);
observer.assertComplete();
}
use of com.squareup.sqlbrite3.SqlBrite.Query in project sqlbrite by square.
the class QueryTest method mapToListIgnoresNullCursor.
@Test
public void mapToListIgnoresNullCursor() {
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestObserver<List<Employee>> subscriber = new TestObserver<>();
Observable.just(nully).lift(Query.mapToList(MAPPER)).subscribe(subscriber);
subscriber.assertNoValues();
subscriber.assertComplete();
}
use of com.squareup.sqlbrite3.SqlBrite.Query in project sqlbrite by square.
the class QueryTest method mapToOptionalIgnoresNullCursor.
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
@Test
public void mapToOptionalIgnoresNullCursor() {
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
Observable.just(nully).lift(Query.mapToOptional(MAPPER)).test().assertValue(Optional.<Employee>empty());
}
use of com.squareup.sqlbrite3.SqlBrite.Query in project sqlbrite by square.
the class SqlBriteTest method asRowsStopsWhenUnsubscribed.
@Test
public void asRowsStopsWhenUnsubscribed() {
MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES);
cursor.addRow(new Object[] { "Alice", "Allison" });
cursor.addRow(new Object[] { "Bob", "Bobberson" });
Query query = new CursorQuery(cursor);
final AtomicInteger count = new AtomicInteger();
query.asRows(new Function<Cursor, Name>() {
@Override
public Name apply(Cursor cursor) throws Exception {
count.incrementAndGet();
return Name.MAP.apply(cursor);
}
}).take(1).blockingFirst();
assertThat(count.get()).isEqualTo(1);
}
use of com.squareup.sqlbrite3.SqlBrite.Query in project sqlbrite by square.
the class SqlBriteTest method asRowsEmpty.
@Test
public void asRowsEmpty() {
MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES);
Query query = new CursorQuery(cursor);
List<Name> names = query.asRows(Name.MAP).toList().blockingGet();
assertThat(names).isEmpty();
}
Aggregations