I have a controller that provides functionality for downloading a file.
@ResponseBody
public void downloadRecycleResults(String batchName, HttpServletResponse response) throws Exception {
File finalResultFile = null;
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + finalResultFile.getName());
IOUtils.copy(new FileReader(finalResultFile), response.getOutputStream());
}
I can’t understand how to write a test, where I can check the content that was written on response. I used the ArgumentCaptorlot, but somehow it does not fit here.
controller.downloadRecycleResults("batchName", mock(HttpServletResponse.class));
verify(response).getOutputStream();
source
share