BaggersListEntryView extends BaseRecyclerViewHolder<BaggersListEntry> { @OnClick(R.id.bagger_entry_invite_button) public void onInviteButtonClicked(Button button) { Context context = getContext(); String chooser = context.getString(R.string.baggers_list_contact_chooser_title); String subject = context.getString(R.string.baggers_list_contact_email_subject); IntentUtils.startEmailIntent(context, chooser, (String) button.getTag(), subject); } BaggersListEntryView(ViewGroup parent); @Override void bindData(@NonNull BaggersListEntry data); @OnClick(R.id.bagger_entry_invite_button) void onInviteButtonClicked(Button button);  }
@Test public void should_send_email_intent_when_clicking_on_button_to_contact_the_bagger() { Context c = RuntimeEnvironment.application; Button button = new Button(c); button.setTag("me@example.com"); view.onInviteButtonClicked(button); ShadowActivity shadowActivity = Shadows.shadowOf(Robolectric.setupActivity(Activity.class)); Intent intent = shadowActivity.getNextStartedActivity(); Intent mailExtra = intent.getParcelableExtra(Intent.EXTRA_INTENT); assertThat(intent.getStringExtra(Intent.EXTRA_TITLE)).isEqualTo(c.getString(R.string.baggers_list_contact_chooser_title)); assertThat(mailExtra.getData().getScheme()).isEqualTo("mailto"); assertThat(mailExtra.getStringExtra(Intent.EXTRA_SUBJECT)).isEqualTo(c.getString(R.string.baggers_list_contact_email_subject)); assertThat(mailExtra.getData().getSchemeSpecificPart()).isEqualTo("me@example.com"); }