@Test public void parseJson_repeatingInterval_shouldReturnValidPositioning() throws Exception { MoPubNativeAdPositioning.MoPubClientPositioning positioning = subject.parseJson( "{repeating: {interval: 2}}"); assertThat(positioning.getFixedPositions()).isEmpty(); assertThat(positioning.getRepeatingInterval()).isEqualTo(2); }
@NonNull @VisibleForTesting MoPubClientPositioning parseJson(@NonNull String jsonString) throws JSONException, MoPubNetworkError { JSONObject jsonObject = new JSONObject(jsonString); String error = jsonObject.optString("error", null); if (error != null) { if (error.equalsIgnoreCase("WARMING_UP")) { throw new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); } throw new JSONException(error); } JSONArray fixed = jsonObject.optJSONArray(FIXED_KEY); JSONObject repeating = jsonObject.optJSONObject(REPEATING_KEY); if (fixed == null && repeating == null) { throw new JSONException("Must contain fixed or repeating positions"); } MoPubClientPositioning positioning = new MoPubClientPositioning(); if (fixed != null) { parseFixedJson(fixed, positioning); } if (repeating != null) { parseRepeatingJson(repeating, positioning); } return positioning; }
PositioningRequest extends JsonRequest<MoPubClientPositioning> { @NonNull @VisibleForTesting MoPubClientPositioning parseJson(@NonNull String jsonString) throws JSONException, MoPubNetworkError { JSONObject jsonObject = new JSONObject(jsonString); String error = jsonObject.optString("error", null); if (error != null) { if (error.equalsIgnoreCase("WARMING_UP")) { throw new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); } throw new JSONException(error); } JSONArray fixed = jsonObject.optJSONArray(FIXED_KEY); JSONObject repeating = jsonObject.optJSONObject(REPEATING_KEY); if (fixed == null && repeating == null) { throw new JSONException("Must contain fixed or repeating positions"); } MoPubClientPositioning positioning = new MoPubClientPositioning(); if (fixed != null) { parseFixedJson(fixed, positioning); } if (repeating != null) { parseRepeatingJson(repeating, positioning); } return positioning; } }
PositioningRequest extends JsonRequest<MoPubClientPositioning> { @NonNull @VisibleForTesting MoPubClientPositioning parseJson(@NonNull String jsonString) throws JSONException, MoPubNetworkError { JSONObject jsonObject = new JSONObject(jsonString); String error = jsonObject.optString("error", null); if (error != null) { if (error.equalsIgnoreCase("WARMING_UP")) { throw new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); } throw new JSONException(error); } JSONArray fixed = jsonObject.optJSONArray(FIXED_KEY); JSONObject repeating = jsonObject.optJSONObject(REPEATING_KEY); if (fixed == null && repeating == null) { throw new JSONException("Must contain fixed or repeating positions"); } MoPubClientPositioning positioning = new MoPubClientPositioning(); if (fixed != null) { parseFixedJson(fixed, positioning); } if (repeating != null) { parseRepeatingJson(repeating, positioning); } return positioning; } PositioningRequest(final String url,
            final Response.Listener<MoPubClientPositioning> listener,
            final Response.ErrorListener errorListener); }
PositioningRequest extends JsonRequest<MoPubClientPositioning> { @NonNull @VisibleForTesting MoPubClientPositioning parseJson(@NonNull String jsonString) throws JSONException, MoPubNetworkError { JSONObject jsonObject = new JSONObject(jsonString); String error = jsonObject.optString("error", null); if (error != null) { if (error.equalsIgnoreCase("WARMING_UP")) { throw new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); } throw new JSONException(error); } JSONArray fixed = jsonObject.optJSONArray(FIXED_KEY); JSONObject repeating = jsonObject.optJSONObject(REPEATING_KEY); if (fixed == null && repeating == null) { throw new JSONException("Must contain fixed or repeating positions"); } MoPubClientPositioning positioning = new MoPubClientPositioning(); if (fixed != null) { parseFixedJson(fixed, positioning); } if (repeating != null) { parseRepeatingJson(repeating, positioning); } return positioning; } PositioningRequest(final String url,
            final Response.Listener<MoPubClientPositioning> listener,
            final Response.ErrorListener errorListener);  }
PositioningRequest extends JsonRequest<MoPubClientPositioning> { @NonNull @VisibleForTesting MoPubClientPositioning parseJson(@NonNull String jsonString) throws JSONException, MoPubNetworkError { JSONObject jsonObject = new JSONObject(jsonString); String error = jsonObject.optString("error", null); if (error != null) { if (error.equalsIgnoreCase("WARMING_UP")) { throw new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP); } throw new JSONException(error); } JSONArray fixed = jsonObject.optJSONArray(FIXED_KEY); JSONObject repeating = jsonObject.optJSONObject(REPEATING_KEY); if (fixed == null && repeating == null) { throw new JSONException("Must contain fixed or repeating positions"); } MoPubClientPositioning positioning = new MoPubClientPositioning(); if (fixed != null) { parseFixedJson(fixed, positioning); } if (repeating != null) { parseRepeatingJson(repeating, positioning); } return positioning; } PositioningRequest(final String url,
            final Response.Listener<MoPubClientPositioning> listener,
            final Response.ErrorListener errorListener);   }