BaseInterstitialActivity extends Activity { protected AdConfiguration getAdConfiguration() { AdConfiguration adConfiguration; try { adConfiguration = (AdConfiguration) getIntent().getSerializableExtra(AD_CONFIGURATION_KEY); } catch (ClassCastException e) { adConfiguration = null; } return adConfiguration; }  abstract View getAdView();  }
@Test public void getAdConfiguration_shouldReturnAdConfigurationFromIntent() throws Exception { Context context = Robolectric.buildActivity(Activity.class).create().get(); Intent intent = new Intent(context, TestInterstitialActivity.class); intent.putExtra(AD_CONFIGURATION_KEY, adConfiguration); subject = Robolectric.buildActivity(TestInterstitialActivity.class) .withIntent(intent) .create().get(); assertThat(subject.getAdConfiguration()).isNotNull(); }
@Test public void getAdConfiguration_withMissingOrWrongAdConfiguration_shouldReturnNull() throws Exception { Context context = Robolectric.buildActivity(Activity.class).create().get(); Intent intent = new Intent(context, TestInterstitialActivity.class); subject = Robolectric.buildActivity(TestInterstitialActivity.class) .withIntent(intent) .create().get(); assertThat(subject.getAdConfiguration()).isNull(); }