i am just developing an Android Application (API 15) and got the following Problem, when trying to write a unit test:
I use android.os.Parcel for saving a class (e.g. if the screen is turned around) and send it to another Activity. If i try to unit test the Parcel Method like this (i got this from the internet):
@Test
public void testParcel() {
Comment test = new Comment();
test.setId(testNr0Id);
test.setComment(testNr0String);
// Obtain a Parcel object and write the parcelable object to it:
Parcel parcel = Parcel.obtain();
test.writeToParcel(parcel, 0);
// After you're done with writing, you need to reset the parcel for reading:
parcel.setDataPosition(0);
// Reconstruct object from parcel and asserts:
Comment createdFromParcel = Comment.CREATOR.createFromParcel(parcel);
assertEquals(test, createdFromParcel);
}
then i get a NullPointerException, because the Parcel returned from Parcel.obtain() is null. The JavaDoc is just saying that this Method "returns an parcel Object from the pool". Now my question is: Which pool? And why is this Parcel-Object null? Any suggestions how to make this test run?
Thanks for your help
Michael