MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
MockControl indexReaderControl = MockControl.createStrictControl(LuceneIndexReader.class);
LuceneIndexReader indexReader = (LuceneIndexReader)indexReaderControl.getMock();
MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
MockControl documentModifierControl = MockControl.createStrictControl(DocumentModifier.class);
DocumentModifier documentModifier = (DocumentModifier)documentModifierControl.getMock();
MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
LuceneHits hits = (LuceneHits)hitsControl.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));
Term term = new Term("id","2");
indexFactory.getIndexReader();
indexFactoryControl.setReturnValue(indexReader, 1);
indexReader.createSearcher();
indexReaderControl.setReturnValue(searcher);
searcher.search(new TermQuery(term));
searcherControl.setReturnValue(hits);
hits.length();
hitsControl.setReturnValue(1, 2);
hits.doc(0);
hitsControl.setReturnValue(document);
documentModifier.updateDocument(document);
documentModifierControl.setReturnValue(document, 1);
searcher.close();
searcherControl.setVoidCallable(1);
indexReader.close();
indexReaderControl.setVoidCallable(1);
indexFactory.getIndexReader();
indexFactoryControl.setReturnValue(indexReader, 1);
indexReader.deleteDocuments(term);
indexReaderControl.setReturnValue(1, 1);
indexReader.close();
indexReaderControl.setVoidCallable(1);
indexFactory.getIndexWriter();
indexFactoryControl.setReturnValue(indexWriter, 1);