use of com.squareup.sqlbrite.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(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 mapToOneOrDefaultAllowsMapperNull.
@Test
public void mapToOneOrDefaultAllowsMapperNull() {
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.mapToOneOrDefault(mapToNull, new Employee("bob", "Bob Bobberson"))).toBlocking().first();
assertThat(employee).isNull();
}
use of com.squareup.sqlbrite.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method nonExclusiveTransactionWorks.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void nonExclusiveTransactionWorks() throws InterruptedException {
final CountDownLatch transactionStarted = new CountDownLatch(1);
final CountDownLatch transactionProceed = new CountDownLatch(1);
final CountDownLatch transactionCompleted = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
Transaction transaction = db.newNonExclusiveTransaction();
transactionStarted.countDown();
try {
db.insert(TABLE_EMPLOYEE, employee("hans", "Hans Hanson"));
transactionProceed.await(10, SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Exception in transaction thread", e);
}
transaction.markSuccessful();
transaction.close();
transactionCompleted.countDown();
}
}.start();
assertThat(transactionStarted.await(10, SECONDS)).isTrue();
//Simple query
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(Query.mapToOne(Employee.MAPPER)).toBlocking().first();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
transactionProceed.countDown();
assertThat(transactionCompleted.await(10, SECONDS)).isTrue();
}
use of com.squareup.sqlbrite.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).toBlocking().first();
//
assertThat(employees).containsExactly(//
new Employee("alice", "Alice Allison"), //
new Employee("bob", "Bob Bobberson"), new Employee("eve", "Eve Evenson"));
}
Aggregations