use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method queryMapToOne.
@Test
public void queryMapToOne() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").mapToOne(Employee.MAPPER).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 mapToOneAllowsMapperNull.
@Test
public void mapToOneAllowsMapperNull() {
Func1<Cursor, Employee> mapToNull = new Func1<Cursor, Employee>() {
@Override
public Employee call(Cursor cursor) {
return null;
}
};
Employee employee = //
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(//
Query.mapToOne(mapToNull)).toBlocking().first();
assertThat(employee).isNull();
}
use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToListReturnsNullOnMapperNull.
@Test
public void mapToListReturnsNullOnMapperNull() {
Func1<Cursor, Employee> mapToNull = new Func1<Cursor, Employee>() {
private int count;
@Override
public Employee call(Cursor cursor) {
return count++ == 2 ? null : Employee.MAPPER.call(cursor);
}
};
List<Employee> employees = //
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).lift(//
Query.mapToList(mapToNull)).toBlocking().first();
assertThat(employees).containsExactly(new Employee("alice", "Alice Allison"), new Employee("bob", "Bob Bobberson"), null);
}
use of com.squareup.sqlbrite.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(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 mapToOneOrDefaultAllowsNullDefault.
@Test
public void mapToOneOrDefaultAllowsNullDefault() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " WHERE 1=2").lift(Query.mapToOneOrDefault(Employee.MAPPER, null)).toBlocking().first();
assertThat(employees).isNull();
}
Aggregations