documentCreatorControl.verify();
}
final public void testAddDocumentWithInputStream() 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(InputStreamDocumentCreator.class);
InputStreamDocumentCreator documentCreator = (InputStreamDocumentCreator)documentCreatorControl.getMock();
MockControl inputStreamControl = MockClassControl.createStrictControl(InputStream.class);
InputStream inputStream = (InputStream)inputStreamControl.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.createInputStream();
documentCreatorControl.setReturnValue(inputStream, 1);
documentCreator.createDocumentFromInputStream(inputStream);
documentCreatorControl.setReturnValue(document, 1);
indexWriter.addDocument(document);
indexWriterControl.setVoidCallable(1);
inputStream.close();
inputStreamControl.setVoidCallable(1);
indexWriter.close();
indexWriterControl.setVoidCallable(1);
indexFactoryControl.replay();
indexWriterControl.replay();
documentCreatorControl.replay();
inputStreamControl.replay();
//Lucene template
LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
template.addDocument(documentCreator);
indexFactoryControl.verify();
indexWriterControl.verify();
documentCreatorControl.verify();
inputStreamControl.verify();
}