@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)); }
@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 = serverExtras.get(HTML_RESPONSE_BODY_KEY); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } try { AdReport adReport = (AdReport) localExtras.get(AD_REPORT_KEY); mMraidController = MraidControllerFactory.create( context, adReport, PlacementType.INLINE); } catch (ClassCastException e) { MoPubLog.w("MRAID banner creating failed:", e); mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } 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); }
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 = serverExtras.get(HTML_RESPONSE_BODY_KEY); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } try { AdReport adReport = (AdReport) localExtras.get(AD_REPORT_KEY); mMraidController = MraidControllerFactory.create( context, adReport, PlacementType.INLINE); } catch (ClassCastException e) { MoPubLog.w("MRAID banner creating failed:", e); mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } 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); } }
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 = serverExtras.get(HTML_RESPONSE_BODY_KEY); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } try { AdReport adReport = (AdReport) localExtras.get(AD_REPORT_KEY); mMraidController = MraidControllerFactory.create( context, adReport, PlacementType.INLINE); } catch (ClassCastException e) { MoPubLog.w("MRAID banner creating failed:", e); mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } 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); }  }
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 = serverExtras.get(HTML_RESPONSE_BODY_KEY); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } try { AdReport adReport = (AdReport) localExtras.get(AD_REPORT_KEY); mMraidController = MraidControllerFactory.create( context, adReport, PlacementType.INLINE); } catch (ClassCastException e) { MoPubLog.w("MRAID banner creating failed:", e); mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } 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); }
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 = serverExtras.get(HTML_RESPONSE_BODY_KEY); } else { mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } try { AdReport adReport = (AdReport) localExtras.get(AD_REPORT_KEY); mMraidController = MraidControllerFactory.create( context, adReport, PlacementType.INLINE); } catch (ClassCastException e) { MoPubLog.w("MRAID banner creating failed:", e); mBannerListener.onBannerFailed(MRAID_LOAD_ERROR); return; } 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);  }