RectangularViewportDefinition extends ViewportDefinition { @Override public boolean isValidFor(GridStructure grid) { if (!_rows.isEmpty()) { int maxRow = _rows.get(_rows.size() - 1); if (maxRow >= grid.getRowCount()) { return false; } } if (!_columns.isEmpty()) { int maxCol = _columns.get(_columns.size() - 1); if (maxCol >= grid.getColumnCount()) { return false; } } return true; } RectangularViewportDefinition(int version,
                                              List<Integer> rows,
                                              List<Integer> columns,
                                              TypeFormatter.Format format,
                                              Boolean enableLogging); @Override Iterator<GridCell> iterator(); @Override boolean isValidFor(GridStructure grid); @Override String toString();  }
@Test public void isValidForGrid() { RectangularViewportDefinition viewportCells = new RectangularViewportDefinition(0, ImmutableList.of(3, 4, 6), ImmutableList.of(8, 10), TypeFormatter.Format.EXPANDED, false); GridStructure validStructure = mock(GridStructure.class); stub(validStructure.getColumnCount()).toReturn(20); stub(validStructure.getRowCount()).toReturn(10); assertTrue(viewportCells.isValidFor(validStructure)); GridStructure invalidColumns = mock(GridStructure.class); stub(invalidColumns.getColumnCount()).toReturn(5); stub(invalidColumns.getRowCount()).toReturn(10); assertFalse(viewportCells.isValidFor(invalidColumns)); GridStructure invalidRows = mock(GridStructure.class); stub(invalidRows.getColumnCount()).toReturn(15); stub(invalidRows.getRowCount()).toReturn(5); assertFalse(viewportCells.isValidFor(invalidRows)); }