* Tests the {@link MutableTableModel#addRows(java.util.List)} method.
*/
public final void testAddRows() {
MutableTableModel model = getTableModel();
TableModelListener listener1 = (TableModelListener) EasyMock.createMock(TableModelListener.class);
TableModelListener listener2 = (TableModelListener) EasyMock.createMock(TableModelListener.class);
model.addTableModelListener(listener1);
model.addTableModelListener(listener2);
try {
model.addRows(null);
Assert.fail("Should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException e) {
//test passes
}
//Passing an empty list of rows should have no effect on the model or listeners
EasyMock.replay(listener1);
EasyMock.replay(listener2);
Assert.assertEquals(0, model.getRowCount());
model.addRows(new ArrayList());
Assert.assertEquals(0, model.getRowCount());
EasyMock.verify(listener1);
EasyMock.verify(listener2);
//reset the mocks for the next test
EasyMock.reset(listener1);
EasyMock.reset(listener2);
List rows = new ArrayList(2);
rows.add(new Object());
rows.add(new Object());
TableModelEvent expectedEvent = new TableModelEvent(model,
0,
1,
TableModelEvent.ALL_COLUMNS,
TableModelEvent.INSERT);
listener1.tableChanged(matchEvent(expectedEvent));
listener2.tableChanged(matchEvent(expectedEvent));
EasyMock.replay(listener1);
EasyMock.replay(listener2);
Assert.assertEquals(0, model.getRowCount());