Skip to content

Instantly share code, notes, and snippets.

@catehstn
Created April 25, 2016 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catehstn/ac97f9bc5e23b91913b60d50b3067f01 to your computer and use it in GitHub Desktop.
Save catehstn/ac97f9bc5e23b91913b60d50b3067f01 to your computer and use it in GitHub Desktop.
@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