InputStreamDownload implements Download { public void write(HttpServletResponse response) throws IOException { writeDetails(response); OutputStream out = response.getOutputStream(); ByteStreams.copy(stream, out); stream.close(); } InputStreamDownload(InputStream input, String contentType, String fileName);  InputStreamDownload(InputStream input, String contentType, String fileName, boolean doDownload, long size); void write(HttpServletResponse response);  }
@Test public void shouldFlushWholeStreamToHttpResponse() throws IOException { InputStreamDownload fd = new InputStreamDownload(inputStream, "type", "x.txt"); fd.write(response); assertArrayEquals(bytes, outputStream.toByteArray()); }
@Test public void shouldUseHeadersToHttpResponse() throws IOException { InputStreamDownload fd = new InputStreamDownload(inputStream, "type", "x.txt"); fd.write(response); verify(response).setHeader("Content-type", "type"); assertArrayEquals(bytes, outputStream.toByteArray()); }