@Test public void asJsonObject_withShallowJsonString_shouldReturnPopulatedJsonObjectAndCloseStream() throws Exception { String jsonData = "{\"key1\":\"value1\",\"key2\":\"2\",\"key3\":\"null\"}"; when(downloadResponse1.getByteArray()).thenReturn(jsonData.getBytes()); JSONObject expectedJsonObject = new JSONObject(); expectedJsonObject.put("key1", "value1"); expectedJsonObject.put("key2", 2); expectedJsonObject.put("key3", JSONObject.NULL); final JSONObject actualJsonObject = HttpResponses.asJsonObject(downloadResponse1); assertThat(actualJsonObject).isEqualsToByComparingFields(expectedJsonObject); }
public static JSONObject asJsonObject(final DownloadResponse downloadResponse) { if (downloadResponse == null) { return null; } try { final String responseString = asResponseString(downloadResponse); final JSONTokener tokener = new JSONTokener(responseString); return new JSONObject(tokener); } catch (Exception e) { return null; } }
HttpResponses { public static JSONObject asJsonObject(final DownloadResponse downloadResponse) { if (downloadResponse == null) { return null; } try { final String responseString = asResponseString(downloadResponse); final JSONTokener tokener = new JSONTokener(responseString); return new JSONObject(tokener); } catch (Exception e) { return null; } } }
HttpResponses { public static JSONObject asJsonObject(final DownloadResponse downloadResponse) { if (downloadResponse == null) { return null; } try { final String responseString = asResponseString(downloadResponse); final JSONTokener tokener = new JSONTokener(responseString); return new JSONObject(tokener); } catch (Exception e) { return null; } } private  HttpResponses(); }
HttpResponses { public static JSONObject asJsonObject(final DownloadResponse downloadResponse) { if (downloadResponse == null) { return null; } try { final String responseString = asResponseString(downloadResponse); final JSONTokener tokener = new JSONTokener(responseString); return new JSONObject(tokener); } catch (Exception e) { return null; } } private  HttpResponses(); static Bitmap asBitmap(final DownloadResponse downloadResponse); static JSONObject asJsonObject(final DownloadResponse downloadResponse); static String asResponseString(final DownloadResponse downloadResponse); }
HttpResponses { public static JSONObject asJsonObject(final DownloadResponse downloadResponse) { if (downloadResponse == null) { return null; } try { final String responseString = asResponseString(downloadResponse); final JSONTokener tokener = new JSONTokener(responseString); return new JSONObject(tokener); } catch (Exception e) { return null; } } private  HttpResponses(); static Bitmap asBitmap(final DownloadResponse downloadResponse); static JSONObject asJsonObject(final DownloadResponse downloadResponse); static String asResponseString(final DownloadResponse downloadResponse);  }