public void testSelectionForDirectSelectionChanges() { SelectionInList<String> sil = new SelectionInList<String>(listModel); PropertyChangeReport selectionEmptyReport = new PropertyChangeReport(); sil.addPropertyChangeListener( SelectionInList.PROPERTYNAME_SELECTION_EMPTY, selectionEmptyReport); sil.setSelection((String) listModel.getElementAt(0)); assertFalse("The selection index is 0 and not empty.", sil.isSelectionEmpty()); assertEquals( "selectionEmpty changed from true to false.", 1, selectionEmptyReport.eventCount()); assertTrue( "1) selectionEmpty change event oldValue == true.", selectionEmptyReport.lastOldBooleanValue()); assertFalse( "1) selectionEmpty change event newValue == false.", selectionEmptyReport.lastNewBooleanValue()); sil.setSelection((String) listModel.getElementAt(1)); assertFalse("The selection index is 1 and not empty.", sil.isSelectionEmpty()); assertEquals("No selectionEmpty change event fired", 1, selectionEmptyReport.eventCount()); sil.setSelection(null); assertTrue("The selection index is empty.", sil.isSelectionEmpty()); assertEquals( "selectionEmpty changed from false to true.", 2, selectionEmptyReport.eventCount()); assertFalse( "2) selectionEmpty change event oldValue == false.", selectionEmptyReport.lastOldBooleanValue()); assertTrue( "2) selectionEmpty change event newValue == true.", selectionEmptyReport.lastNewBooleanValue()); }
public void testSelectionForDirectSelectionIndexChanges() { SelectionInList<String> sil = new SelectionInList<String>(listModel); // Create change reports. PropertyChangeReport valueReport = new PropertyChangeReport(); PropertyChangeReport selectionReport = new PropertyChangeReport(); PropertyChangeReport selectionEmptyReport = new PropertyChangeReport(); PropertyChangeReport selectionIndexReport = new PropertyChangeReport(); // Register change reports for value, selection, selection index, // and selectionEmpty sil.addValueChangeListener(valueReport); sil.addPropertyChangeListener(SelectionInList.PROPERTYNAME_SELECTION, selectionReport); sil.addPropertyChangeListener( SelectionInList.PROPERTYNAME_SELECTION_EMPTY, selectionEmptyReport); sil.addPropertyChangeListener( SelectionInList.PROPERTYNAME_SELECTION_INDEX, selectionIndexReport); assertEquals("The initial value is null.", null, sil.getValue()); assertEquals("The initial selection is null.", null, sil.getSelection()); assertTrue("The initial selection is empty.", sil.isSelectionEmpty()); assertEquals("The initial selection index is -1.", -1, sil.getSelectionIndex()); sil.setSelectionIndex(0); assertEquals( "The new value is the first list element.", listModel.getElementAt(0), sil.getValue()); assertEquals( "The new selection is the first list element.", listModel.getElementAt(0), sil.getSelection()); assertFalse("The selection is not empty.", sil.isSelectionEmpty()); assertEquals("The new selection index is 0.", 0, sil.getSelectionIndex()); assertEquals( "selectionEmpty changed from true to false.", 1, selectionEmptyReport.eventCount()); assertTrue( "1) selectionEmpty change event oldValue == true.", selectionEmptyReport.lastOldBooleanValue()); assertFalse( "1) selectionEmpty change event newValue == false.", selectionEmptyReport.lastNewBooleanValue()); sil.setSelectionIndex(1); assertFalse("The selection index is 1 and not empty.", sil.isSelectionEmpty()); assertEquals("No selectionEmpty change event fired", 1, selectionEmptyReport.eventCount()); sil.clearSelection(); assertTrue("The selection index is empty.", sil.isSelectionEmpty()); assertEquals( "selectionEmpty changed from false to true.", 2, selectionEmptyReport.eventCount()); assertFalse( "2) selectionEmpty change event oldValue == false.", selectionEmptyReport.lastOldBooleanValue()); assertTrue( "2) selectionEmpty change event newValue == true.", selectionEmptyReport.lastNewBooleanValue()); }