DataModelWrapper extends DataModel<E> { public void walk(FacesContext context, DataVisitor visitor) throws IOException { int rowCount = wrappedModel.getRowCount(); int currentRow = 0; while (rowCount < 0 || currentRow < rowCount) { wrappedModel.setRowIndex(currentRow); if (!wrappedModel.isRowAvailable() || DataVisitResult.STOP.equals(visitor.process(context, currentRow))) { break; } currentRow++; } } DataModelWrapper(DataModel<E> wrapped); void walk(FacesContext context, DataVisitor visitor); int getRowCount(); E getRowData(); int getRowIndex(); Object getWrappedData(); boolean isRowAvailable(); void setRowIndex(int rowIndex); void setWrappedData(Object data);  }
@Test void testWalk() throws Exception { final DataModel dataModelMock = mock(DataModel.class); final DataVisitor dataVisitorMock = mock(DataVisitor.class); final DataModelWrapper dataModelWrapper = new DataModelWrapper<>(dataModelMock); when(dataModelMock.getRowCount()).thenReturn(2); when(dataModelMock.isRowAvailable()).thenReturn(true); dataModelWrapper.walk(null, dataVisitorMock); verify(dataModelMock).setRowIndex(0); verify(dataModelMock).setRowIndex(1); verify(dataVisitorMock).process(null, 0); verify(dataVisitorMock).process(null, 1); verifyNoMoreInteractions(dataVisitorMock); }