org.fest.swing.driver
Class JListDriver

java.lang.Object
  extended by org.fest.swing.driver.ComponentDriver
      extended by org.fest.swing.driver.ContainerDriver
          extended by org.fest.swing.driver.JComponentDriver
              extended by org.fest.swing.driver.JListDriver

public class JListDriver
extends JComponentDriver

Understands functional testing of JLists:

This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.

Author:
Alex Ruiz, Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
 
Constructor Summary
JListDriver(Robot robot)
          Creates a new JListDriver.
 
Method Summary
 void cellReader(JListCellReader newCellReader)
          Updates the implementation of JListCellReader to use when comparing internal values of a JList and the values expected in a test.
 void clearSelection(JList list)
          Clears the selection in the given JList.
 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, 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.
 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.
 String[] contentsOf(JList list)
          Returns an array of Strings that represents the contents of the given JList, using this driver's JListCellReader.
 void drag(JList list, int index)
          Starts a drag operation at the location of the given index.
 void drag(JList list, Pattern pattern)
          Starts a drag operation at the location of the first item matching the given regular expression pattern.
 void drag(JList list, String value)
          Starts a drag operation at the location of the first item matching the given value.
 void drop(JList list)
          Ends a drag operation at the center of the JList.
 void drop(JList list, int index)
          Ends a drag operation at the location of the given index.
 void drop(JList list, Pattern pattern)
          Ends a drag operation at the location of the first item matching the given regular expression pattern.
 void drop(JList list, String value)
          Ends a drag operation at the location of the first item matching the given value.
 int indexOf(JList list, Pattern pattern)
          Returns the index of the first item matching the given regular expression pattern.
 int indexOf(JList list, String value)
          Returns the index of the first item matching the given value.
 Point pointAt(JList list, String value)
          Returns the coordinates of the first item matching the given value.
 void requireItemCount(JList list, int expected)
          Verifies that number of items in the given JList is equal to the expected one.
 void requireNoSelection(JList list)
          Verifies that the JList does not have a selection.
 void requireSelectedItems(JList list, int... indices)
          Verifies that the given item indices are selected in the JList.
 void requireSelectedItems(JList list, Pattern... patterns)
          Verifies that the selected items in the JList match the given regular expression patterns.
 void requireSelectedItems(JList list, String... items)
          Verifies that the selected items in the JList match the given values.
 void requireSelection(JList list, int index)
          Verifies that the selected index in the JList matches the given value.
 void requireSelection(JList list, Pattern pattern)
          Verifies that the selected item in the JList matches the given regular expression pattern.
 void requireSelection(JList list, String value)
          Verifies that the selected item in the JList matches the given value.
 String[] selectionOf(JList list)
          Returns an array of Strings that represents the selection in the given JList, using this driver's JListCellReader.
 void selectItem(JList list, int index)
          Selects the item under the given index using left mouse button once.
 void selectItem(JList list, Pattern pattern)
          Selects the item in the given JList whose value matches the given regular expression pattern.
 void selectItem(JList list, String value)
          Selects the item in the given JList whose value matches the given one.
 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, 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.
 void selectItems(JList list, String[] values)
          Selects the items matching the given values.
 JPopupMenu showPopupMenu(JList list, int index)
          Shows a pop-up menu at the location of the specified item in the JList.
 JPopupMenu showPopupMenu(JList list, Pattern pattern)
          Shows a pop-up menu at the location of the specified item in the JList.
 JPopupMenu showPopupMenu(JList list, String value)
          Shows a pop-up menu at the location of the specified item in the JList.
 String value(JList list, int index)
          Returns the String representation of the element under the given index, using this driver's JListCellReader.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JListDriver

public JListDriver(Robot robot)
Creates a new JListDriver.

Parameters:
robot - the robot to use to simulate user input.
Method Detail

contentsOf

@RunsInEDT
public String[] contentsOf(JList list)
Returns an array of Strings that represents the contents of the given JList, using this driver's JListCellReader.

Parameters:
list - the target JList.
Returns:
an array of Strings that represents the contents of the given JList.
See Also:
cellReader(JListCellReader)

selectItems

@RunsInEDT
public void selectItems(JList list,
                                  String[] values)
Selects the items matching the given values.

Parameters:
list - the target JList.
values - the values to match. Each String can be a regular expression.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
LocationUnavailableException - if an element matching the any of the given values cannot be found.

selectItems

@RunsInEDT
public void selectItems(JList list,
                                  Pattern[] patterns)
Selects the items matching the given regular expression patterns.

