LuceneSearchEngine { public List<String> searchForText(final String text) { List<String> fileNames = new ArrayList<>(); getNewReaderAndSearcherUsingWriter(); Query query = createQuery(text); try { TopDocs queryResult = doSearch(query); fileNames = getFileNames(queryResult); closeIndexReader(); } catch (IOException e) { logger.error(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } return fileNames; }  @PostConstruct void initQueryParserProperties(); List<String> searchForText(final String text);  }
@Test(expectedExceptions = QueryCannotBeParsedException.class) public void testSearchForTextWhenCannotParseQueryShouldThrowError() throws IOException, ParseException { given(readerFactory.create(true)).willReturn(indexReader); given(searcherFactory.create(indexReader)).willReturn(indexSearcher); given(queryParser.parse(TEXT)).willThrow(new ParseException()); underTest.searchForText(TEXT); }
@Test(expectedExceptions = SystemException.class) public void testSearchForTextWhenCannotCreateIndexReadertShouldThrowException() throws IOException { given(readerFactory.create(true)).willThrow(new IOException()); underTest.searchForText(TEXT); }