DataTable extends AbstractDataSource implements MutableDataSource { public int add(Comparable<?>... values) { return add(Arrays.asList(values)); } DataTable();  DataTable(Class<? extends Comparable<?>>... types); @SuppressWarnings("unchecked")  DataTable(int cols, Class<? extends Comparable<?>> type);  DataTable(DataSource source);  DataTable(Column... columns); int add(Comparable<?>... values); int add(List<? extends Comparable<?>> values); int add(Row row); void add(Record row); void remove(int row); void removeLast(); void clear(); Comparable<?> get(int col, int row); @SuppressWarnings("unchecked") Comparable<T> set(int col, int row, Comparable<T> value); int getRowCount(); void sort(final DataComparator... comparators); @Override void setName(String name);  }
@Test public void testAdd() { int sizeBefore = table.getRowCount(); table.add(0, -1); table.add(1, -2); int rowIndex = table.add(2, -3); assertEquals(sizeBefore + 3, table.getRowCount()); assertEquals(table.getRowCount() - 1, rowIndex); try { table.add(1); fail("Expected IllegalArgumentException exception."); } catch (IllegalArgumentException e) { } try { table.add(1.0, 1.0); fail("Expected IllegalArgumentException exception."); } catch (IllegalArgumentException e) { } }
@Test public void testAddCollectionReturnsInsertedPosition() { DataTable table = new DataTable(); table.add(); table.add(); int insertedPosition = table.add(Collections.<Comparable<?>>emptyList()); assertThat(insertedPosition, is(2)); }
@Test(expected = IllegalArgumentException.class) public void testAddRecordThrowsExceptionIfColumnCountDoesNotMatch() { DataTable table = new DataTable(String.class, Double.class); Record record = new Record("1"); table.add(record); }
@Test public void testEventsAdd() { table.add(12, 34); MockDataListener listener = new MockDataListener(); table.addDataListener(listener); assertNull(listener.added); assertNull(listener.updated); assertNull(listener.removed); int row = table.add(56, 78); assertNotNull(listener.added); assertNull(listener.updated); assertNull(listener.removed); assertEquals(2, listener.added.length); assertEquals(0, listener.added[0].getCol()); assertEquals(row, listener.added[0].getRow()); assertNull(listener.added[0].getOld()); assertEquals(56, listener.added[0].getNew()); assertEquals(1, listener.added[1].getCol()); assertEquals(row, listener.added[1].getRow()); assertNull(listener.added[1].getOld()); assertEquals(78, listener.added[1].getNew()); }