Indexer { public void index(Talk...talks) { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, new GermanAnalyzer(Version.LUCENE_43)); IndexWriter writer = null; try { writer = new IndexWriter(directory, config); for (Talk talk: talks) { logger.info(String.format("Indexing talk %s", talk.title)); writer.addDocument(asDocument(talk)); } writer.commit(); } catch (IOException ex) { if (writer != null) { try { writer.rollback(); } catch (IOException e) { e.printStackTrace(); } } } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } Indexer(Directory directory); void index(Talk...talks); void indexDirectory(String path); static void main(String [] args);  }
@Test public void twoTalksAreIndexed() throws IOException { Talk talk1 = new Talk("/path/to/talk1", "Title 1", Arrays.asList("Author 1"), new Date(), "Contents", new ArrayList<String>(), ""); Talk talk2 = new Talk("/path/to/talk2", "Title 2", Arrays.asList("Author 2"), new Date(), "More Contents", new ArrayList<String>(), ""); indexer.index(talk1, talk2); assertDocumentCount(2); }