AdViewController { @VisibleForTesting @NonNull static MoPubErrorCode getErrorCodeFromVolleyError(@NonNull final VolleyError error, @Nullable final Context context) { final NetworkResponse networkResponse = error.networkResponse; if (error instanceof MoPubNetworkError) { switch (((MoPubNetworkError) error).getReason()) { case WARMING_UP: return MoPubErrorCode.WARMUP; case NO_FILL: return MoPubErrorCode.NO_FILL; default: return MoPubErrorCode.UNSPECIFIED; } } if (networkResponse == null) { if (!DeviceUtils.isNetworkAvailable(context)) { return MoPubErrorCode.NO_CONNECTION; } return MoPubErrorCode.UNSPECIFIED; } if (error.networkResponse.statusCode >= 400) { return MoPubErrorCode.SERVER_ERROR; } return MoPubErrorCode.UNSPECIFIED; } AdViewController(@NonNull Context context, @NonNull MoPubView view); static void setShouldHonorServerDimensions(View view); @Nullable MoPubView getMoPubView(); void loadAd(); void reload(); String getKeywords(); void setKeywords(String keywords); Location getLocation(); void setLocation(Location location); String getAdUnitId(); void setAdUnitId(@NonNull String adUnitId); long getBroadcastIdentifier(); void setTimeout(int milliseconds); int getAdWidth(); int getAdHeight(); @Deprecated String getClickTrackingUrl(); @Deprecated String getRedirectUrl(); @Deprecated String getResponseString(); boolean getAutorefreshEnabled(); @Nullable AdReport getAdReport(); boolean getTesting(); void setTesting(boolean enabled); @Deprecated void customEventDidLoadAd(); @Deprecated void customEventDidFailToLoadAd(); @Deprecated void customEventActionWillBegin(); @Deprecated void setClickthroughUrl(String clickthroughUrl); @Deprecated boolean isFacebookSupported(); @Deprecated void setFacebookSupported(boolean enabled);  }
@Test public void getErrorCodeFromVolleyError_whenNoConnection_shouldReturnErrorCodeNoConnection() { final VolleyError noConnectionError = new NoConnectionError(); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( noConnectionError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.NO_CONNECTION); }
@Test public void getErrorCodeFromVolleyError_withNullResponse_whenConnectionValid_shouldReturnErrorCodeUnspecified() { final VolleyError noConnectionError = new NoConnectionError(); shadowOf(activity).grantPermissions(Manifest.permission.INTERNET); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( noConnectionError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.UNSPECIFIED); }
@Test public void getErrorCodeFromVolleyError_withInvalidServerResponse_shouldReturnErrorCodeServerError() { for (int htmlErrorCode : HTML_ERROR_CODES) { final NetworkResponse errorNetworkResponse = new NetworkResponse(htmlErrorCode, null, null, true, 0); final VolleyError volleyError = new VolleyError(errorNetworkResponse); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( volleyError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.SERVER_ERROR); } }
@Test public void getErrorCodeFromVolleyError_withErrorReasonWarmingUp_shouldReturnErrorCodeWarmingUp() { final VolleyError networkError = new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( networkError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.WARMUP); }
@Test public void getErrorCodeFromVolleyError_withErrorReasonNoFill_shouldReturnErrorCodeNoFill() { final VolleyError networkError = new MoPubNetworkError(MoPubNetworkError.Reason.NO_FILL); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( networkError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.NO_FILL); }
@Test public void getErrorCodeFromVolleyError_withErrorReasonBadHeaderData_shouldReturnErrorCodeUnspecified() { final VolleyError networkError = new MoPubNetworkError( MoPubNetworkError.Reason.BAD_HEADER_DATA); final MoPubErrorCode errorCode = AdViewController.getErrorCodeFromVolleyError( networkError, activity); assertThat(errorCode).isEqualTo(MoPubErrorCode.UNSPECIFIED); }