use of com.squareup.sqlbrite.TestDb.Employee 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;
}
};
TestSubscriber<Employee> subscriber = new TestSubscriber<>();
Observable.just(nully).lift(Query.mapToOneOrDefault(Employee.MAPPER, defaultEmployee)).subscribe(subscriber);
subscriber.assertValues(defaultEmployee);
subscriber.assertCompleted();
}
use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToList.
@Test
public void mapToList() {
List<Employee> employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).lift(Query.mapToList(Employee.MAPPER)).toBlocking().first();
//
assertThat(employees).containsExactly(//
new Employee("alice", "Alice Allison"), //
new Employee("bob", "Bob Bobberson"), new Employee("eve", "Eve Evenson"));
}
use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method queryMapToOneOrDefault.
@Test
public void queryMapToOneOrDefault() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").mapToOneOrDefault(Employee.MAPPER, null).toBlocking().first();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
}
use of com.squareup.sqlbrite.TestDb.Employee 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();
}
use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToOneOrDefaultReturnsDefaultAndDoesNotReRequestWhenNoRows.
@Test
public void mapToOneOrDefaultReturnsDefaultAndDoesNotReRequestWhenNoRows() {
final List<Long> requests = new ArrayList<>();
Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
List<Employee> employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " WHERE 1=2").take(1).doOnRequest(new Action1<Long>() {
@Override
public void call(Long n) {
requests.add(n);
}
}).lift(Query.mapToOneOrDefault(Employee.MAPPER, defaultEmployee)).toList().toBlocking().first();
assertThat(employees).containsExactly(defaultEmployee);
assertThat(requests).containsExactly(Long.MAX_VALUE);
}
Aggregations