@Parameterized.Parameters(name = "{0} bits")
 public static List<Object[]> formats() {
   ArrayList<Object[]> parameters = new ArrayList<>();
   for (BitmapDocumentFormat format : BitmapDocumentFormat.values()) {
     parameters.add(new Object[] {format});
   }
   return parameters;
 }
  @Test
  public void shouldReadPagesOfDocumentsFromSearcher() throws Exception {
    final int labelId = 7;
    final int pageSize = 2;
    // given
    Query query = mock(Query.class);
    IndexSearcher searcher = mock(IndexSearcher.class);
    ScoreDoc doc1 = new ScoreDoc(37, 0.0f);
    ScoreDoc doc2 = new ScoreDoc(16, 0.0f);
    ScoreDoc doc3 = new ScoreDoc(11, 0.0f);
    when(searcher.searchAfter(any(ScoreDoc.class), same(query), anyInt()))
        .thenReturn(
            docs(doc1, doc2), // page1
            docs(doc3) // page2
            );
    when(searcher.doc(37))
        .thenReturn(document(format.rangeField(0x1), format.labelField(labelId, 0x01)));
    when(searcher.doc(16))
        .thenReturn(document(format.rangeField(0x2), format.labelField(labelId, 0x03)));
    when(searcher.doc(11))
        .thenReturn(document(format.rangeField(0x3), format.labelField(labelId, 0x30)));

    PrimitiveLongIterator iterator =
        flatten(new PageOfRangesIterator(format, searcher, pageSize, query, labelId));

    // when
    List<Long> longs = primitivesList(iterator);

    // then
    assertEquals(
        asList(
            /*doc1:*/ (1L << format.bitmapFormat().shift),
            /*doc2:*/ (2L << format.bitmapFormat().shift),
            (2L << format.bitmapFormat().shift) + 1,
            /*doc3:*/ (3L << format.bitmapFormat().shift) + 4,
            (3L << format.bitmapFormat().shift) + 5),
        longs);

    ArgumentCaptor<ScoreDoc> prefixCollector = ArgumentCaptor.forClass(ScoreDoc.class);
    verify(searcher, times(2)).searchAfter(prefixCollector.capture(), same(query), eq(2));
    assertEquals(asList(null, doc2), prefixCollector.getAllValues());

    verify(searcher, times(3)).doc(anyInt());
    verifyNoMoreInteractions(searcher);
  }