MoPubActivity extends BaseInterstitialActivity { @Override public View getAdView() { Intent intent = getIntent(); boolean isScrollable = intent.getBooleanExtra(SCROLLABLE_KEY, false); String redirectUrl = intent.getStringExtra(REDIRECT_URL_KEY); String clickthroughUrl = intent.getStringExtra(CLICKTHROUGH_URL_KEY); String htmlResponse = intent.getStringExtra(HTML_RESPONSE_BODY_KEY); mHtmlInterstitialWebView = HtmlInterstitialWebViewFactory.create(getApplicationContext(), new BroadcastingInterstitialListener(), isScrollable, redirectUrl, clickthroughUrl, getAdConfiguration()); mHtmlInterstitialWebView.loadHtmlResponse(htmlResponse); return mHtmlInterstitialWebView; }  static void start(Context context, String htmlData, boolean isScrollable, String redirectUrl, String clickthroughUrl, AdConfiguration adConfiguration); @Override View getAdView();  }
@Test public void getAdView_shouldReturnPopulatedHtmlWebView() throws Exception { View adView = subject.getAdView(); assertThat(adView).isSameAs(htmlInterstitialWebView); assertThat(TestHtmlInterstitialWebViewFactory.getLatestListener()).isNotNull(); assertThat(TestHtmlInterstitialWebViewFactory.getLatestIsScrollable()).isEqualTo(EXPECTED_IS_SCROLLABLE); assertThat(TestHtmlInterstitialWebViewFactory.getLatestClickthroughUrl()).isEqualTo(EXPECTED_CLICKTHROUGH_URL); assertThat(TestHtmlInterstitialWebViewFactory.getLatestRedirectUrl()).isEqualTo(EXPECTED_REDIRECT_URL); verify(htmlInterstitialWebView).loadHtmlResponse(EXPECTED_HTML_DATA); }
@Test public void getAdView_shouldCreateHtmlInterstitialWebViewAndLoadResponse() throws Exception { subject.getAdView(); assertThat(TestHtmlInterstitialWebViewFactory.getLatestListener()).isNotNull(); assertThat(TestHtmlInterstitialWebViewFactory.getLatestIsScrollable()).isEqualTo(EXPECTED_IS_SCROLLABLE); assertThat(TestHtmlInterstitialWebViewFactory.getLatestRedirectUrl()).isEqualTo(EXPECTED_REDIRECT_URL); assertThat(TestHtmlInterstitialWebViewFactory.getLatestClickthroughUrl()).isEqualTo(EXPECTED_CLICKTHROUGH_URL); verify(htmlInterstitialWebView).loadHtmlResponse(EXPECTED_HTML_DATA); }
@Test public void getAdView_shouldSetUpForBroadcastingClicks() throws Exception { subject.getAdView(); BroadcastReceiver broadcastReceiver = mock(BroadcastReceiver.class); ShadowLocalBroadcastManager.getInstance(subject).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter()); TestHtmlInterstitialWebViewFactory.getLatestListener().onInterstitialClicked(); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(broadcastReceiver).onReceive(any(Context.class), intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertThat(intent.getAction()).isEqualTo(ACTION_INTERSTITIAL_CLICK); }
@Test public void getAdView_shouldSetUpForBroadcastingFail() throws Exception { subject.getAdView(); BroadcastReceiver broadcastReceiver = mock(BroadcastReceiver.class); ShadowLocalBroadcastManager.getInstance(subject).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter()); TestHtmlInterstitialWebViewFactory.getLatestListener().onInterstitialFailed(UNSPECIFIED); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(broadcastReceiver).onReceive(any(Context.class), intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertThat(intent.getAction()).isEqualTo(ACTION_INTERSTITIAL_FAIL); assertThat(shadowOf(subject).isFinishing()).isTrue(); }