@Test public void onAdError_shouldNotifyListener() { subject.onAdError(new MoPubNetworkError(MoPubNetworkError.Reason.BAD_BODY)); verify(mockNetworkListener).onNativeFail(eq(NativeErrorCode.INVALID_JSON)); }
@VisibleForTesting void onAdError(@NonNull final VolleyError volleyError) { MoPubLog.d("Native ad request failed.", volleyError); if (volleyError instanceof MoPubNetworkError) { MoPubNetworkError error = (MoPubNetworkError) volleyError; switch (error.getReason()) { case BAD_BODY: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case BAD_HEADER_DATA: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case WARMING_UP: MoPubLog.c(MoPubErrorCode.WARMUP.toString()); mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case NO_FILL: mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case UNSPECIFIED: default: mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); return; } } else { NetworkResponse response = volleyError.networkResponse; if (response != null && response.statusCode >= 500 && response.statusCode < 600) { mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE); } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) { MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString())); mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR); } else { mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); } } }
MoPubNative { @VisibleForTesting void onAdError(@NonNull final VolleyError volleyError) { MoPubLog.d("Native ad request failed.", volleyError); if (volleyError instanceof MoPubNetworkError) { MoPubNetworkError error = (MoPubNetworkError) volleyError; switch (error.getReason()) { case BAD_BODY: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case BAD_HEADER_DATA: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case WARMING_UP: MoPubLog.c(MoPubErrorCode.WARMUP.toString()); mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case NO_FILL: mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case UNSPECIFIED: default: mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); return; } } else { NetworkResponse response = volleyError.networkResponse; if (response != null && response.statusCode >= 500 && response.statusCode < 600) { mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE); } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) { MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString())); mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR); } else { mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); } } } }
MoPubNative { @VisibleForTesting void onAdError(@NonNull final VolleyError volleyError) { MoPubLog.d("Native ad request failed.", volleyError); if (volleyError instanceof MoPubNetworkError) { MoPubNetworkError error = (MoPubNetworkError) volleyError; switch (error.getReason()) { case BAD_BODY: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case BAD_HEADER_DATA: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case WARMING_UP: MoPubLog.c(MoPubErrorCode.WARMUP.toString()); mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case NO_FILL: mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case UNSPECIFIED: default: mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); return; } } else { NetworkResponse response = volleyError.networkResponse; if (response != null && response.statusCode >= 500 && response.statusCode < 600) { mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE); } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) { MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString())); mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR); } else { mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); } } } @Deprecated  MoPubNative(@NonNull final Context context,
            @NonNull final String adUnitId,
            @NonNull final MoPubNativeListener moPubNativeListener);  MoPubNative(@NonNull final Context context,
                @NonNull final String adUnitId,
                @NonNull final MoPubNativeNetworkListener moPubNativeNetworkListener); }
MoPubNative { @VisibleForTesting void onAdError(@NonNull final VolleyError volleyError) { MoPubLog.d("Native ad request failed.", volleyError); if (volleyError instanceof MoPubNetworkError) { MoPubNetworkError error = (MoPubNetworkError) volleyError; switch (error.getReason()) { case BAD_BODY: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case BAD_HEADER_DATA: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case WARMING_UP: MoPubLog.c(MoPubErrorCode.WARMUP.toString()); mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case NO_FILL: mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case UNSPECIFIED: default: mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); return; } } else { NetworkResponse response = volleyError.networkResponse; if (response != null && response.statusCode >= 500 && response.statusCode < 600) { mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE); } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) { MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString())); mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR); } else { mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); } } } @Deprecated  MoPubNative(@NonNull final Context context,
            @NonNull final String adUnitId,
            @NonNull final MoPubNativeListener moPubNativeListener);  MoPubNative(@NonNull final Context context,
                @NonNull final String adUnitId,
                @NonNull final MoPubNativeNetworkListener moPubNativeNetworkListener); void setNativeEventListener(@Nullable final MoPubNativeEventListener nativeEventListener); void destroy(); void setLocalExtras(@Nullable final Map<String, Object> localExtras); void makeRequest(); void makeRequest(@Nullable final RequestParameters requestParameters); void makeRequest(@Nullable final RequestParameters requestParameters,
            @Nullable Integer sequenceNumber); }
MoPubNative { @VisibleForTesting void onAdError(@NonNull final VolleyError volleyError) { MoPubLog.d("Native ad request failed.", volleyError); if (volleyError instanceof MoPubNetworkError) { MoPubNetworkError error = (MoPubNetworkError) volleyError; switch (error.getReason()) { case BAD_BODY: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case BAD_HEADER_DATA: mMoPubNativeNetworkListener.onNativeFail(INVALID_JSON); return; case WARMING_UP: MoPubLog.c(MoPubErrorCode.WARMUP.toString()); mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case NO_FILL: mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE); return; case UNSPECIFIED: default: mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); return; } } else { NetworkResponse response = volleyError.networkResponse; if (response != null && response.statusCode >= 500 && response.statusCode < 600) { mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE); } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) { MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString())); mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR); } else { mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED); } } } @Deprecated  MoPubNative(@NonNull final Context context,
            @NonNull final String adUnitId,
            @NonNull final MoPubNativeListener moPubNativeListener);  MoPubNative(@NonNull final Context context,
                @NonNull final String adUnitId,
                @NonNull final MoPubNativeNetworkListener moPubNativeNetworkListener); void setNativeEventListener(@Nullable final MoPubNativeEventListener nativeEventListener); void destroy(); void setLocalExtras(@Nullable final Map<String, Object> localExtras); void makeRequest(); void makeRequest(@Nullable final RequestParameters requestParameters); void makeRequest(@Nullable final RequestParameters requestParameters,
            @Nullable Integer sequenceNumber);  }