FileDownloadUtils { public static boolean downloadFile(HttpServletResponse response, String fileName) { File file = new File(fileName); return downloadFile(response, file); }  static boolean downloadFile(HttpServletResponse response, String fileName); static boolean downloadFile(HttpServletResponse response, File file); static final int FILE_CHUNK_BUFFER_SIZE; }
@Test public void testDownloadFileHttpServletResponseString() throws IOException { File downFile = new ClassPathResource("TEST_USER.zip").getFile(); String filePath = downFile.getAbsolutePath(); MockHttpServletResponse resp = new MockHttpServletResponse(); FileDownloadUtils.downloadFile(resp, filePath); String lengthHeader = resp.getHeader("Content-Length"); assertThat(lengthHeader, is(String.valueOf(downFile.length()))); }
@Test public void testDownloadNotExistFile() throws IOException { File downFile = null; HttpServletResponse resp = new MockHttpServletResponse(); boolean result = FileDownloadUtils.downloadFile(resp, downFile); assertThat(result, is(false)); downFile = new File("Not-existed-file"); result = FileDownloadUtils.downloadFile(resp, downFile); assertThat(result, is(false)); }