I have a Fragment (support.v4 to be precise) that calls startActivityForResult and I want to test the request code it is called with.
The only way I can see to test this is by inspecting the parent shadow activity:
IntentForResult intentForResult = shadowActivity.getNextStartedActivityForResult();
assertEquals(requestCode, intentForResult.requestCode);
Unfortunately, the request codes used in fragments are not what the activity sees, so this results in not very nice reverse engineering:
int activityRequestCode = (fragmentIndex<<16) + (fragRequestCode&0xffff);
assertEquals(activityRequestCode , intentForResult.requestCode);
I thought that I could call
Robolectric.shadowOf(fragment).getNextStartedActivityForResult();
but unfortunately there isn't a ShadowFragment class in the
shadows.
So two answers I'm looking for:
- Am I missing some reason why there isn't an existing ShadowFragment class?
- Is there a better way for me to test this?
Thanks