MraidBanner extends CustomEventBanner { @Override protected void loadBanner(@NonNull Context context, @NonNull CustomEventBannerListener customEventBannerListener, @NonNull Map<String, Object> localExtras, @NonNull Map<String, String> serverExtras) { mBannerListener = customEventBannerListener; String htmlData; if (extrasAreValid(serverExtras)) { htmlData = Uri.decode(serverExtras.get(HTML_RESPONSE_BODY_KEY)); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } AdConfiguration adConfiguration = AdConfiguration.extractFromMap(localExtras); if (htmlData == null || adConfiguration == null) { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } mMraidController = MraidControllerFactory.create( context, adConfiguration, PlacementType.INLINE); mMraidController.setDebugListener(mDebugListener); mMraidController.setMraidListener(new MraidListener() { @Override public void onLoaded(View view) { AdViewController.setShouldHonorServerDimensions(view); mBannerListener.onBannerLoaded(view); } @Override public void onFailedToLoad() { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); } @Override public void onExpand() { mBannerListener.onBannerExpanded(); mBannerListener.onBannerClicked(); } @Override public void onOpen() { mBannerListener.onBannerClicked(); } @Override public void onClose() { mBannerListener.onBannerCollapsed(); } }); mMraidController.loadContent(htmlData); }  @VisibleForTesting void setDebugListener(@Nullable MraidWebViewDebugListener debugListener);  }
@Test public void loadBanner_whenExtrasAreMalformed_shouldNotifyBannerListenerFailureAndReturn() { serverExtras.remove(HTML_RESPONSE_BODY_KEY); subject.loadBanner(context, mockBannerListener, localExtras, serverExtras); verify(mockBannerListener).onBannerFailed(eq(MRAID_LOAD_ERROR)); }
@Test public void loadBanner_whenAdConfigurationMissing_shouldNotifyBannerListenerFailureAndReturn() { localExtras.remove(AD_CONFIGURATION_KEY); subject.loadBanner(context, mockBannerListener, localExtras, serverExtras); verify(mockBannerListener).onBannerFailed(eq(MRAID_LOAD_ERROR)); }