FileDownload implements Download { public void write(HttpServletResponse response) throws IOException { inputDownload.write(response); } FileDownload(File file, String contentType, String fileName);  FileDownload(File file, String contentType);  FileDownload(File file, String contentType, String fileName, boolean doDownload); void write(HttpServletResponse response);  }
@Test public void shouldFlushWholeFileToHttpResponse() throws IOException { FileDownload fd = new FileDownload(file, "type"); fd.write(response); assertArrayEquals(bytes, outputStream.toByteArray()); }
@Test public void shouldUseHeadersToHttpResponse() throws IOException { FileDownload fd = new FileDownload(file, "type", "x.txt", false); fd.write(response); verify(response, times(1)).setHeader("Content-type", "type"); verify(response, times(1)).setHeader("Content-disposition", "inline; filename=x.txt"); assertArrayEquals(bytes, outputStream.toByteArray()); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionIfFileDoesntExists() throws Exception { File file0 = new File("a.path.that.doesnot.exists"); FileDownload fd = new FileDownload(file0, "type", "x.txt", false); fd.write(response); }