Search in sources :

Example 6 with Employee

use of com.squareup.sqlbrite3.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(MAPPER)).blockingFirst();
    // 
    assertThat(employees).containsExactly(// 
    new Employee("alice", "Alice Allison"), // 
    new Employee("bob", "Bob Bobberson"), new Employee("eve", "Eve Evenson"));
}
Also used : Employee(com.squareup.sqlbrite3.TestDb.Employee) Test(org.junit.Test)

Example 7 with Employee

use of com.squareup.sqlbrite3.TestDb.Employee 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());
}
Also used : Query(com.squareup.sqlbrite3.SqlBrite.Query) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress)

Example 8 with Employee

use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.

the class QueryTest method mapToOne.

@Test
public void mapToOne() {
    Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(Query.mapToOne(MAPPER)).blockingFirst();
    assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
}
Also used : Employee(com.squareup.sqlbrite3.TestDb.Employee) Test(org.junit.Test)

Example 9 with Employee

use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.

the class BriteDatabaseTest method queryMapToList.

@Test
public void queryMapToList() {
    List<Employee> employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).mapToList(Employee.MAPPER).blockingFirst();
    // 
    assertThat(employees).containsExactly(// 
    new Employee("alice", "Alice Allison"), // 
    new Employee("bob", "Bob Bobberson"), new Employee("eve", "Eve Evenson"));
}
Also used : Employee(com.squareup.sqlbrite3.TestDb.Employee) Test(org.junit.Test)

Example 10 with Employee

use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.

the class BriteDatabaseTest method synchronousQueryWithSupportSQLiteQueryDuringTransactionSeesChanges.

@Test
public void synchronousQueryWithSupportSQLiteQueryDuringTransactionSeesChanges() {
    Transaction transaction = db.newTransaction();
    try {
        assertCursor(db.query(new SimpleSQLiteQuery(SELECT_EMPLOYEES))).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
        db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
        db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
        assertCursor(db.query(new SimpleSQLiteQuery(SELECT_EMPLOYEES))).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
        transaction.markSuccessful();
    } finally {
        transaction.end();
    }
}
Also used : Transaction(com.squareup.sqlbrite3.BriteDatabase.Transaction) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 Transaction (com.squareup.sqlbrite3.BriteDatabase.Transaction)11 Employee (com.squareup.sqlbrite3.TestDb.Employee)10 Query (com.squareup.sqlbrite3.SqlBrite.Query)6 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)3 TestObserver (io.reactivex.observers.TestObserver)3 SdkSuppress (android.support.test.filters.SdkSuppress)2 TargetApi (android.annotation.TargetApi)1 Cursor (android.database.Cursor)1 Function (io.reactivex.functions.Function)1 Closeable (java.io.Closeable)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1