Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Test
public void testTapGalleryButtonAndReturnOK() {
// Stub the Uri returned by the gallery intent.
Uri uri = Uri.parse("uri_string");
// Build a result to return when the activity is launched.
Intent resultData = new Intent();
resultData.setData(uri);
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Set up result stubbing when an intent sent to "choose photo" is seen.
intending(toPackage("com.android.gallery")).respondWith(result);
onView(withId(R.id.home_gallery_button)).check(matches(withText("Gallery")));
onView(withId(R.id.home_gallery_button)).perform(click());
// Check image processor is reset.
verify(imageProcessor).resetOriginalImage();
// New activity should be launched
intended(hasComponent(ImageEditingActivity.class.getName()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment