org.fest.swing.driver
Class JComboBoxDriver

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

public class JComboBoxDriver
extends JComponentDriver

Understands functional testing of JComboBoxes:

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
JComboBoxDriver(Robot robot)
          Creates a new JComboBoxDriver.
 
Method Summary
 void cellReader(JComboBoxCellReader newCellReader)
          Updates the implementation of JComboBoxCellReader to use when comparing internal values of a JComboBox and the values expected in a test.
 void clearSelection(JComboBox comboBox)
          Clears the selection in the given JComboBox.
 String[] contentsOf(JComboBox comboBox)
          Returns an array of Strings that represents the contents of the given JComboBox list.
 JList dropDownList()
          Find the JList in the pop-up raised by the JComboBox, if the LAF actually uses one.
 void enterText(JComboBox comboBox, String text)
          Simulates a user entering the specified text in the JComboBox.
 void pressAndReleaseKeys(JComboBox comboBox, int... keyCodes)
          Simulates a user pressing and releasing the given keys on the JComboBox.
 void replaceText(JComboBox comboBox, String text)
          Simulates a user entering the specified text in the JComboBox, replacing any text.
 void requireEditable(JComboBox comboBox)
          Asserts that the given JComboBox is editable.
 void requireItemCount(JComboBox comboBox, int expected)
          Verifies that number of items in the given JComboBox is equal to the expected one.
 void requireNoSelection(JComboBox comboBox)
          Verifies that the JComboBox does not have any selection.
 void requireNotEditable(JComboBox comboBox)
          Asserts that the given JComboBox is not editable.
 void requireSelection(JComboBox comboBox, int index)
          Verifies that the index of the selected item in the JComboBox is equal to the given value.
 void requireSelection(JComboBox comboBox, Pattern pattern)
          Verifies that the String representation of the selected item in the JComboBox matches the given regular expression pattern.
 void requireSelection(JComboBox comboBox, String value)
          Verifies that the String representation of the selected item in the JComboBox matches the given text.
 void selectAllText(JComboBox comboBox)
          Simulates a user selecting the text in the JComboBox.
 void selectItem(JComboBox comboBox, int index)
          Selects the item under the given index in the JComboBox.
 void selectItem(JComboBox comboBox, Pattern pattern)
          Selects the first item matching the given regular expression pattern in the JComboBox.
 void selectItem(JComboBox comboBox, String value)
          Selects the first item matching the given text in the JComboBox.
 String value(JComboBox comboBox, int index)
          Returns the String representation of the element under the given index, using this driver's JComboBoxCellReader.
 
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

JComboBoxDriver

public JComboBoxDriver(Robot robot)
Creates a new JComboBoxDriver.

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

contentsOf

@RunsInEDT
public String[] contentsOf(JComboBox comboBox)
Returns an array of Strings that represents the contents of the given JComboBox list. The String representation of each element is performed using this driver's JComboBoxCellReader.

Parameters:
comboBox - the target JComboBox.
Returns:
an array of Strings that represent the contents of the given JComboBox list.
See Also:
value(JComboBox, int), cellReader(JComboBoxCellReader)

selectItem

@RunsInEDT
public void selectItem(JComboBox comboBox,
                                 String value)
Selects the first item matching the given text in the JComboBox. The text of the JComboBox items is obtained by this fixture's JComboBoxCellReader.

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

selectItem

@RunsInEDT
public void selectItem(JComboBox comboBox,
                                 Pattern pattern)
Selects the first item matching the given regular expression pattern in the JComboBox. The text of the JComboBox items is obtained by this fixture's JComboBoxCellReader.

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

requireSelection

@RunsInEDT
public void requireSelection(JComboBox comboBox,
                                       String value)
Verifies that the String representation of the selected item in the JComboBox matches the given text.

Parameters:
comboBox - the target JComboBox.
value - the text to match. It can be a regular expression.
Throws:
AssertionError - if the selected item does not match the given value.
See Also:
cellReader(JComboBoxCellReader)

requireSelection

@RunsInEDT
public void requireSelection(JComboBox comboBox,
                                       Pattern pattern)
