use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method queryMapToOneOrDefault.
@Test
public void queryMapToOneOrDefault() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").mapToOneOrDefault(Employee.MAPPER, new Employee("wrong", "Wrong Person")).blockingFirst();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method nestedTransactionsOnMultipleTables.
@Test
public void nestedTransactionsOnMultipleTables() {
db.createQuery(BOTH_TABLES, SELECT_MANAGER_LIST).subscribe(o);
o.assertCursor().hasRow("Eve Evenson", "Alice Allison").isExhausted();
Transaction transactionOuter = db.newTransaction();
try {
Transaction transactionInner = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionInner = db.newTransaction();
try {
db.insert(TABLE_MANAGER, CONFLICT_NONE, manager(testDb.aliceId, testDb.bobId));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionOuter.markSuccessful();
} finally {
transactionOuter.end();
}
o.assertCursor().hasRow("Eve Evenson", "Alice Allison").hasRow("Alice Allison", "Bob Bobberson").isExhausted();
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class QueryTest method mapToOneIgnoresNullCursor.
@Test
public void mapToOneIgnoresNullCursor() {
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestObserver<Employee> observer = new TestObserver<>();
Observable.just(nully).lift(Query.mapToOne(MAPPER)).subscribe(observer);
observer.assertNoValues();
observer.assertComplete();
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method transactionDoesNotThrow.
@Test
public void transactionDoesNotThrow() {
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"));
transaction.markSuccessful();
} finally {
// Transactions should not throw on close().
transaction.close();
}
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 BriteDatabaseTest method transactionIsCloseable.
@Test
public void transactionIsCloseable() throws IOException {
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();
// noinspection UnnecessaryLocalVariable
// Verify type is implemented.
Closeable closeableTransaction = transaction;
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
transaction.markSuccessful();
} finally {
closeableTransaction.close();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
Aggregations