TableStructure { public void setValue(int rowIndex, int columnIndex, boolean isInsertRow, boolean isInsertColumn, AbstractComponent value) { assert canSetValue(rowIndex, columnIndex, isInsertRow, isInsertColumn); assert type != TableType.ZERO_DIMENSIONAL; if (!canEmbedInTable(value)) return; if (type == TableType.ONE_DIMENSIONAL) { int componentIndex; if (rowIndex < rowList.size()) { componentIndex = rowList.get(rowIndex).get(0).getIndex(); } else { componentIndex = rootComponent.getComponents().size(); } if (!isInsertRow) { TableCell cell = rowList.get(rowIndex).get(columnIndex); AbstractComponent toBeRemoved = cell.getValue(); rootComponent.removeDelegateComponent(toBeRemoved); } rootComponent.addDelegateComponents(componentIndex, Collections.<AbstractComponent> singletonList(value)); } else { if (isInsertRow) { int componentIndex; if (rowIndex < rowList.size()) { componentIndex = rowList.get(rowIndex).getIndex(); } else { componentIndex = rootComponent.getComponents().size(); } AbstractComponent newChild = ServiceAccess.getService(ComponentRegistry.class).newCollection(Collections.singleton(value)); rootComponent.addDelegateComponents(componentIndex, Collections.singleton(newChild)); } else { TableRow row = rowList.get(rowIndex); int componentIndex; AbstractComponent targetComponent; if (!isInsertColumn && columnIndex < row.size()) { } if (columnIndex < row.size()) { targetComponent = row.get(columnIndex).getParent(); componentIndex = row.get(columnIndex).getIndex(); if (!isInsertColumn) { targetComponent.removeDelegateComponent(row.get(columnIndex).getValue()); } } else { targetComponent = row.get(row.size()-1).getParent(); componentIndex = targetComponent.getComponents().size(); } targetComponent.addDelegateComponents(componentIndex, Collections.singleton(value)); } updateColumnCount(); } buildTable(); } TableStructure(TableType type, AbstractComponent rootComponent); void notifyTableStructureChanged(); int getRowCount(); int getColumnCount(); boolean isSkeleton(); AbstractComponent getValue(int rowIndex, int columnIndex); void setValue(int rowIndex, int columnIndex, boolean isInsertRow, boolean isInsertColumn, AbstractComponent value); boolean canSetValue(int rowIndex, int columnIndex, boolean isInsertRow, boolean isInsertColumn); AbstractComponent getModifiedComponent(int rowIndex, int columnIndex, boolean isInsertRow, boolean isInsertColumn); TableType getType();  }
@Test(dataProvider="setValueTests") public void testSetValue(TableType type, int rowIndex, int columnIndex, boolean isInsertRow, boolean isInsertColumn) { TableStructure structure = getTableStructure(type); AbstractComponent[][] oldValues = new AbstractComponent[structure.getRowCount()][structure.getColumnCount()]; for (int i=0; i < structure.getRowCount(); ++i) { for (int j=0; j < structure.getColumnCount(); ++j) { oldValues[i][j] = structure.getValue(i, j); } } AbstractComponent newValue = new MockFeedComponent(); structure.setValue(rowIndex, columnIndex, isInsertRow, isInsertColumn, newValue); if (isInsertRow || isInsertColumn) { assertSame(structure.getValue(rowIndex, columnIndex), newValue); } else { for (int i=0; i < structure.getRowCount(); ++i) { for (int j=0; j < structure.getColumnCount(); ++j) { if (i==rowIndex && j==columnIndex) { assertSame(structure.getValue(i,j), newValue); } else { assertSame(structure.getValue(i,j), oldValues[i][j]); } } } } }
@Test(dataProvider="badSetValueTests", expectedExceptions={ArrayIndexOutOfBoundsException.class, AssertionError.class}) private void testBadSetValue(TableType type, Integer rowIndex, Integer columnIndex, boolean isInsertRow, boolean isInsertColumn) { TableStructure structure = getTableStructure(type); AbstractComponent newValue = new MockFeedComponent(); structure.setValue(rowIndex, columnIndex, isInsertRow, isInsertColumn, newValue); }