@Test public void asJsonObject_withMalformedJsonString_shouldReturnNullAndCloseStream() throws Exception { String jsonData = "{whoops, forgot closing brace"; when(downloadResponse1.getByteArray()).thenReturn(jsonData.getBytes()); final JSONObject jsonObject = HttpResponses.asJsonObject(downloadResponse1); assertThat(jsonObject).isNull(); }
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);  }