LuceneDeleteEngine { public void deleteDocFromIndex(final String fileName) { try { Term term = termFactory.createTerm(fieldName, fileName); indexWriter.deleteDocuments(term); } catch (IOException e) { throw new SystemException("Could not delete file " + fileName + " from the index. Reason:" + e.getMessage()); } }  void deleteDocFromIndex(final String fileName);  }
@Test public void testDeleteDocFromIndexShouldDeleteFileFromIndex() throws IOException { given(termFactory.createTerm(FIELD_NAME, TEXT)).willReturn(term); underTest.deleteDocFromIndex(TEXT); verify(indexWriter).deleteDocuments(term); }
@Test(expectedExceptions = SystemException.class) public void testDeleteDocFromIndexWhenCannotDeleteShouldThrowException() throws IOException { given(termFactory.createTerm(FIELD_NAME, TEXT)).willReturn(term); willThrow(new IOException()).given(indexWriter).deleteDocuments(term); underTest.deleteDocFromIndex(TEXT); }