use of com.activeandroid.query.From in project ActiveAndroid by pardom.
the class CountTest method testCountGroupBy.
/**
* Should return the total number of rows, even if the rows are grouped. May seem weird, just
* test it in an SQL explorer.
*/
public void testCountGroupBy() {
cleanTable();
populateTable();
From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 1");
final List<MockModel> list = from.execute();
final int count = from.count();
assertEquals(2, count);
assertEquals(1, list.size());
}
use of com.activeandroid.query.From in project ActiveAndroid by pardom.
the class CountTest method testCountEmptyResult.
/**
* Should return the same count as there are entries in the result set if the where-clause
* matches zero entries.
*/
public void testCountEmptyResult() {
cleanTable();
populateTable();
From from = new Select().from(MockModel.class).where("intField = ?", 3);
final List<MockModel> list = from.execute();
final int count = from.count();
assertEquals(0, count);
assertEquals(list.size(), count);
}
use of com.activeandroid.query.From in project ActiveAndroid by pardom.
the class ExistsTest method testCountGroupBy.
/**
* Should not change the result if group by is used.
*/
public void testCountGroupBy() {
cleanTable();
populateTable();
From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 1");
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertTrue(exists);
assertTrue(list.size() > 0);
}
use of com.activeandroid.query.From in project ActiveAndroid by pardom.
the class ExistsTest method testCountGroupByEmpty.
/**
* Should not exist if group by eliminates all rows.
*/
public void testCountGroupByEmpty() {
cleanTable();
populateTable();
From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 3");
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertFalse(exists);
assertFalse(list.size() > 0);
}
use of com.activeandroid.query.From in project ActiveAndroid by pardom.
the class ExistsTest method testExistsWhereClause.
/**
* Should return {@code true} since the where-clause matches rows and thus the result set isn't
* empty.
*/
public void testExistsWhereClause() {
cleanTable();
populateTable();
From from = new Select().from(MockModel.class).where("intField = ?", 1);
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertTrue(exists);
assertTrue(list.size() > 0);
}