AllResultFileDownloadController { @SuppressWarnings("unchecked") @RequestMapping(value = "/downloadAll") public void downloadFiles(final HttpSession session, final HttpServletResponse response) { List<List<String>> searchResultWithPairs = (List<List<String>>) session.getAttribute(SEARCH_RESULT_KEY); if (searchResultWithPairs != null && !searchResultWithPairs.isEmpty()) { writeZipToResponse(response, searchResultWithPairs); clearSearchResultFromSession(session); } }  @SuppressWarnings("unchecked") @RequestMapping(value = "/downloadAll") void downloadFiles(final HttpSession session, final HttpServletResponse response);  }
@Test public void testDownloadFilesWhenThereIsSearchingResult() throws ServletException, IOException { List<String> pair = new ArrayList<String>(); pair.add("first"); pair.add("test"); List<List<String>> list = new ArrayList<>(); list.add(pair); given(session.getAttribute(SEARCH_RESULT_KEY)).willReturn(list); given(response.getOutputStream()).willReturn(outputStream); underTest.downloadFiles(session, response); verify(fileZipper).createZipWithFiles(list, outputStream); verify(session).removeAttribute(SEARCH_RESULT_KEY); }
@Test public void testDownloadFilesWithoutSearchingResult() throws ServletException, IOException { List<List<String>> list = new ArrayList<>(); given(session.getAttribute(SEARCH_RESULT_KEY)).willReturn(list); given(response.getOutputStream()).willReturn(outputStream); underTest.downloadFiles(session, response); verify(fileZipper, times(0)).createZipWithFiles(list, outputStream); }