greenrobot/greenDAO — Issue #22: AbstractDAO.loadAll crashes when testing with Robolectric
Author: kiefermat
Created: 2012-02-13 17:05:53+00:00
State: open

I am trying to test a project that uses greenDAO with Robolectric (http://pivotal.github.com/robolectric/). However, when calling loadAll on a generated DAO class, loadAll crashes with a NullPointerException.

The reason for this is that the method protected List loadAllFromCursor(Cursor cursor) in class AbstractDAO is assuming the CursorWindow of a CrossProcessCursor to be always not null. When adding a null pointer check to this method, the loadAll method works fine also with Robolectric.

E.g. do something like this.
if (cursor instanceof CrossProcessCursor) {
CursorWindow window = ((CrossProcessCursor) cursor).getWindow();
if (window != null) {
if(window.getNumRows() == count) {
cursor = new FastCursor(window);
} else {
DaoLog.d("Window vs. result size: " + window.getNumRows() + "/" + count);
}
}
}

If necessary, I can provide you a test project.