org.fest.swing.fixture
Class JComboBoxFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JComboBox>
      extended by org.fest.swing.fixture.JComboBoxFixture
All Implemented Interfaces:
ClientPropertyStorageFixture, CommonComponentFixture, EditableComponentFixture, FocusableComponentFixture, ItemGroupFixture, JComponentFixture, JPopupMenuInvokerFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture, ToolTipDisplayFixture

public class JComboBoxFixture
extends ComponentFixture<JComboBox>
implements CommonComponentFixture, EditableComponentFixture, ItemGroupFixture, JComponentFixture, JPopupMenuInvokerFixture

Understands functional testing of JComboBoxes:

The conversion between the values given in tests and the values being displayed by a JComboBox renderer is performed by a JComboBoxCellReader. This fixture uses a JComboBoxCellReader by default.

Author:
Alex Ruiz, Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JComboBoxFixture(Robot robot, JComboBox target)
          Creates a new JComboBoxFixture.
JComboBoxFixture(Robot robot, String comboBoxName)
          Creates a new JComboBoxFixture.
 
Method Summary
 JComboBoxFixture cellReader(JComboBoxCellReader cellReader)
          Updates the implementation of JComboBoxCellReader to use when comparing internal values of this fixture's JComboBox and the values expected in a test.
 JComboBoxFixture clearSelection()
          Clears the selection in this fixture's JComboBox.
 JComboBoxFixture click()
          Simulates a user clicking this fixture's JComboBox.
 JComboBoxFixture click(MouseButton button)
          Simulates a user clicking this fixture's JComboBox.
 JComboBoxFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JComboBox.
 Object clientProperty(Object key)
          Returns the client property stored in this fixture's JComboBox, under the given key.
 String[] contents()
          Returns the String representation of the elements in this fixture's JComboBox, using this fixture's JComboBoxCellReader.
 JComboBoxFixture doubleClick()
          Simulates a user double-clicking this fixture's JComboBox.
protected  void driver(JComboBoxDriver newDriver)
          Sets the JComboBoxDriver to be used by this fixture.
 JComboBoxFixture enterText(String text)
          Simulates a user entering the specified text in this fixture's JComboBox.
 JComboBoxFixture focus()
          Gives input focus to this fixture's JComboBox.
 JList list()
          Finds and returns the JList in the pop-up raised by this fixture's JComboBox.
 JComboBoxFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JComboBox.
 JComboBoxFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's JComboBox.
 JComboBoxFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JComboBox.
 JComboBoxFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JComboBox.
 JComboBoxFixture replaceText(String text)
          Simulates a user entering the specified text in the JComboBox, replacing any text.
 JComboBoxFixture requireDisabled()
          Asserts that this fixture's JComboBox is disabled.
 JComboBoxFixture requireEditable()
          Asserts that this fixture's JComboBox is editable.
 JComboBoxFixture requireEnabled()
          Asserts that this fixture's JComboBox is enabled.
 JComboBoxFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JComboBox is enabled.
 JComboBoxFixture requireFocused()
          Asserts that this fixture's JComboBox has input focus.
 JComboBoxFixture requireItemCount(int expected)
          Verifies that this fixture's JComboBox has the expected number of items
 JComboBoxFixture requireNoSelection()
          Verifies that this fixture's JComboBox does not have any selection.
 JComboBoxFixture requireNotEditable()
          Asserts that this fixture's JComboBox is not editable.
 JComboBoxFixture requireNotVisible()
          Asserts that this fixture's JComboBox is not visible.
 JComboBoxFixture requireSelection(int index)
          Verifies that the index of the selected item in this fixture's JComboBox is equal to the given value.
 JComboBoxFixture requireSelection(Pattern pattern)
          Verifies that the String representation of the selected item in this fixture's JComboBox matches the given regular expression pattern.
 JComboBoxFixture requireSelection(String value)
          Verifies that the String representation of the selected item in this fixture's JComboBox matches the given text.
 JComboBoxFixture requireToolTip(Pattern pattern)
          Asserts that the toolTip in this fixture's JComboBox matches the given regular expression pattern.
 JComboBoxFixture requireToolTip(String expected)
          Asserts that the toolTip in this fixture's JComboBox matches the given value.
 JComboBoxFixture requireVisible()
          Asserts that this fixture's JComboBox is visible.
 JComboBoxFixture rightClick()
          Simulates a user right-clicking this fixture's JComboBox.
 JComboBoxFixture selectAllText()
          Simulates a user selecting the text in the JComboBox.
 JComboBoxFixture selectItem(int index)
          Simulates a user selecting an item in this fixture's JComboBox.
 JComboBoxFixture selectItem(Pattern pattern)
          Simulates a user selecting an item in this fixture's JComboBox.
 JComboBoxFixture selectItem(String text)
          Simulates a user selecting an item in this fixture's JComboBox.
 JPopupMenuFixture showPopupMenu()
          Shows a pop-up menu using this fixture's JComboBox as the invoker of the pop-up menu.
 JPopupMenuFixture showPopupMenuAt(Point p)
          Shows a pop-up menu at the given point using this fixture's JComboBox as the invoker of the pop-up menu.
 String valueAt(int index)
          Returns the String representation of the value of an item in this fixture's JComboBox, using this fixture's JComboBoxCellReader.
 
