assertEquals(numDoc, 3);
}
final public void testAddDocument() throws Exception {
SimpleAnalyzer analyzer = new SimpleAnalyzer();
MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
MockControl documentCreatorControl = MockControl.createStrictControl(DocumentCreator.class);
DocumentCreator documentCreator = (DocumentCreator)documentCreatorControl.getMock();
//document
Document document = new Document();
document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
indexFactory.getIndexWriter();
indexFactoryControl.setReturnValue(indexWriter, 1);
documentCreator.createDocument();
documentCreatorControl.setReturnValue(document);
indexWriter.addDocument(document);
indexWriterControl.setVoidCallable(1);
indexWriter.close();
indexWriterControl.setVoidCallable(1);
indexFactoryControl.replay();
indexWriterControl.replay();
documentCreatorControl.replay();
//Lucene template
LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
template.addDocument(documentCreator);
indexFactoryControl.verify();
indexWriterControl.verify();
documentCreatorControl.verify();
}