@Test public void loadNativeAd_withNullResponseBody_shouldNotifyListenerOfOnNativeAdFailed() throws Exception { localExtras.remove(DataKeys.JSON_BODY_KEY); subject.loadNativeAd(context, mCustomEventNativeListener, localExtras, serverExtras); verify(mCustomEventNativeListener, never()).onNativeAdLoaded(any(MoPubCustomEventNative.MoPubForwardingNativeAd.class)); verify(mCustomEventNativeListener).onNativeAdFailed(NativeErrorCode.INVALID_JSON); }
@Override protected void loadNativeAd(@NonNull final Context context, @NonNull final CustomEventNativeListener customEventNativeListener, @NonNull final Map<String, Object> localExtras, @NonNull final Map<String, String> serverExtras) { Object json = localExtras.get(JSON_BODY_KEY); if (!(json instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_JSON); return; } final MoPubForwardingNativeAd moPubForwardingNativeAd = new MoPubForwardingNativeAd(context.getApplicationContext(), (JSONObject) json, customEventNativeListener); try { moPubForwardingNativeAd.loadAd(); } catch (IllegalArgumentException e) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } }
MoPubCustomEventNative extends CustomEventNative { @Override protected void loadNativeAd(@NonNull final Context context, @NonNull final CustomEventNativeListener customEventNativeListener, @NonNull final Map<String, Object> localExtras, @NonNull final Map<String, String> serverExtras) { Object json = localExtras.get(JSON_BODY_KEY); if (!(json instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_JSON); return; } final MoPubForwardingNativeAd moPubForwardingNativeAd = new MoPubForwardingNativeAd(context.getApplicationContext(), (JSONObject) json, customEventNativeListener); try { moPubForwardingNativeAd.loadAd(); } catch (IllegalArgumentException e) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } } }
MoPubCustomEventNative extends CustomEventNative { @Override protected void loadNativeAd(@NonNull final Context context, @NonNull final CustomEventNativeListener customEventNativeListener, @NonNull final Map<String, Object> localExtras, @NonNull final Map<String, String> serverExtras) { Object json = localExtras.get(JSON_BODY_KEY); if (!(json instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_JSON); return; } final MoPubForwardingNativeAd moPubForwardingNativeAd = new MoPubForwardingNativeAd(context.getApplicationContext(), (JSONObject) json, customEventNativeListener); try { moPubForwardingNativeAd.loadAd(); } catch (IllegalArgumentException e) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } }  }
MoPubCustomEventNative extends CustomEventNative { @Override protected void loadNativeAd(@NonNull final Context context, @NonNull final CustomEventNativeListener customEventNativeListener, @NonNull final Map<String, Object> localExtras, @NonNull final Map<String, String> serverExtras) { Object json = localExtras.get(JSON_BODY_KEY); if (!(json instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_JSON); return; } final MoPubForwardingNativeAd moPubForwardingNativeAd = new MoPubForwardingNativeAd(context.getApplicationContext(), (JSONObject) json, customEventNativeListener); try { moPubForwardingNativeAd.loadAd(); } catch (IllegalArgumentException e) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } }   }
MoPubCustomEventNative extends CustomEventNative { @Override protected void loadNativeAd(@NonNull final Context context, @NonNull final CustomEventNativeListener customEventNativeListener, @NonNull final Map<String, Object> localExtras, @NonNull final Map<String, String> serverExtras) { Object json = localExtras.get(JSON_BODY_KEY); if (!(json instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_JSON); return; } final MoPubForwardingNativeAd moPubForwardingNativeAd = new MoPubForwardingNativeAd(context.getApplicationContext(), (JSONObject) json, customEventNativeListener); try { moPubForwardingNativeAd.loadAd(); } catch (IllegalArgumentException e) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } }    }