responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1);
@Test public void testFailure_cannotReadStream() throws Exception { InputStream stream = Mockito.mock(InputStream.class); when(stream.read(isA(byte[].class))).thenThrow(new IOException()); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(400, stream, AdHocReportDownloadHelper.REPORT_CHARSET, DownloadFormat.CSV.name()); try { downloadReport(DownloadFormat.CSV, rawResponse, null); fail("Should have thrown an exception"); } catch (ReportDownloadResponseException e) { assertEquals(400, e.getHttpStatus()); } }
@Test public void testFailure_cannotReadStream() throws Exception { InputStream stream = Mockito.mock(InputStream.class); when(stream.read(isA(byte[].class))).thenThrow(new IOException()); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(400, stream, AdHocReportDownloadHelper.REPORT_CHARSET, DownloadFormat.CSV.name()); try { downloadReport(DownloadFormat.CSV, rawResponse, null); fail("Should have thrown an exception"); } catch (ReportDownloadResponseException e) { assertEquals(400, e.getHttpStatus()); } }
@Test public void testFailure_cannotReadStream() throws Exception { InputStream stream = Mockito.mock(InputStream.class); when(stream.read(isA(byte[].class))).thenThrow(new IOException()); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(400, stream, AdHocReportDownloadHelper.REPORT_CHARSET, DownloadFormat.CSV.name()); try { downloadReport(DownloadFormat.CSV, rawResponse, null); fail("Should have thrown an exception"); } catch (ReportDownloadResponseException e) { assertEquals(400, e.getHttpStatus()); } }
responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1);