use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testEqString.
public void testEqString() {
ArrayList<TestEntity> inserted = insert(3);
String value = getSimpleString(1);
List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.eq(value)).list();
assertEquals(1, result.size());
TestEntity resultEntity = result.get(0);
assertEquals(value, resultEntity.getSimpleString());
assertEquals(inserted.get(1).getId(), resultEntity.getId());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testNotEqString.
public void testNotEqString() {
ArrayList<TestEntity> inserted = insert(3);
String value = getSimpleString(1);
List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.notEq(value)).list();
assertEquals(2, result.size());
TestEntity resultEntity1 = result.get(0);
TestEntity resultEntity2 = result.get(1);
long loId = Math.min(resultEntity1.getId(), resultEntity2.getId());
long hiId = Math.max(resultEntity1.getId(), resultEntity2.getId());
assertEquals((long) inserted.get(0).getId(), loId);
assertEquals((long) inserted.get(2).getId(), hiId);
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testLike.
public void testLike() {
TestEntity entity = insert(3).get(1);
entity.setSimpleString("greenrobot");
dao.update(entity);
Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleString.like("%robot")).build();
TestEntity entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "green%");
entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "%enrob%");
entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "%nothere%");
entity2 = query.unique();
assertNull(entity2);
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryForThreadTest method testGetForCurrentThread_ManyThreadsDontLeak.
public void testGetForCurrentThread_ManyThreadsDontLeak() throws Exception {
if (VERSION.SDK_INT > VERSION_CODES.LOLLIPOP_MR1) {
DaoLog.i("testGetForCurrentThread_ManyThreadsDontLeak does not work on API level " + VERSION.SDK_INT);
return;
}
QueryBuilder<TestEntity> builder = dao.queryBuilder().where(Properties.SimpleInteger.eq("dummy"));
final Query<TestEntity> query = builder.build();
for (int i = 1; i <= LEAK_TEST_ITERATIONS; i++) {
Thread thread = new Thread() {
public void run() {
query.forCurrentThread();
}
};
thread.start();
if (i % 10 == 0) {
thread.join();
}
}
Field queryDataField = Query.class.getDeclaredField("queryData");
queryDataField.setAccessible(true);
Object queryData = queryDataField.get(query);
Class<?> dataSuperclass = queryData.getClass().getSuperclass();
Field mapField = dataSuperclass.getDeclaredField("queriesForThreads");
mapField.setAccessible(true);
Method gcMethod = dataSuperclass.getDeclaredMethod("gc");
gcMethod.setAccessible(true);
Map map = (Map) mapField.get(queryData);
for (int i = 0; map.size() > 1 && i < 1000; i++) {
DaoLog.d("Queries left after " + i + ". GC: " + map.size());
System.gc();
gcMethod.invoke(queryData);
}
assertEquals(1, map.size());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxDaoTest method testSaveInTx.
public void testSaveInTx() {
TestEntity foo = insertEntity("foo");
TestEntity bar = insertEntity("bar");
foo.setSimpleStringNotNull("foo2");
assertUpdatedEntities(foo, bar, rxDao.saveInTx(foo, bar));
}
Aggregations