import javax.swing.*; /* @test * @bug 6921688 * @summary Lead selection index should be cleared after selection was erased * @author Fedor Bobin * @run main DefaultListSelectionModelTest */ public class DefaultListSelectionModelTest { public static void main(String[] args) { final DefaultListSelectionModel defaultListSelectionModel = new DefaultListSelectionModel(); defaultListSelectionModel.setSelectionInterval(0, 0); if (defaultListSelectionModel.getLeadSelectionIndex() != 0) { throw new AssertionError("Was selected only item 0 but lead selected index = " + defaultListSelectionModel.getLeadSelectionIndex()); } defaultListSelectionModel.removeIndexInterval(0, 0); if (!defaultListSelectionModel.isSelectionEmpty()) { throw new AssertionError("Selection should be empty"); } if (defaultListSelectionModel.getLeadSelectionIndex() != -1) { throw new AssertionError("Selection is empty => there is no lead selected index => " + "lead selected index must be -1 but lead selected index = " + defaultListSelectionModel.getLeadSelectionIndex()); } } }