Parameters:
list - the target JList.
patterns - the regular expression patterns to match.
Throws:
NullPointerException - if the given array is null.
NullPointerException - if any of the regular expression patterns is null.
IllegalArgumentException - if the given array is empty.
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList 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

selectItem

@RunsInEDT
public void selectItem(JList list,
                                 String value)
Selects the item in the given JList whose value matches the given one.

Parameters:
list - the target JList.
value - the value to match.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
LocationUnavailableException - if an element matching the given value cannot be found.

selectItem

@RunsInEDT
public void selectItem(JList list,
                                 Pattern pattern)
Selects the item in the given JList whose value matches the given regular expression pattern.

Parameters:
list - the target JList.
pattern - the regular expression to match.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
LocationUnavailableException - if an element matching the given value cannot be found.
NullPointerException - if the given regular expression pattern is null.
Since:
1.2

clickItem

public 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.

Parameters:
list - the target JList.
value - the value to match.
button - the button to use.
times - the number of times to click.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
LocationUnavailableException - if an element matching the given value cannot be found.

clickItem

public 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.

Parameters:
list - the target JList.
pattern - the regular expression pattern to match.
button - the button to use.
times - the number of times to click.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
NullPointerException - if the given regular expression pattern is null.
LocationUnavailableException - if an element matching the given regular expression pattern cannot be found.
Since:
1.2

selectItems

public void selectItems(JList list,
                        int[] indices)
Selects the items under the given indices.

Parameters:
list - the target JList.
indices - the indices of the items to select.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if any of the indices is negative or greater than the index of the last item in the JList.

clearSelection

public void clearSelection(JList list)
Clears the selection in the given JList. Since this method does not simulate user input, it does not verifies that the JList is enabled and showing.

Parameters:
list - the target JList.
Since:
1.2

selectItems

@RunsInEDT
public void selectItems(JList list,
                                  Range.From from,
                                  Range.To to)
Selects the items in the specified range.

Parameters:
list - the target JList.
from - the starting point of the selection.
to - the last item to select.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the any index is negative or greater than the index of the last item in the JList.

selectItems

@RunsInEDT
public void selectItems(JList list,
                                  int start,
                                  int end)
Selects the items in the specified range.

Parameters:
list - the target JList.
start - the starting point of the selection.
end - the last item to select (inclusive.)
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the any index is negative or greater than the index of the last item in the JList.

selectItem

@RunsInEDT
public void selectItem(JList list,
                                 int index)
Selects the item under the given index using left mouse button once.

Parameters:
list - the target JList.
index - the index of the item to click.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.

clickItem

@RunsInEDT
public 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.

Parameters:
list - the target JList.
index - the index of the item to click.
button - the button to use.
times - the number of times to click.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.

requireSelection

@RunsInEDT
public void requireSelection(JList list,
                                       String value)
Verifies that the selected item in the JList matches the given value.

Parameters:
list - the target JList.
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:
cellReader(JListCellReader)

requireSelection

@RunsInEDT
public void requireSelection(JList list,
                                       Pattern pattern)
Verifies that the selected item in the JList matches the given regular expression pattern.

Parameters:
list - the target JList.
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 is null.
Since:
1.2
See Also:
cellReader(JListCellReader)

requireSelection

@RunsInEDT
public void requireSelection(JList list,
                                       int index)
Verifies that the selected index in the JList matches the given value.

Parameters:
list - the target JList.
index - the selection index to match.
Throws:
AssertionError - if the selected index does not match the value.
Since:
1.2

selectionOf

@RunsInEDT
public String[] selectionOf(JList list)
Returns an array of Strings that represents the selection in the given JList, using this driver's JListCellReader.

Parameters:
list - the target JList.
Returns:
an array of Strings that represents the selection in the given JList.
See Also:
cellReader(JListCellReader)

requireSelectedItems

@RunsInEDT
public void requireSelectedItems(JList list,
                                           String... items)
Verifies that the selected items in the JList match the given values.

Parameters:
list - the target JList.
items - the values to match. Each value can be a regular expression pattern.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
AssertionError - if the selected items do not match the given values.

requireSelectedItems

@RunsInEDT
public void requireSelectedItems(JList list,
                                           Pattern... patterns)
Verifies that the selected items in the JList match the given regular expression patterns.

Parameters:
list - the target JList.
patterns - the regular expression patterns to match.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
NullPointerException - if any of the patterns in the array is null.
AssertionError - if the selected items do not match the given values.
Since:
1.2
See Also:
cellReader(JListCellReader)

requireSelectedItems

@RunsInEDT
public void requireSelectedItems(JList list,
                                           int... indices)
Verifies that the given item indices are selected in the JList.

