use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method transactionOnlyNotifiesOnce.
@Test
public void transactionOnlyNotifiesOnce() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
o.assertNoMoreEvents();
transaction.markSuccessful();
} finally {
transaction.end();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of com.squareup.sqlbrite3.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;
}
};
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.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToListReturnsNullOnMapperNull.
@Test
public void mapToListReturnsNullOnMapperNull() {
Function<Cursor, Employee> mapToNull = new Function<Cursor, Employee>() {
private int count;
@Override
public Employee apply(Cursor cursor) throws Exception {
return count++ == 2 ? null : MAPPER.apply(cursor);
}
};
List<Employee> employees = //
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).lift(//
Query.mapToList(mapToNull)).blockingFirst();
assertThat(employees).containsExactly(new Employee("alice", "Alice Allison"), new Employee("bob", "Bob Bobberson"), null);
}
use of com.squareup.sqlbrite3.TestDb.Employee 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.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToOneOrDefault.
@Test
public void mapToOneOrDefault() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(Query.mapToOneOrDefault(MAPPER, new Employee("fred", "Fred Frederson"))).blockingFirst();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
}
Aggregations