assertEquals(1, firstModel.getTableModelListeners().length);
assertEquals(3, table.getColumnCount());
// 2. wire up a TableComparatorChooser and make the third column sort
TableComparatorChooser chooser = TableComparatorChooser.install(table, sorted, AbstractTableComparatorChooser.SINGLE_COLUMN);
chooser.appendComparator(2, 0, false);
// the TableComparatorChooser should install a PropertyChangeListener on the JTable
assertEquals(initialNumPropertyChangeListenersOnJTable+1, table.getPropertyChangeListeners().length);
// the TableComparatorChooser should install a TableModelListener on the EventTableModel
assertEquals(2, firstModel.getTableModelListeners().length);
// this assertion proves that the TableComparatorChooser cleared its sorting state
assertEquals(1, chooser.getSortingColumns().size());
// 3. changing the TableFormat within the existing EventTableModel should clear the sorting state
firstModel.setTableFormat(new TestTableFormat(1));
// this assertion proves that the JTable has rebuilt the TableColumnModel
assertEquals(1, table.getColumnCount());
// this assertion proves that the TableComparatorChooser cleared its sorting state
assertTrue(chooser.getSortingColumns().isEmpty());
assertEquals(2, firstModel.getTableModelListeners().length);
// 4. reapply a sort to the JTable on the first column
chooser.appendComparator(0, 0, false);
assertEquals(1, chooser.getSortingColumns().size());
// 5. set a new EventTableModel that only uses 2 columns
secondModel = new EventTableModel<String>(sorted, new TestTableFormat(2));
table.setModel(secondModel);
// nothing should listen to firstModel, and secondModel is now active
assertEquals(0, firstModel.getTableModelListeners().length);
assertEquals(2, secondModel.getTableModelListeners().length);
// this assertion proves that the JTable has rebuilt the TableColumnModel
assertEquals(2, table.getColumnCount());
// this assertion proves that the TableComparatorChooser cleared its sorting state
assertTrue(chooser.getSortingColumns().isEmpty());
// 6. disposing of the TableComparatorChooser should remove all listeners
assertEquals(initialNumPropertyChangeListenersOnJTable+1, table.getPropertyChangeListeners().length);
chooser.dispose();
assertEquals(initialNumPropertyChangeListenersOnJTable, table.getPropertyChangeListeners().length);
assertEquals(0, firstModel.getTableModelListeners().length);
assertEquals(1, secondModel.getTableModelListeners().length); // the JTable is still listening to the secondModel
// replacing the JTable's model should remove the remaining listener from secondModel