Parameters:
list - the target JList.
indices - the expected indices of the selected items.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
AssertionError - if the selection in the JList does not match the given one.

requireNoSelection

@RunsInEDT
public void requireNoSelection(JList list)
Verifies that the JList does not have a selection.

Parameters:
list - the target JList.
Throws:
AssertionError - if the JList has a selection.

drag

@RunsInEDT
public void drag(JList list,
                           String value)
Starts a drag operation at the location of the first item matching the given value.

Parameters:
list - the target JList.
value - the value to match. It can be a regular expression.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
LocationUnavailableException - if an element matching the given value cannot be found.
See Also:
cellReader(JListCellReader)

drag

@RunsInEDT
public void drag(JList list,
                           Pattern pattern)
Starts a drag operation at the location of the first item matching the given regular expression pattern.

Parameters:
list - the target JList.
pattern - the regular expression pattern to match.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
NullPointerException - if the regular expression pattern is null.
LocationUnavailableException - if an element matching the given regular expression pattern cannot be found.
Since:
1.2
See Also:
cellReader(JListCellReader)

drop

@RunsInEDT
public void drop(JList list,
                           String value)
Ends a drag operation at the location of the first item matching the given value.

Parameters:
list - the target JList.
value - the value to match. It can be a regular expression.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList 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

public void drop(JList list,
                 Pattern pattern)
Ends a drag operation at the location of the first item matching the given regular expression pattern.

Parameters:
list - the target JList.
pattern - the regular expression pattern to match.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
NullPointerException - if the given regular expression pattern is null.
LocationUnavailableException - if an element matching the given value cannot be found.
ActionFailedException - if there is no drag action in effect.
Since:
1.2

drag

@RunsInEDT
public void drag(JList list,
                           int index)
Starts a drag operation at the location of the given index.

Parameters:
list - the target JList.
index - the given index.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.

drop

@RunsInEDT
public void drop(JList list,
                           int index)
Ends a drag operation at the location of the given index.

Parameters:
list - the target JList.
index - the given index.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
ActionFailedException - if there is no drag action in effect.

drop

@RunsInEDT
public void drop(JList list)
Ends a drag operation at the center of the JList.

Parameters:
list - the target JList.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
ActionFailedException - if there is no drag action in effect.

showPopupMenu

@RunsInEDT
public JPopupMenu showPopupMenu(JList list,
                                          String value)
Shows a pop-up menu at the location of the specified item in the JList.

Parameters:
list - the target JList.
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 the JList is disabled.
IllegalStateException - if the JList 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

@RunsInEDT
public JPopupMenu showPopupMenu(JList list,
                                          Pattern pattern)
Shows a pop-up menu at the location of the specified item in the JList.

Parameters:
list - the target JList.
pattern - the regular expression pattern to match.
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList is not showing on the screen.
NullPointerException - if the regular expression pattern is null.
ComponentLookupException - if a pop-up menu cannot be found.
LocationUnavailableException - if an element matching the given value cannot be found.
Since:
1.2

showPopupMenu

@RunsInEDT
public JPopupMenu showPopupMenu(JList list,
                                          int index)
Shows a pop-up menu at the location of the specified item in the JList.

Parameters:
list - the target JList.
index - the index of the item.
Returns:
a driver that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JList is disabled.
IllegalStateException - if the JList 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 the JList.

pointAt

@RunsInEDT
public Point pointAt(JList list,
                               String value)
Returns the coordinates of the first item matching the given value.

Parameters:
list - the target JList.
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

@RunsInEDT
public int indexOf(JList list,
                             String value)
Returns the index of the first item matching the given value.

Parameters:
list - the target JList
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

@RunsInEDT
public int indexOf(JList list,
                             Pattern pattern)
Returns the index of the first item matching the given regular expression pattern.

Parameters:
list - the target JList.
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 is null.
Since:
1.2

value

@RunsInEDT
public String value(JList list,
                              int index)
Returns the String representation of the element under the given index, using this driver's JListCellReader.

Parameters:
list - the target JList.
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 the JList.
See Also:
cellReader(JListCellReader)

cellReader

public void cellReader(JListCellReader newCellReader)
Updates the implementation of JListCellReader to use when comparing internal values of a JList and the values expected in a test.

Parameters:
newCellReader - the new JListCellValueReader to use.
Throws:
NullPointerException - if newCellReader is null.

requireItemCount

@RunsInEDT
public void requireItemCount(JList list,
                                       int expected)
Verifies that number of items in the given JList is equal to the expected one.

Parameters:
list - the target JList.
expected - the expected number of items.
Throws:
AssertionError - if the number of items in the given JList is not equal to the expected one.
Since:
1.2


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.