DocumentFieldsProvider implements IDataProvider<DocumentField> { @Override public Iterator<? extends DocumentField> iterator(long first, long count) { return getFields().listIterator((int) first); } DocumentFieldsProvider(IModel<SolrDocument> documentModel, FieldFilter fieldFilter, List<String> fieldOrder); @Override Iterator<? extends DocumentField> iterator(long first, long count); @Override long size(); @Override IModel<DocumentField> model(DocumentField object); @Override void detach();  }
@Test public void testOrder() { final FieldFilter allowAllFilter = new FieldFilter() { @Override public boolean allowField(String fieldName) { return true; } }; final List<String> order = ImmutableList.of("field4", "field2", "field1", "field3"); instance = new DocumentFieldsProvider(Model.of(document), allowAllFilter, order); final long first = 0L; final long count = 100L; final Iterator<? extends DocumentField> result = instance.iterator(first, count); assertTrue(result.hasNext()); assertEquals("field4", result.next().getFieldName()); assertTrue(result.hasNext()); assertEquals("field2", result.next().getFieldName()); assertTrue(result.hasNext()); assertEquals("field1", result.next().getFieldName()); assertTrue(result.hasNext()); assertEquals("field3", result.next().getFieldName()); assertFalse(result.hasNext()); }
@Test public void testIterator() { context.checking(new Expectations() { { oneOf(filter).allowField("field1"); will(returnValue(true)); oneOf(filter).allowField("field2"); will(returnValue(false)); oneOf(filter).allowField("field3"); will(returnValue(true)); oneOf(filter).allowField("field4"); will(returnValue(false)); } }); final long first = 0L; final long count = 100L; final Iterator<? extends DocumentField> result = instance.iterator(first, count); assertTrue(result.hasNext()); assertEquals("field1", result.next().getFieldName()); assertTrue(result.hasNext()); assertEquals("field3", result.next().getFieldName()); assertFalse(result.hasNext()); }