FileIndexer { public void indexFile(final File file) { FileInputStream fis = getInputStream(file); Document doc = documentFactory.createDocument(); Field pathField = new StringField(fieldName, file.getAbsolutePath(), Field.Store.YES); doc.add(pathField); doc.add(new LongField("modified", file.lastModified(), Field.Store.NO)); BufferedReader bufferedReader; try { bufferedReader = bufferedReaderFactory.createReader(fis); doc.add(new Field("contents", bufferedReader, TextField.TYPE_NOT_STORED)); addDocument(file, doc); fis.close(); } catch (IOException e) { logger.error(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } }  void indexFile(final File file);  }
@Test public void testIndexFileShouldUpdateIndexWhenWriterInAppendMode() throws IOException { given(writer.getConfig().getOpenMode()).willReturn(OpenMode.APPEND); given(file.getPath()).willReturn("path"); given(termFactory.createTerm(FIELD_NAME, "path")).willReturn(term); underTest.indexFile(file); verify(writer).updateDocument(term, document); }
@Test(expectedExceptions = SystemException.class) public void testIndexFileShouldThrowExceptionWhenFileNotFound() throws IOException { given(fileInputStreamFactory.createFileInputStream(file)).willThrow(new FileNotFoundException()); underTest.indexFile(file); }