_TestUtil.checkIndex(directory);
IndexSearcher searcher = new IndexSearcher(directory);
Hits hits = searcher.search(new TermQuery(new Term("field", "iterator")));
HitIterator iterator = (HitIterator) hits.iterator();
assertEquals(2, iterator.length());
assertTrue(iterator.hasNext());
Hit hit = (Hit) iterator.next();
assertEquals("iterator test doc 1", hit.get("field"));
assertTrue(iterator.hasNext());
hit = (Hit) iterator.next();
assertEquals("iterator test doc 2", hit.getDocument().get("field"));
assertFalse(iterator.hasNext());
boolean caughtException = false;
try {
iterator.next();
} catch (NoSuchElementException e) {
assertTrue(true);
caughtException = true;
}