List< ContainerEvent > events = listener.assertExclusiveInsertionEvents();
listener.reset();
assertEquals( "wrong number of events fired by setDefaulColumns", defaultColumnsCount, events.size() );
for ( int i=0; i<defaultColumnsCount; ++i )
{
final ContainerEvent event = events.get(i);
final int index = impl_assertInteger( event.Accessor );
assertEquals( "unexpected Accessor value in insert notification", i, index );
assertTrue( "wrong column object notified in insert notification",
impl_areSameInterface( event.Element, m_columnModel.getColumn(i) ) );
}
// insert some more default columns, ensure that all previously existing columns are removed
final int moreDefaultColumnsCount = 5;
m_columnModel.setDefaultColumns( moreDefaultColumnsCount );
impl_assertColumnModelConsistency();
assertEquals( "setting default columns is expected to remove all previously existing columns",
moreDefaultColumnsCount, m_columnModel.getColumnCount() );
// in this situation, both removal and insertion events have been notified
final List< ContainerEvent > removalEvents = listener.getRemovalEvents();
final List< ContainerEvent > insertionEvents = listener.getInsertionEvents();
listener.reset();
// for the removal events, check the indexes
assertEquals( "wrong number of columns removed (or notified) upon setting default columns",
defaultColumnsCount, removalEvents.size() );
for ( int i=0; i<removalEvents.size(); ++i )
{
final ContainerEvent event = removalEvents.get(i);
final int removedIndex = impl_assertInteger( event.Accessor );
// The implementation is allowed to remove the columns from the beginning, in which case the
// index of the removed column must always be 0, since e.g. the second column has index 0
// after the first column (which previously had index 0) had been removed.
// Alternatively, the implementation is allowed to remove columns from the end, which means
// that the column index given in the event is steadily increasing.
assertTrue( "unexpected column removal event column index",
( removedIndex == 0 ) || ( removedIndex == removalEvents.size() - 1 - i ) );
}
// for the insertion events, check the indexes as well
assertEquals( "wrong number of insertion events when setting default columns over existing columns",
moreDefaultColumnsCount, insertionEvents.size() );
for ( int i=0; i<insertionEvents.size(); ++i )
{
final ContainerEvent event = insertionEvents.get(i);
final int index = impl_assertInteger( event.Accessor );
assertEquals( i, index );
}
// okay, remove all those columns
while ( m_columnModel.getColumnCount() != 0 )
{
final int columnCount = m_columnModel.getColumnCount();
final int removeColumnIndex = m_randomGenerator.nextInt( columnCount );
m_columnModel.removeColumn( removeColumnIndex );
events = listener.assertExclusiveRemovalEvents();
listener.reset();
assertEquals( "removing a single column should notify a single event", 1, events.size() );
final ContainerEvent event = events.get(0);
final int removalIndex = impl_assertInteger( event.Accessor );
assertEquals( "removing an arbitrary column does not notify the proper accessor",
removeColumnIndex, removalIndex );
}