android - Unable to use MatrixCursor.newRow() in Robolectric -
i have contentprovider
attempting call matrixcursor.newrow()
. crashing nullpointerexception
in private method matrixcursor.ensurecapacity()
. debugging this, see matrixcursor.data
null (appears shadowmatrixcursor not instantiate in constructor).
i'm using latest robolectric jar, version 2.2.
@runwith(robolectrictestrunner.class) public class matrixcursortest { @test public void thiscrashesinnewrow() { matrixcursor c = new matrixcursor(new string[] { "test", "cols" }, 1); matrixcursor.rowbuilder b = c.newrow(); // crashes npe } }
i'm trying understand how can around this. i've tried creating "myshadowmatrixcursor" follows, don't see how can override behavior of newrow() return empty rowbuilder (whose constructor default/package-private, not accessible shadow.)
import android.database.matrixcursor; import android.database.matrixcursor.rowbuilder; import org.robolectric.annotation.implementation; import org.robolectric.annotation.implements; import org.robolectric.annotation.realobject; @implements(value = matrixcursor.class, inheritimplementationmethods = true) public class myshadowmatrixcursor extends org.robolectric.shadows.shadowmatrixcursor { @realobject private matrixcursor cursor; @implementation public rowbuilder newrow() { // causes infinite loop because shadow intercepts again: return cursor.newrow(); // doesn't work because rowbuilder constructor package-private ...return cursor.new rowbuilder() // how can return instance of matrixcursor.rowbuilder instead? } @implementation public void ensurecapacity(int i) { // override private ensurecapacity // nothing } }
so, questions code above:
how can return instance of matrixcursor.rowbuilder?
is possible shadow private method i'm attempting ensurecapacity() above? edit: yes, make "public" in shadow class.
pretty new robolectric, i'm overlooking?
edit: figured out how override private method making public in shadow class. however, i'm getting npes elsewhere state of matrixcursor doesn't appear set @ all?
erich suggested try robolectric 2.3-snapshot build, did , indeed fix issue. see https://groups.google.com/forum/#!topic/robolectric/i5z5n5nh4pw.
unrelated, 2 new issues occurring contentresolver.gettype() submitted patch here: https://github.com/robolectric/robolectric/pull/954 , still working on contentprovider.openfile().
Comments
Post a Comment