ResultFileDownloadController { @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) public void downloadFile(@RequestParam(value = "filePath") final String filePath, final HttpServletResponse response) { addFileToResponse(filePath, response, true); }  @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) void downloadFile(@RequestParam(value = "filePath") final String filePath, final HttpServletResponse response); @RequestMapping(value = "/openFile", method = RequestMethod.GET) void openFile(@RequestParam(value = "filePath") final String filePath, final HttpServletResponse response);  }
@Test public void testDownloadFileWhenTheFileExistsOnThePath() throws IOException { given(response.getOutputStream()).willReturn(outputStream); underTest.downloadFile("src/test/resources/first_testreq.txt", response); verify(response).setHeader(Mockito.anyString(), Mockito.anyString()); verify(response).setContentType(Mockito.anyString()); verify(response).flushBuffer(); }
@Test public void testDownloadFileWhenTheFileNotExistsOnThePath() throws IOException { given(response.getOutputStream()).willReturn(outputStream); underTest.downloadFile("src/test/resources/testreq.txt", response); verify(response).setHeader(Mockito.anyString(), Mockito.anyString()); verify(response).setContentType(Mockito.anyString()); }