### Question:
ListSelection implements ListEventListener<E> { public void setSelection(int index) { setSelection(index, index); } ListSelection(EventList<E> source);  ListSelection(EventList<E> source, int[] initialSelection); @Override void listChanged(ListEvent<E> listChanges); void addValidSelectionMatcher(Matcher<E> validSelectionMatcher); void removeValidSelectionMatcher(Matcher<E> validSelectionMatcher); EventList<E> getSelected(); EventList<E> getTogglingSelected(); EventList<E> getDeselected(); EventList<E> getTogglingDeselected(); EventList<E> getSource(); void invertSelection(); boolean isSelected(int sourceIndex); void deselect(int index); void deselect(int start, int end); void deselect(int[] indices); void deselectAll(); void select(int index); void select(int start, int end); void select(int[] indices); int select(E value); boolean select(Collection<E> values); void selectAll(); void setSelection(int index); void setSelection(int start, int end); void setSelection(int[] indices); int getAnchorSelectionIndex(); void setAnchorSelectionIndex(int anchorSelectionIndex); int getLeadSelectionIndex(); void setLeadSelectionIndex(int leadSelectionIndex); void setSelectionMode(int selectionMode); int getSelectionMode(); int getMinSelectionIndex(); int getMaxSelectionIndex(); void addSelectionListener(Listener selectionListener); void removeSelectionListener(Listener selectionListener); void dispose(); static final int SINGLE_SELECTION; static final int SINGLE_INTERVAL_SELECTION; static final int MULTIPLE_INTERVAL_SELECTION; static final int MULTIPLE_INTERVAL_SELECTION_DEFENSIVE; }### Answer:
@Test public void testSettingSelectionRange() { for(int i = 0; i < 20; i++) { source.add(new Integer(i)); } listSelection.setSelection(5, 14); assertEquals(10, selectedList.size()); assertEquals(new Integer(5), selectedList.get(0)); assertEquals(new Integer(14), selectedList.get(9)); assertEquals(10, deselectedList.size()); listSelection.setSelection(15, 16); assertEquals(2, selectedList.size()); assertEquals(new Integer(15), selectedList.get(0)); assertEquals(new Integer(16), selectedList.get(1)); assertEquals(18, deselectedList.size()); listSelection.setSelection(10, 19); assertEquals(10, selectedList.size()); assertEquals(new Integer(10), selectedList.get(0)); assertEquals(new Integer(19), selectedList.get(9)); assertEquals(10, deselectedList.size()); listSelection.setSelection(10, 15); assertEquals(6, selectedList.size()); assertEquals(new Integer(10), selectedList.get(0)); assertEquals(new Integer(15), selectedList.get(5)); assertEquals(14, deselectedList.size()); }
@Test public void testSettingSelectionByArray() { int[] testArray1 = {0, 1, 5, 6, 8, 9, 14, 15, 18, 19}; int[] testArray2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; int[] testArray3 = {0, 1, 2, 3, 4, 15, 16, 17, 18, 19}; for(int i = 0; i < 20; i++) { source.add(new Integer(i)); } listSelection.setSelection(testArray1); assertEquals(10, selectedList.size()); assertEquals(10, deselectedList.size()); listSelection.setSelection(testArray2); assertEquals(10, selectedList.size()); assertEquals(10, deselectedList.size()); listSelection.setSelection(testArray3); assertEquals(10, selectedList.size()); assertEquals(10, deselectedList.size()); }