Verifies that the String representation of the selected item in the JComboBox matches the given regular expression pattern.

Parameters:
comboBox - the target JComboBox.
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(JComboBoxCellReader)

requireSelection

@RunsInEDT
public void requireSelection(JComboBox comboBox,
                                       int index)
Verifies that the index of the selected item in the JComboBox is equal to the given value.

Parameters:
comboBox - the target JComboBox.
index - the expected selection index.
Throws:
AssertionError - if the selection index is not equal to the given value.
Since:
1.2

requireNoSelection

@RunsInEDT
public void requireNoSelection(JComboBox comboBox)
Verifies that the JComboBox does not have any selection.

Parameters:
comboBox - the target JComboBox.
Throws:
AssertionError - if the JComboBox has a selection.

value

public String value(JComboBox comboBox,
                    int index)
Returns the String representation of the element under the given index, using this driver's JComboBoxCellReader.

Parameters:
comboBox - the target JComboBox.
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 JComboBox.
See Also:
cellReader(JComboBoxCellReader)

clearSelection

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

Parameters:
comboBox - the target JComboBox.
Since:
1.2

selectItem

@RunsInEDT
public void selectItem(JComboBox comboBox,
                                 int index)
Selects the item under the given index in the JComboBox.

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

replaceText

@RunsInEDT
public void replaceText(JComboBox comboBox,
                                  String text)
Simulates a user entering the specified text in the JComboBox, replacing any text. This action is executed only if the JComboBox is editable.

Parameters:
comboBox - the target JComboBox.
text - the text to enter.
Throws:
IllegalStateException - if the JComboBox is disabled.
IllegalStateException - if the JComboBox is not showing on the screen.
IllegalStateException - if the JComboBox is not editable.

selectAllText

@RunsInEDT
public void selectAllText(JComboBox comboBox)
Simulates a user selecting the text in the JComboBox. This action is executed only if the JComboBox is editable.

Parameters:
comboBox - the target JComboBox.
Throws:
IllegalStateException - if the JComboBox is disabled.
IllegalStateException - if the JComboBox is not showing on the screen.
IllegalStateException - if the JComboBox is not editable.

enterText

@RunsInEDT
public void enterText(JComboBox comboBox,
                                String text)
Simulates a user entering the specified text in the JComboBox. This action is executed only if the JComboBox is editable.

Parameters:
comboBox - the target JComboBox.
text - the text to enter.
Throws:
IllegalStateException - if the JComboBox is disabled.
IllegalStateException - if the JComboBox is not showing on the screen.
IllegalStateException - if the JComboBox is not editable.
ActionFailedException - if the JComboBox does not have an editor.

pressAndReleaseKeys

@RunsInEDT
public void pressAndReleaseKeys(JComboBox comboBox,
                                          int... keyCodes)
Simulates a user pressing and releasing the given keys on the JComboBox.

Parameters:
comboBox - the target JComboBox.
keyCodes - one or more codes of the keys to press.
Throws:
NullPointerException - if the given array of codes is null.
IllegalStateException - if the JComboBox is disabled.
IllegalStateException - if the JComboBox is not showing on the screen.
IllegalArgumentException - if the given code is not a valid key code.
See Also:
KeyEvent

dropDownList

@RunsInEDT
public JList dropDownList()
Find the JList in the pop-up raised by the JComboBox, if the LAF actually uses one.

Returns:
the found JList.
Throws:
ComponentLookupException - if the JList in the pop-up could not be found.

requireEditable

@RunsInEDT
public void requireEditable(JComboBox comboBox)
Asserts that the given JComboBox is editable.

Parameters:
comboBox - the target JComboBox.
Throws:
AssertionError - if the JComboBox is not editable.

requireNotEditable

@RunsInEDT
public void requireNotEditable(JComboBox comboBox)
Asserts that the given JComboBox is not editable.

Parameters:
comboBox - the given JComboBox.
Throws:
AssertionError - if the JComboBox is editable.

cellReader

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

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

requireItemCount

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

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


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