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
JList
s:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JListCellReader
private static final String
private static final String
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Point
cellCenterIn
(Pair<Integer, Point> scrollInfo) void
cellReader
(JListCellReader newCellReader) Updates the implementation of
to use when comparing internal values of aJListCellReader
and the values expected in a test.JList
void
clearSelection
(JList list) Clears the selection in the given
.JList
private static void
clearSelectionOf
(JList list) void
clickItem
(JList list, int index, MouseButton button, int times) Clicks the item under the given index, using the specified mouse button, the given number times.void
clickItem
(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.void
clickItem
(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 void
clickItem
(JList list, TextMatcher matcher, MouseButton button, int times) String[]
contentsOf
(JList list) Returns an array ofString
s that represents the contents of the given
, using this driver'sJList
.JListCellReader
void
Starts a drag operation at the location of the given index.void
Starts a drag operation at the location of the first item matching the given value.void
Starts a drag operation at the location of the first item matching the given regular expression pattern.private void
drag
(JList list, TextMatcher matcher) void
Ends a drag operation at the center of the
.JList
void
Ends a drag operation at the location of the given index.void
Ends a drag operation at the location of the first item matching the given value.void
Ends a drag operation at the location of the first item matching the given regular expression pattern.private void
drop
(JList list, TextMatcher matcher) private LocationUnavailableException
failMatchingNotFound
(JList list, TextMatcher matcher) private void
failNoSelection
(JList list) int
Returns the index of the first item matching the given value.int
Returns the index of the first item matching the given regular expression pattern.private int
indexOf
(JList list, TextMatcher matcher) private static int
itemIndex
(JList list, TextMatcher matcher, JListCellReader cellReader) Returns the coordinates of the first item matching the given value.private String
requiredSelection
(JList list) void
requireItemCount
(JList list, int expected) Verifies that number of items in the given
is equal to the expected one.JList
void
requireNoSelection
(JList list) Verifies that the
does not have a selection.JList
void
requireSelectedItems
(JList list, int... indices) Verifies that the given item indices are selected in the
.JList
void
requireSelectedItems
(JList list, String... items) Verifies that the selected items in the
match the given values.JList
void
requireSelectedItems
(JList list, Pattern... patterns) Verifies that the selected items in the
match the given regular expression patterns.JList
private void
requireSelectedItems
(JList list, TextMatcher matcher) void
requireSelection
(JList list, int index) Verifies that the selected index in the
matches the given value.JList
void
requireSelection
(JList list, String value) Verifies that the selected item in the
matches the given value.JList
void
requireSelection
(JList list, Pattern pattern) Verifies that the selected item in the
matches the given regular expression pattern.JList
private org.fest.assertions.Description
selectedIndexProperty
(JList list) String[]
selectionOf
(JList list) Returns an array ofString
s that represents the selection in the given
, using this driver'sJList
.JListCellReader
void
selectItem
(JList list, int index) Selects the item under the given index using left mouse button once.void
selectItem
(JList list, String value) Selects the item in the given
whose value matches the given one.JList
void
selectItem
(JList list, Pattern pattern) Selects the item in the given
whose value matches the given regular expression pattern.JList
private void
selectItem
(JList list, TextMatcher matcher) void
selectItems
(JList list, int[] indices) Selects the items under the given indices.void
selectItems
(JList list, int start, int end) Selects the items in the specified range.void
selectItems
(JList list, String[] values) Selects the items matching the given values.void
selectItems
(JList list, Pattern[] patterns) Selects the items matching the given regular expression patterns.void
selectItems
(JList list, Range.From from, Range.To to) Selects the items in the specified range.private void
selectItems
(JList list, TextMatcher matcher) showPopupMenu
(JList list, int index) Shows a pop-up menu at the location of the specified item in the
.JList
showPopupMenu
(JList list, String value) Shows a pop-up menu at the location of the specified item in the
.JList
showPopupMenu
(JList list, Pattern pattern) Shows a pop-up menu at the location of the specified item in the
.JList
private JPopupMenu
showPopupMenu
(JList list, TextMatcher matcher) private void
validateArrayOfIndices
(int[] indices) private static void
validateIndicesAndClearSelection
(JList list, int... indices) Returns theString
representation of the element under the given index, using this driver's
.JListCellReader
private void
Methods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
Methods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidth
Methods 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 ofString
s that represents the contents of the given
, using this driver'sJList
.JListCellReader
- Parameters:
list
- the targetJList
.- Returns:
- an array of
String
s 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. EachString
can be a regular expression.- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.IllegalStateException
- if theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 given
whose value matches the given one.JList
- Parameters:
list
- the targetJList
.value
- the value to match.- Throws:
IllegalStateException
- if theJList
is disabled.IllegalStateException
- if theJList
is not showing on the screen.LocationUnavailableException
- if an element matching the given value cannot be found.
-
selectItem
Selects the item in the given
whose value matches the given regular expression pattern.JList
- Parameters:
list
- the targetJList
.pattern
- the regular expression to match.- Throws:
IllegalStateException
- if theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
JList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 the
matches 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 the
matches 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 the
matches 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 ofString
s that represents the selection in the given
, using this driver'sJList
.JListCellReader
- Parameters:
list
- the targetJList
.- Returns:
- an array of
String
s that represents the selection in the givenJList
. - See Also:
-
requireSelectedItems
Verifies that the selected items in the
match 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 the
match 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 theJList
does not match the given one.
-
validateArrayOfIndices
private void validateArrayOfIndices(int[] indices) -
requireNoSelection
Verifies that the
does not have a selection.JList
- Parameters:
list
- the targetJList
.- Throws:
AssertionError
- if theJList
has 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 theJList
is disabled.IllegalStateException
- if theJList
is 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 targetJList
value
- 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 theString
representation 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 of
to use when comparing internal values of aJListCellReader
and the values expected in a test.JList
- Parameters:
newCellReader
- the newJListCellValueReader
to use.- Throws:
NullPointerException
- ifnewCellReader
isnull
.
-
requireItemCount
Verifies that number of items in the given
is 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 given
is not equal to the expected one.JList
- Since:
- 1.2
-