### Question:
NusicWebViewActivity extends RoboActionBarActivity { @VisibleForTesting Intent createShareIntent() { return new Intent(Intent.ACTION_SEND) .setType("text/plain") .putExtra(Intent.EXTRA_SUBJECT, getExtraOrEmpty(EXTRA_SUBJECT)) .putExtra(Intent.EXTRA_TEXT, createShareText()); }  @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); static final String EXTRA_URL; static final String EXTRA_SUBJECT; }### Answer:
@Test public void createShareIntent() throws Exception { Intent intent = new Intent() .putExtra(NusicWebViewActivity.EXTRA_URL, expectedUrl) .putExtra(NusicWebViewActivity.EXTRA_SUBJECT, expectedSubject); NusicWebViewActivity activity = Robolectric.buildActivity(NusicWebViewActivity.class, intent).create().get(); Intent shareIntent = activity.createShareIntent(); Assert.assertEquals("subject", expectedSubject, shareIntent.getStringExtra(Intent.EXTRA_SUBJECT)); Assert.assertEquals("url", expectedUrl + "\n" + RuntimeEnvironment.application.getString(R.string.NusicWebViewActivity_sharedViaNusic), shareIntent.getStringExtra(Intent.EXTRA_TEXT)); }
@Test public void createShareIntentNoExtras() throws Exception { NusicWebViewActivity activity = Robolectric.setupActivity(NusicWebViewActivity.class); Intent shareIntent = activity.createShareIntent(); Assert.assertEquals("subject", "", shareIntent.getStringExtra(Intent.EXTRA_SUBJECT)); Assert.assertEquals("url", "", shareIntent.getStringExtra(Intent.EXTRA_TEXT)); }