SearchController { @RequestMapping(value = "/search", method = RequestMethod.GET) public void searchAndZip(@RequestParam("text") final String searchedText, final HttpServletResponse resp) { if (searchedText != null && !"".equals(searchedText)) { List<List<String>> searchResult; try { searchResult = searchForText(searchedText); } catch (QueryCannotBeParsedException e) { logger.warn("Invalid query"); searchResult = new ArrayList<List<String>>(); } zipSearchResult(searchedText, resp, searchResult); } }  @RequestMapping(value = "/search", method = RequestMethod.GET) void searchAndZip(@RequestParam("text") final String searchedText, final HttpServletResponse resp); @ResponseBody @RequestMapping(value = "/search", method = RequestMethod.POST) ResponseEntity<String> searchForFiles(@RequestParam("searchedText") final String searchedText, final HttpSession session);  }
@Test public void testSearchAndZipWhenSearchedTextIsNotEmpty() throws IOException { underTest.searchAndZip("test", response); verify(luceneEngine).search("test"); verify(fileChecker).checkFilesExistsWithPairs(lucineResult); verify(fileZipper).createZipWithFiles(listOfLists, outputStream); }
@Test public void testSearchAndZipWhenSearchedTextIsEmptyString() throws IOException { underTest.searchAndZip("", response); verify(fileChecker, times(0)).checkFilesExistsWithPairs(lucineResult); verify(fileZipper, times(0)).createZipWithFiles(listOfLists, outputStream); }
@Test public void testSearchAndZipWhenSearchedTextIsNull() throws IOException { underTest.searchAndZip(null, response); verify(fileChecker, times(0)).checkFilesExistsWithPairs(lucineResult); verify(fileZipper, times(0)).createZipWithFiles(listOfLists, outputStream); }
@Test public void testSearchAndZipWhenQueryIsNotValid() throws IOException { given(luceneEngine.search("test")).willThrow(new QueryCannotBeParsedException("Parse Exception")); underTest.searchAndZip("test", response); verify(fileZipper).createZipWithFiles(new ArrayList<List<String>>(), outputStream); }