### Question:
SolrDocumentIterator extends AbstractDocumentIterator<String> { @Override public long size() { return getResults() instanceof SolrDocumentList ? ((SolrDocumentList) results).getNumFound() : results.size(); }  @Override boolean hasNext(); @Override Pair<DocumentReference, String> next(); @Override long size();  }### Answer:
@Test void size() throws Exception { SolrDocumentList results = mock(SolrDocumentList.class); when(results.getNumFound()).thenReturn(12L); QueryResponse response = mock(QueryResponse.class); when(response.getResults()).thenReturn(results); when(this.solrInstance.query(any(SolrQuery.class))).thenReturn(response); DocumentIterator<String> iterator = this.solrIterator; WikiReference rootReference = new WikiReference("wiki"); iterator.setRootReference(rootReference); assertEquals(12, iterator.size()); verify(this.resolver).getQuery(rootReference); }
@Test void sizeWithException() { assertThrows(IllegalStateException.class, () -> this.solrIterator.size(), "Failed to query the Solr index."); }