Methods inherited from class org.fest.swing.fixture.ComponentFixture
background, component, font, foreground, requireShowing, targetCastedTo, validateNotNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JComboBoxFixture

public JComboBoxFixture(Robot robot,
                        JComboBox target)
Creates a new JComboBoxFixture.

Parameters:
robot - performs simulation of user events on the given JComboBox.
target - the JComboBox to be managed by this fixture.
Throws:
NullPointerException - if robot is null.
NullPointerException - if target is null.

JComboBoxFixture

public JComboBoxFixture(Robot robot,
                        String comboBoxName)
Creates a new JComboBoxFixture.

Parameters:
robot - performs simulation of user events on a JComboBox.
comboBoxName - the name of the JComboBox to find using the given Robot.
Throws:
NullPointerException - if robot is null.
ComponentLookupException - if a matching JComboBox could not be found.
ComponentLookupException - if more than one matching JComboBox is found.
Method Detail

driver

protected final void driver(JComboBoxDriver newDriver)
Sets the JComboBoxDriver to be used by this fixture.

Parameters:
newDriver - the new JComboBoxDriver.
Throws:
NullPointerException - if the given driver is null.

click

public JComboBoxFixture click()
Simulates a user clicking this fixture's JComboBox.

Specified by:
click in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

click

public JComboBoxFixture click(MouseButton button)
Simulates a user clicking this fixture's JComboBox.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
button - the button to click.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseButton is null.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

click

public JComboBoxFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JComboBox.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
mouseClickInfo - specifies the button to click and the times the button should be clicked.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

doubleClick

public JComboBoxFixture doubleClick()
Simulates a user double-clicking this fixture's JComboBox.

Specified by:
doubleClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

rightClick

public JComboBoxFixture rightClick()
Simulates a user right-clicking this fixture's JComboBox.

Specified by:
rightClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

contents

public String[] contents()
Returns the String representation of the elements in this fixture's JComboBox, using this fixture's JComboBoxCellReader.

Specified by:
contents in interface ItemGroupFixture
Returns:
the String representation of the elements in this fixture's JComboBox.
See Also:
cellReader(JComboBoxCellReader)

replaceText

