Monday, June 11, 2012

[android-developers] Calendar EditEventHelper test case

Hello,

I'm doing some Unit Test with Android Calendar application.
In the test code in EditEventHelperTest.java, lots of testSaveEvent*
encountered "java.lang.NullPointerException".
This comes from AsyncQueryService. startBatch(...).


public void startBatch(int token, Object cookie, String authority,
ArrayList<ContentProviderOperation> cpo, long delayMillis)
{
OperationInfo info = new OperationInfo();
info.op = Operation.EVENT_ARG_BATCH;
info.resolver = mContext.getContentResolver();
info.handler = mHandler;

getContentResolver() cause NULL pointer exception.

I found null resolver derived from wrong mContext. Not in test case
mContext type is EditEventActivity, but in test case the type is
MockAbsCalendarActivity.
MockAbsCalendarActivity in EditEventHelperTest.java is mock test
module and defines new startBatch for test module.

I changed EditEventHelper creator code like this

public EditEventHelper(Context context, CalendarEventModel model)
{
// mService = new AsyncQueryService(context);
mService =
((AbstractCalendarActivity)context).getAsyncQueryService();
}

This removes Null pointer exception and run test case with right
startBatch function.

Thanks

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate