EventSelectionModel<String> eventSelectionModel = new EventSelectionModel<String>(source);
ListSelectionChangeCounter eventSelectionModelCounter = new ListSelectionChangeCounter();
eventSelectionModel.addListSelectionListener(eventSelectionModelCounter);
// create DefaultListSelectionModel (SUN's selection model)
DefaultListSelectionModel defaultListSelectionModel = new DefaultListSelectionModel();
ListSelectionChangeCounter defaultListSelectionModelCounter = new ListSelectionChangeCounter();
defaultListSelectionModel.addListSelectionListener(defaultListSelectionModelCounter);
// create two different JLists (one with EventSelectionModel and one with DefaultListSelectionModel) that share the same data model
JList eventList = new JList(model);
eventList.setSelectionModel(eventSelectionModel);
JList defaultList = new JList(model);
defaultList.setSelectionModel(defaultListSelectionModel);
// select the first element in both selection models
eventSelectionModel.setSelectionInterval(0, 0);
defaultListSelectionModel.setSelectionInterval(0, 0);
// verify that each selection model broadcasted the selection event
assertEquals(1, defaultListSelectionModelCounter.getCountAndReset());
assertEquals(1, eventSelectionModelCounter.getCountAndReset());
// change an element in the model which is selected in the selection models
source.set(0, "Bart");
// selection should not have changed in either selection model
assertEquals(0, defaultListSelectionModel.getMinSelectionIndex());
assertEquals(0, defaultListSelectionModel.getMaxSelectionIndex());
assertEquals(0, defaultListSelectionModel.getLeadSelectionIndex());
assertEquals(0, defaultListSelectionModel.getAnchorSelectionIndex());
assertEquals(0, eventSelectionModel.getMinSelectionIndex());
assertEquals(0, eventSelectionModel.getMaxSelectionIndex());
assertEquals(0, eventSelectionModel.getLeadSelectionIndex());
assertEquals(0, eventSelectionModel.getAnchorSelectionIndex());