public JComboBoxFixture replaceText(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:
text - the text to enter.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
IllegalStateException - if this fixture's JComboBox is not editable.

selectAllText

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

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
IllegalStateException - if this fixture's JComboBox is not editable.

enterText

public JComboBoxFixture enterText(String text)
Simulates a user entering the specified text in this fixture's JComboBox. This action is executed only if the JComboBox is editable.

Parameters:
text - the text to enter.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
IllegalStateException - if this fixture's JComboBox is not editable.
ActionFailedException - if this fixture's JComboBox does not have an editor.

focus

public JComboBoxFixture focus()
Gives input focus to this fixture's JComboBox.

Specified by:
focus in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.

list

public JList list()
Finds and returns the JList in the pop-up raised by this fixture's JComboBox.

Returns:
the JList in the pop-up raised by this fixture's JComboBox.
Throws:
ComponentLookupException - if the JList in the pop-up could not be found.

pressAndReleaseKey

public JComboBoxFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's JComboBox. Modifiers is a mask from the available InputEvent masks.

Specified by:
pressAndReleaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyPressInfo - specifies the key and modifiers to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given KeyPressInfo is null.
IllegalArgumentException - if the given code is not a valid key code.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
See Also:
KeyPressInfo

pressAndReleaseKeys

public JComboBoxFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys on this fixture's JComboBox.

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - one or more codes of the keys to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given array of codes is null.
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
See Also:
KeyEvent

pressKey

public JComboBoxFixture pressKey(int keyCode)
Simulates a user pressing the given key on this fixture's JComboBox.

Specified by:
pressKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to press.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
See Also:
KeyEvent

releaseKey

public JComboBoxFixture releaseKey(int keyCode)
Simulates a user releasing the given key on this fixture's JComboBox.

Specified by:
releaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to release.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
See Also:
KeyEvent

clearSelection

public JComboBoxFixture clearSelection()
Clears the selection in this fixture's JComboBox. Since this method does not simulate user input, it does not verifies that this fixture's JComboBox is enabled and showing.

Specified by:
clearSelection in interface ItemGroupFixture
Returns:
this fixture.
Since:
1.2

selectItem

public JComboBoxFixture selectItem(int index)
Simulates a user selecting an item in this fixture's JComboBox.

Specified by:
selectItem in interface ItemGroupFixture
Parameters:
index - the index of the item to select.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's 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.

selectItem

public JComboBoxFixture selectItem(String text)
Simulates a user selecting an item in this fixture's JComboBox. The text of the item to select must match the given String. Such text is retrieved by this fixture's JComboBoxCellReader.

Specified by:
selectItem in interface ItemGroupFixture
Parameters:
text - the text of the item to select. It can be a regular expression.
Returns:
this fixture.
Throws:
LocationUnavailableException - if an element matching the given text cannot be found.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
See Also:
cellReader(JComboBoxCellReader)

selectItem

public JComboBoxFixture selectItem(Pattern pattern)
Simulates a user selecting an item in this fixture's JComboBox. The text of the item to select must match the given regular expression pattern. Such text is retrieved by this fixture's JComboBoxCellReader.

Specified by:
selectItem in interface ItemGroupFixture
Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
LocationUnavailableException - if an element matching the given pattern cannot be found.
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
NullPointerException - if the given regular expression pattern is null.
Since:
1.2
See Also:
cellReader(JComboBoxCellReader)

valueAt

public String valueAt(int index)
Returns the String representation of the value of an item in this fixture's JComboBox, using this fixture's JComboBoxCellReader.

Specified by:
valueAt in interface ItemGroupFixture
Parameters:
index - the index of the item to return.
Returns:
the String representation of the value of an item in this fixture's JComboBox.
Throws:
IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JComboBox.
See Also:
cellReader(JComboBoxCellReader)

requireEnabled

public JComboBoxFixture requireEnabled()
Asserts that this fixture's JComboBox is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is disabled.

requireFocused

public JComboBoxFixture requireFocused()
Asserts that this fixture's JComboBox has input focus.

Specified by:
requireFocused in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox does not have input focus.

requireEnabled

public JComboBoxFixture requireEnabled(Timeout timeout)
Asserts that this fixture's JComboBox is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Parameters:
timeout - the time this fixture will wait for the component to be enabled.
Returns:
this fixture.
Throws:
WaitTimedOutError - if this fixture's JComboBox is never enabled.

requireDisabled

public JComboBoxFixture requireDisabled()
Asserts that this fixture's JComboBox is disabled.

Specified by:
requireDisabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is enabled.

requireVisible

public JComboBoxFixture requireVisible()
Asserts that this fixture's JComboBox is visible.

Specified by:
requireVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is not visible.

requireNotVisible

public JComboBoxFixture requireNotVisible()
Asserts that this fixture's JComboBox is not visible.

Specified by:
requireNotVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is visible.

requireEditable

public JComboBoxFixture requireEditable()
Asserts that this fixture's JComboBox is editable.

Specified by:
requireEditable in interface EditableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is not editable.

requireNotEditable

public JComboBoxFixture requireNotEditable()
Asserts that this fixture's JComboBox is not editable.

Specified by:
requireNotEditable in interface EditableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox is editable.

requireSelection

public JComboBoxFixture requireSelection(String value)
Verifies that the String representation of the selected item in this fixture's JComboBox matches the given text.

Specified by:
requireSelection in interface ItemGroupFixture
Parameters:
value - the text to match. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the selected item does not match the given text.
See Also:
cellReader(JComboBoxCellReader)

requireItemCount

public JComboBoxFixture requireItemCount(int expected)
Verifies that this fixture's JComboBox has the expected number of items

Specified by:
requireItemCount in interface ItemGroupFixture
Parameters:
expected - the expected number of items.
Returns:
this fixture.
Throws:
AssertionError - if the number of items in this fixture's JComboBox is not equal to the expected one.
Since:
1.2

requireSelection

public JComboBoxFixture requireSelection(Pattern pattern)
Verifies that the String representation of the selected item in this fixture's JComboBox matches the given regular expression pattern.

Specified by:
requireSelection in interface ItemGroupFixture
Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the selected item does not match the given regular expression pattern.
Since:
1.2
See Also:
cellReader(JComboBoxCellReader)

requireSelection

public JComboBoxFixture requireSelection(int index)
Verifies that the index of the selected item in this fixture's JComboBox is equal to the given value.

Specified by:
requireSelection in interface ItemGroupFixture
Parameters:
index - the expected selection index.
Returns:
this fixture.
Throws:
AssertionError - if the selected index is not equal to the given one.
Since:
1.2

requireNoSelection

public JComboBoxFixture requireNoSelection()
Verifies that this fixture's JComboBox does not have any selection.

Specified by:
requireNoSelection in interface ItemGroupFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JComboBox has a selection.

requireToolTip

public JComboBoxFixture requireToolTip(String expected)
Asserts that the toolTip in this fixture's JComboBox matches the given value.

Specified by:
requireToolTip in interface ToolTipDisplayFixture
Parameters:
expected - the given value. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the toolTip in this fixture's JComboBox does not match the given value.
Since:
1.2

requireToolTip

public JComboBoxFixture requireToolTip(Pattern pattern)
Asserts that the toolTip in this fixture's JComboBox matches the given regular expression pattern.

Specified by:
requireToolTip in interface ToolTipDisplayFixture
Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the toolTip in this fixture's JComboBox does not match the given regular expression pattern.
Since:
1.2

clientProperty

public Object clientProperty(Object key)
Returns the client property stored in this fixture's JComboBox, under the given key.

Specified by:
clientProperty in interface ClientPropertyStorageFixture
Parameters:
key - the key to use to retrieve the client property.
Returns:
the value of the client property stored under the given key, or null if the property was not found.
Throws:
NullPointerException - if the given key is null.
Since:
1.2

showPopupMenu

public JPopupMenuFixture showPopupMenu()
Shows a pop-up menu using this fixture's JComboBox as the invoker of the pop-up menu.

Specified by:
showPopupMenu in interface JPopupMenuInvokerFixture
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.

showPopupMenuAt

public JPopupMenuFixture showPopupMenuAt(Point p)
Shows a pop-up menu at the given point using this fixture's JComboBox as the invoker of the pop-up menu.

Specified by:
showPopupMenuAt in interface JPopupMenuInvokerFixture
Parameters:
p - the given point where to show the pop-up menu.
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
IllegalStateException - if this fixture's JComboBox is disabled.
IllegalStateException - if this fixture's JComboBox is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.

cellReader

public JComboBoxFixture cellReader(JComboBoxCellReader cellReader)
Updates the implementation of JComboBoxCellReader to use when comparing internal values of this fixture's JComboBox and the values expected in a test. The default implementation to use is BasicJComboBoxCellReader.

Parameters:
cellReader - the new JComboBoxCellValueReader to use.
Returns:
this fixture.
Throws:
NullPointerException - if cellReader is null.


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