Search in sources :

Example 1 with Employee

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"));
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Test(org.junit.Test)

Example 2 with Employee

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();
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Func1(rx.functions.Func1) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 3 with Employee

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);
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Func1(rx.functions.Func1) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 4 with Employee

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"));
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Test(org.junit.Test)

Example 5 with Employee

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();
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Test(org.junit.Test)

Aggregations

Employee (com.squareup.sqlbrite.TestDb.Employee)14 Test (org.junit.Test)14 Cursor (android.database.Cursor)3 Func1 (rx.functions.Func1)3 Query (com.squareup.sqlbrite.SqlBrite.Query)2 TestSubscriber (rx.observers.TestSubscriber)2 TargetApi (android.annotation.TargetApi)1 SdkSuppress (android.support.test.filters.SdkSuppress)1 Transaction (com.squareup.sqlbrite.BriteDatabase.Transaction)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1