Package org.fest.swing.driver
Class JListDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
org.fest.swing.driver.ContainerDriver
org.fest.swing.driver.JComponentDriver
org.fest.swing.driver.JListDriver
Understands functional testing of
JLists:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JListCellReaderprivate static final Stringprivate static final StringFields inherited from class org.fest.swing.driver.ComponentDriver
robot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate PointcellCenterIn(Pair<Integer, Point> scrollInfo) voidcellReader(JListCellReader newCellReader) Updates the implementation ofto use when comparing internal values of aJListCellReaderand the values expected in a test.JListvoidclearSelection(JList list) Clears the selection in the given.JListprivate static voidclearSelectionOf(JList list) voidclickItem(JList list, int index, MouseButton button, int times) Clicks the item under the given index, using the specified mouse button, the given number times.voidclickItem(JList list, String value, MouseButton button, int times) Clicks the first item matching the given value, using the specified mouse button, the given number times.voidclickItem(JList list, Pattern pattern, MouseButton button, int times) Clicks the first item matching the given regular expression pattern, using the specified mouse button, the given number times.private voidclickItem(JList list, TextMatcher matcher, MouseButton button, int times) String[]contentsOf(JList list) Returns an array ofStrings that represents the contents of the given, using this driver'sJList.JListCellReadervoidStarts a drag operation at the location of the given index.voidStarts a drag operation at the location of the first item matching the given value.voidStarts a drag operation at the location of the first item matching the given regular expression pattern.private voiddrag(JList list, TextMatcher matcher) voidEnds a drag operation at the center of the.JListvoidEnds a drag operation at the location of the given index.voidEnds a drag operation at the location of the first item matching the given value.voidEnds a drag operation at the location of the first item matching the given regular expression pattern.private voiddrop(JList list, TextMatcher matcher) private LocationUnavailableExceptionfailMatchingNotFound(JList list, TextMatcher matcher) private voidfailNoSelection(JList list) intReturns the index of the first item matching the given value.intReturns the index of the first item matching the given regular expression pattern.private intindexOf(JList list, TextMatcher matcher) private static intitemIndex(JList list, TextMatcher matcher, JListCellReader cellReader) Returns the coordinates of the first item matching the given value.private StringrequiredSelection(JList list) voidrequireItemCount(JList list, int expected) Verifies that number of items in the givenis equal to the expected one.JListvoidrequireNoSelection(JList list) Verifies that thedoes not have a selection.JListvoidrequireSelectedItems(JList list, int... indices) Verifies that the given item indices are selected in the.JListvoidrequireSelectedItems(JList list, String... items) Verifies that the selected items in thematch the given values.JListvoidrequireSelectedItems(JList list, Pattern... patterns) Verifies that the selected items in thematch the given regular expression patterns.JListprivate voidrequireSelectedItems(JList list, TextMatcher matcher) voidrequireSelection(JList list, int index) Verifies that the selected index in thematches the given value.JListvoidrequireSelection(JList list, String value) Verifies that the selected item in thematches the given value.JListvoidrequireSelection(JList list, Pattern pattern) Verifies that the selected item in thematches the given regular expression pattern.JListprivate org.fest.assertions.DescriptionselectedIndexProperty(JList list) String[]selectionOf(JList list) Returns an array ofStrings that represents the selection in the given, using this driver'sJList.JListCellReadervoidselectItem(JList list, int index) Selects the item under the given index using left mouse button once.voidselectItem(JList list, String value) Selects the item in the givenwhose value matches the given one.JListvoidselectItem(JList list, Pattern pattern) Selects the item in the givenwhose value matches the given regular expression pattern.JListprivate voidselectItem(JList list, TextMatcher matcher) voidselectItems(JList list, int[] indices) Selects the items under the given indices.voidselectItems(JList list, int start, int end) Selects the items in the specified range.voidselectItems(JList list, String[] values) Selects the items matching the given values.voidselectItems(JList list, Pattern[] patterns) Selects the items matching the given regular expression patterns.voidselectItems(JList list, Range.From from, Range.To to) Selects the items in the specified range.private voidselectItems(JList list, TextMatcher matcher) showPopupMenu(JList list, int index) Shows a pop-up menu at the location of the specified item in the.JListshowPopupMenu(JList list, String value) Shows a pop-up menu at the location of the specified item in the.JListshowPopupMenu(JList list, Pattern pattern) Shows a pop-up menu at the location of the specified item in the.JListprivate JPopupMenushowPopupMenu(JList list, TextMatcher matcher) private voidvalidateArrayOfIndices(int[] indices) private static voidvalidateIndicesAndClearSelection(JList list, int... indices) Returns theStringrepresentation of the element under the given index, using this driver's.JListCellReaderprivate voidMethods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisibleMethods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidthMethods inherited from class org.fest.swing.driver.ComponentDriver
assertIsEnabledAndShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, focus, focusAndWaitForFocusGain, invokePopupMenu, invokePopupMenu, moveMouseIgnoringAnyError, moveMouseIgnoringAnyError, performAccessibleActionOf, pressAndReleaseKey, pressAndReleaseKey, pressAndReleaseKeys, pressKey, propertyName, releaseKey, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireSize, requireVisible, rightClick, settings, waitForShowing
-
Field Details
-
SELECTED_INDICES_PROPERTY
- See Also:
-
SELECTED_INDEX_PROPERTY
- See Also:
-
cellReader
-
-
Constructor Details
-
JListDriver
Creates a newJListDriver.- Parameters:
robot- the robot to use to simulate user input.
-
-
Method Details
-
contentsOf
Returns an array ofStrings that represents the contents of the given, using this driver'sJList.JListCellReader- Parameters:
list- the targetJList.- Returns:
- an array of
Strings that represents the contents of the givenJList. - See Also:
-
selectItems
Selects the items matching the given values.- Parameters:
list- the targetJList.values- the values to match. EachStringcan be a regular expression.- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the any of the given values cannot be found.
-
selectItems
Selects the items matching the given regular expression patterns.- Parameters:
list- the targetJList.patterns- the regular expression patterns to match.- Throws:
NullPointerException- if the given array isnull.NullPointerException- if any of the regular expression patterns isnull.IllegalArgumentException- if the given array is empty.IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the any of the given regular expression patterns cannot be found.- Since:
- 1.2
-
selectItems
-
selectItem
Selects the item in the givenwhose value matches the given one.JList- Parameters:
list- the targetJList.value- the value to match.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the given value cannot be found.
-
selectItem
Selects the item in the givenwhose value matches the given regular expression pattern.JList- Parameters:
list- the targetJList.pattern- the regular expression to match.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the given value cannot be found.NullPointerException- if the given regular expression pattern isnull.- Since:
- 1.2
-
selectItem
-
clickItem
Clicks the first item matching the given value, using the specified mouse button, the given number times.- Parameters:
list- the targetJList.value- the value to match.button- the button to use.times- the number of times to click.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the given value cannot be found.
-
clickItem
Clicks the first item matching the given regular expression pattern, using the specified mouse button, the given number times.- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.button- the button to use.times- the number of times to click.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.NullPointerException- if the given regular expression pattern isnull.LocationUnavailableException- if an element matching the given regular expression pattern cannot be found.- Since:
- 1.2
-
clickItem
-
selectItems
Selects the items under the given indices.- Parameters:
list- the targetJList.indices- the indices of the items to select.- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if any of the indices is negative or greater than the index of the last item in theJList.
-
clearSelection
Clears the selection in the given. Since this method does not simulate user input, it does not verifies that theJListJListis enabled and showing.- Parameters:
list- the targetJList.- Since:
- 1.2
-
clearSelectionOf
-
selectItems
Selects the items in the specified range.- Parameters:
list- the targetJList.from- the starting point of the selection.to- the last item to select.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the any index is negative or greater than the index of the last item in theJList.
-
selectItems
Selects the items in the specified range.- Parameters:
list- the targetJList.start- the starting point of the selection.end- the last item to select (inclusive.)- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the any index is negative or greater than the index of the last item in theJList.
-
validateIndicesAndClearSelection
-
selectItem
Selects the item under the given index using left mouse button once.- Parameters:
list- the targetJList.index- the index of the item to click.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.
-
clickItem
Clicks the item under the given index, using the specified mouse button, the given number times.- Parameters:
list- the targetJList.index- the index of the item to click.button- the button to use.times- the number of times to click.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.
-
requireSelection
Verifies that the selected item in thematches the given value.JList- Parameters:
list- the targetJList.value- the value to match. It can be a regular expression pattern.- Throws:
AssertionError- if the selected item does not match the value.- See Also:
-
requireSelection
Verifies that the selected item in thematches the given regular expression pattern.JList- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.- Throws:
AssertionError- if the selected item does not match the given regular expression pattern.NullPointerException- if the given regular expression pattern isnull.- Since:
- 1.2
- See Also:
-
requiredSelection
-
requireSelection
Verifies that the selected index in thematches the given value.JList- Parameters:
list- the targetJList.index- the selection index to match.- Throws:
AssertionError- if the selected index does not match the value.- Since:
- 1.2
-
selectionOf
Returns an array ofStrings that represents the selection in the given, using this driver'sJList.JListCellReader- Parameters:
list- the targetJList.- Returns:
- an array of
Strings that represents the selection in the givenJList. - See Also:
-
requireSelectedItems
Verifies that the selected items in thematch the given values.JList- Parameters:
list- the targetJList.items- the values to match. Each value can be a regular expression pattern.- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.AssertionError- if the selected items do not match the given values.
-
requireSelectedItems
Verifies that the selected items in thematch the given regular expression patterns.JList- Parameters:
list- the targetJList.patterns- the regular expression patterns to match.- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.NullPointerException- if any of the patterns in the array isnull.AssertionError- if the selected items do not match the given values.- Since:
- 1.2
- See Also:
-
requireSelectedItems
-
requireSelectedItems
Verifies that the given item indices are selected in the.JList- Parameters:
list- the targetJList.indices- the expected indices of the selected items.- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.AssertionError- if the selection in theJListdoes not match the given one.
-
validateArrayOfIndices
private void validateArrayOfIndices(int[] indices) -
requireNoSelection
Verifies that thedoes not have a selection.JList- Parameters:
list- the targetJList.- Throws:
AssertionError- if theJListhas a selection.
-
failNoSelection
-
selectedIndexProperty
-
drag
Starts a drag operation at the location of the first item matching the given value.- Parameters:
list- the targetJList.value- the value to match. It can be a regular expression.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the given value cannot be found.- See Also:
-
drag
Starts a drag operation at the location of the first item matching the given regular expression pattern.- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.NullPointerException- if the regular expression pattern isnull.LocationUnavailableException- if an element matching the given regular expression pattern cannot be found.- Since:
- 1.2
- See Also:
-
drag
-
drop
Ends a drag operation at the location of the first item matching the given value.- Parameters:
list- the targetJList.value- the value to match. It can be a regular expression.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.LocationUnavailableException- if an element matching the given value cannot be found.ActionFailedException- if there is no drag action in effect.
-
drop
Ends a drag operation at the location of the first item matching the given regular expression pattern.- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.NullPointerException- if the given regular expression pattern isnull.LocationUnavailableException- if an element matching the given value cannot be found.ActionFailedException- if there is no drag action in effect.- Since:
- 1.2
-
drop
-
verify
-
drag
Starts a drag operation at the location of the given index.- Parameters:
list- the targetJList.index- the given index.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.
-
drop
Ends a drag operation at the location of the given index.- Parameters:
list- the targetJList.index- the given index.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.ActionFailedException- if there is no drag action in effect.
-
drop
Ends a drag operation at the center of the.JList- Parameters:
list- the targetJList.- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.ActionFailedException- if there is no drag action in effect.
-
showPopupMenu
Shows a pop-up menu at the location of the specified item in the.JList- Parameters:
list- the targetJList.value- the value to match. It can be a regular expression pattern.- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.ComponentLookupException- if a pop-up menu cannot be found.LocationUnavailableException- if an element matching the given value cannot be found.
-
showPopupMenu
Shows a pop-up menu at the location of the specified item in the.JList- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.NullPointerException- if the regular expression pattern isnull.ComponentLookupException- if a pop-up menu cannot be found.LocationUnavailableException- if an element matching the given value cannot be found.- Since:
- 1.2
-
showPopupMenu
-
cellCenterIn
-
showPopupMenu
Shows a pop-up menu at the location of the specified item in the.JList- Parameters:
list- the targetJList.index- the index of the item.- Returns:
- a driver that manages the displayed pop-up menu.
- Throws:
IllegalStateException- if theJListis disabled.IllegalStateException- if theJListis not showing on the screen.ComponentLookupException- if a pop-up menu cannot be found.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.
-
pointAt
Returns the coordinates of the first item matching the given value.- Parameters:
list- the targetJList.value- the value to match.- Returns:
- the coordinates of the item at the given item.
- Throws:
LocationUnavailableException- if an element matching the given value cannot be found.
-
indexOf
Returns the index of the first item matching the given value.- Parameters:
list- the targetJListvalue- the value to match. It can be a regular expression.- Returns:
- the index of the first item matching the given value.
- Throws:
LocationUnavailableException- if an element matching the given value cannot be found.
-
indexOf
Returns the index of the first item matching the given regular expression pattern.- Parameters:
list- the targetJList.pattern- the regular expression pattern to match.- Returns:
- the index of the first item matching the given regular expression pattern.
- Throws:
LocationUnavailableException- if an element matching the given value cannot be found.NullPointerException- if the given regular expression pattern isnull.- Since:
- 1.2
-
indexOf
-
itemIndex
@RunsInEDT private static int itemIndex(JList list, TextMatcher matcher, JListCellReader cellReader) -
failMatchingNotFound
-
value
Returns theStringrepresentation of the element under the given index, using this driver's.JListCellReader- Parameters:
list- the targetJList.index- the given index.- Returns:
- the value of the element under the given index.
- Throws:
IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJList.- See Also:
-
cellReader
Updates the implementation ofto use when comparing internal values of aJListCellReaderand the values expected in a test.JList- Parameters:
newCellReader- the newJListCellValueReaderto use.- Throws:
NullPointerException- ifnewCellReaderisnull.
-
requireItemCount
Verifies that number of items in the givenis equal to the expected one.JList- Parameters:
list- the targetJList.expected- the expected number of items.- Throws:
AssertionError- if the number of items in the givenis not equal to the expected one.JList- Since:
- 1.2
-