Package org.fest.swing.fixture
Class 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
JComboBox
es:
- user input simulation
- state verification
- property value query
The conversion between the values given in tests and the values being displayed by a
renderer is performed by a JComboBox
. This fixture uses a
JComboBoxCellReader
by default.
JComboBoxCellReader
-
Field Summary
FieldsFields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
-
Constructor Summary
ConstructorsConstructorDescriptionJComboBoxFixture
(Robot robot, String comboBoxName) Creates a new
.JComboBoxFixture
JComboBoxFixture
(Robot robot, JComboBox target) Creates a new
.JComboBoxFixture
-
Method Summary
Modifier and TypeMethodDescriptioncellReader
(JComboBoxCellReader cellReader) Updates the implementation of
to use when comparing internal values of this fixture'sJComboBoxCellReader
and the values expected in a test.JComboBox
Clears the selection in this fixture's
.JComboBox
click()
Simulates a user clicking this fixture's
.JComboBox
click
(MouseButton button) Simulates a user clicking this fixture's
.JComboBox
click
(MouseClickInfo mouseClickInfo) Simulates a user clicking this fixture's
.JComboBox
clientProperty
(Object key) Returns the client property stored in this fixture's
, under the given key.JComboBox
String[]
contents()
Returns theString
representation of the elements in this fixture's
, using this fixture'sJComboBox
.JComboBoxCellReader
private void
Simulates a user double-clicking this fixture's
.JComboBox
protected final void
driver
(JComboBoxDriver newDriver) Sets the
to be used by this fixture.JComboBoxDriver
Simulates a user entering the specified text in this fixture's
.JComboBox
focus()
Gives input focus to this fixture's
.JComboBox
list()
pressAndReleaseKey
(KeyPressInfo keyPressInfo) Simulates a user pressing given key with the given modifiers on this fixture's
.JComboBox
pressAndReleaseKeys
(int... keyCodes) Simulates a user pressing and releasing the given keys on this fixture's
.JComboBox
pressKey
(int keyCode) Simulates a user pressing the given key on this fixture's
.JComboBox
releaseKey
(int keyCode) Simulates a user releasing the given key on this fixture's
.JComboBox
replaceText
(String text) Simulates a user entering the specified text in the
, replacing any text.JComboBox
Asserts that this fixture's
is disabled.JComboBox
Asserts that this fixture's
is editable.JComboBox
Asserts that this fixture's
is enabled.JComboBox
requireEnabled
(Timeout timeout) Asserts that this fixture's
is enabled.JComboBox
Asserts that this fixture's
has input focus.JComboBox
requireItemCount
(int expected) Verifies that this fixture's
has the expected number of itemsJComboBox
Verifies that this fixture's
does not have any selection.JComboBox
Asserts that this fixture's
is not editable.JComboBox
Asserts that this fixture's
is not visible.JComboBox
requireSelection
(int index) Verifies that the index of the selected item in this fixture's
is equal to the given value.JComboBox
requireSelection
(String value) Verifies that theString
representation of the selected item in this fixture's
matches the given text.JComboBox
requireSelection
(Pattern pattern) Verifies that theString
representation of the selected item in this fixture's
matches the given regular expression pattern.JComboBox
requireToolTip
(String expected) Asserts that the toolTip in this fixture's
matches the given value.JComboBox
requireToolTip
(Pattern pattern) Asserts that the toolTip in this fixture's
matches the given regular expression pattern.JComboBox
Asserts that this fixture's
is visible.JComboBox
Simulates a user right-clicking this fixture's
.JComboBox
Simulates a user selecting the text in the
.JComboBox
selectItem
(int index) Simulates a user selecting an item in this fixture's
.JComboBox
selectItem
(String text) Simulates a user selecting an item in this fixture's
.JComboBox
selectItem
(Pattern pattern) Simulates a user selecting an item in this fixture's
.JComboBox
Shows a pop-up menu using this fixture's
as the invoker of the pop-up menu.JComboBox
Shows a pop-up menu at the given point using this fixture's
as the invoker of the pop-up menu.JComboBox
valueAt
(int index) Returns theString
representation of the value of an item in this fixture's
, using this fixture'sJComboBox
.JComboBoxCellReader
Methods inherited from class org.fest.swing.fixture.ComponentFixture
background, component, font, foreground, requireShowing, targetCastedTo, validateNotNull
-
Field Details
-
driver
-
-
Constructor Details
-
JComboBoxFixture
Creates a new
.JComboBoxFixture
- Parameters:
robot
- performs simulation of user events on the givenJComboBox
.target
- theJComboBox
to be managed by this fixture.- Throws:
NullPointerException
- ifrobot
isnull
.NullPointerException
- iftarget
isnull
.
-
JComboBoxFixture
Creates a new
.JComboBoxFixture
- Parameters:
robot
- performs simulation of user events on aJComboBox
.comboBoxName
- the name of theJComboBox
to find using the givenRobot
.- Throws:
NullPointerException
- ifrobot
isnull
.ComponentLookupException
- if a matchingJComboBox
could not be found.ComponentLookupException
- if more than one matchingJComboBox
is found.
-
-
Method Details
-
createDriver
private void createDriver() -
driver
Sets the
to be used by this fixture.JComboBoxDriver
- Parameters:
newDriver
- the newJComboBoxDriver
.- Throws:
NullPointerException
- if the given driver isnull
.
-
click
Simulates a user clicking this fixture's
.JComboBox
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
click
Simulates a user clicking this fixture's
.JComboBox
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
button
- the button to click.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenMouseButton
isnull
.IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
click
Simulates a user clicking this fixture's
.JComboBox
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
mouseClickInfo
- specifies the button to click and the times the button should be clicked.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenMouseClickInfo
isnull
.IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
doubleClick
Simulates a user double-clicking this fixture's
.JComboBox
- Specified by:
doubleClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
rightClick
Simulates a user right-clicking this fixture's
.JComboBox
- Specified by:
rightClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
contents
Returns theString
representation of the elements in this fixture's
, using this fixture'sJComboBox
.JComboBoxCellReader
- Specified by:
contents
in interfaceItemGroupFixture
- Returns:
- the
String
representation of the elements in this fixture'sJComboBox
. - See Also:
-
replaceText
Simulates a user entering the specified text in the
, replacing any text. This action is executed only if theJComboBox
is editable.JComboBox
- Parameters:
text
- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.IllegalStateException
- if this fixture'sJComboBox
is not editable.
-
selectAllText
Simulates a user selecting the text in the
. This action is executed only if theJComboBox
is editable.JComboBox
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.IllegalStateException
- if this fixture'sJComboBox
is not editable.
-
enterText
Simulates a user entering the specified text in this fixture's
. This action is executed only if theJComboBox
is editable.JComboBox
- Parameters:
text
- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.IllegalStateException
- if this fixture'sJComboBox
is not editable.ActionFailedException
- if this fixture'sJComboBox
does not have an editor.
-
focus
Gives input focus to this fixture's
.JComboBox
- Specified by:
focus
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.
-
list
- Returns:
- the
JList
in the pop-up raised by this fixture'sJComboBox
. - Throws:
ComponentLookupException
- if theJList
in the pop-up could not be found.
-
pressAndReleaseKey
Simulates a user pressing given key with the given modifiers on this fixture's
. Modifiers is a mask from the availableJComboBox
masks.InputEvent
- Specified by:
pressAndReleaseKey
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyPressInfo
- specifies the key and modifiers to press.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenKeyPressInfo
isnull
.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.- See Also:
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys on this fixture's
.JComboBox
- Specified by:
pressAndReleaseKeys
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyCodes
- one or more codes of the keys to press.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given array of codes isnull
.IllegalArgumentException
- if any of the given code is not a valid key code.IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.- See Also:
-
pressKey
Simulates a user pressing the given key on this fixture's
.JComboBox
- Specified by:
pressKey
in interfaceKeyboardInputSimulationFixture
- 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'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.- See Also:
-
releaseKey
Simulates a user releasing the given key on this fixture's
.JComboBox
- Specified by:
releaseKey
in interfaceKeyboardInputSimulationFixture
- 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'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.- See Also:
-
clearSelection
Clears the selection in this fixture's
. Since this method does not simulate user input, it does not verifies that this fixture'sJComboBox
JComboBox
is enabled and showing.- Specified by:
clearSelection
in interfaceItemGroupFixture
- Returns:
- this fixture.
- Since:
- 1.2
-
selectItem
Simulates a user selecting an item in this fixture's
.JComboBox
- Specified by:
selectItem
in interfaceItemGroupFixture
- Parameters:
index
- the index of the item to select.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.IndexOutOfBoundsException
- if the given index is negative or greater than the index of the last item in theJComboBox
.
-
selectItem
Simulates a user selecting an item in this fixture's
. The text of the item to select must match the givenJComboBox
String
. Such text is retrieved by this fixture's
.JComboBoxCellReader
- Specified by:
selectItem
in interfaceItemGroupFixture
- 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'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.- See Also:
-
selectItem
Simulates a user selecting an item in this fixture's
. The text of the item to select must match the given regular expression pattern. Such text is retrieved by this fixture'sJComboBox
.JComboBoxCellReader
- Specified by:
selectItem
in interfaceItemGroupFixture
- 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'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.NullPointerException
- if the given regular expression pattern isnull
.- Since:
- 1.2
- See Also:
-
valueAt
Returns theString
representation of the value of an item in this fixture's
, using this fixture'sJComboBox
.JComboBoxCellReader
- Specified by:
valueAt
in interfaceItemGroupFixture
- Parameters:
index
- the index of the item to return.- Returns:
- the
String
representation of the value of an item in this fixture'sJComboBox
. - Throws:
IndexOutOfBoundsException
- if the given index is negative or greater than the index of the last item in theJComboBox
.- See Also:
-
requireEnabled
Asserts that this fixture's
is enabled.JComboBox
- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is disabled.
-
requireFocused
Asserts that this fixture's
has input focus.JComboBox
- Specified by:
requireFocused
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
does not have input focus.
-
requireEnabled
Asserts that this fixture's
is enabled.JComboBox
- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Parameters:
timeout
- the time this fixture will wait for the component to be enabled.- Returns:
- this fixture.
- Throws:
WaitTimedOutError
- if this fixture'sJComboBox
is never enabled.
-
requireDisabled
Asserts that this fixture's
is disabled.JComboBox
- Specified by:
requireDisabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is enabled.
-
requireVisible
Asserts that this fixture's
is visible.JComboBox
- Specified by:
requireVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is not visible.
-
requireNotVisible
Asserts that this fixture's
is not visible.JComboBox
- Specified by:
requireNotVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is visible.
-
requireEditable
Asserts that this fixture's
is editable.JComboBox
- Specified by:
requireEditable
in interfaceEditableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is not editable.
-
requireNotEditable
Asserts that this fixture's
is not editable.JComboBox
- Specified by:
requireNotEditable
in interfaceEditableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
is editable.
-
requireSelection
Verifies that theString
representation of the selected item in this fixture's
matches the given text.JComboBox
- Specified by:
requireSelection
in interfaceItemGroupFixture
- 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:
-
requireItemCount
Verifies that this fixture's
has the expected number of itemsJComboBox
- Specified by:
requireItemCount
in interfaceItemGroupFixture
- Parameters:
expected
- the expected number of items.- Returns:
- this fixture.
- Throws:
AssertionError
- if the number of items in this fixture'sJComboBox
is not equal to the expected one.- Since:
- 1.2
-
requireSelection
Verifies that theString
representation of the selected item in this fixture's
matches the given regular expression pattern.JComboBox
- Specified by:
requireSelection
in interfaceItemGroupFixture
- Parameters:
pattern
- the regular expression pattern to match.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the selected item does not match the given regular expression pattern.- Since:
- 1.2
- See Also:
-
requireSelection
Verifies that the index of the selected item in this fixture's
is equal to the given value.JComboBox
- Specified by:
requireSelection
in interfaceItemGroupFixture
- 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
Verifies that this fixture's
does not have any selection.JComboBox
- Specified by:
requireNoSelection
in interfaceItemGroupFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJComboBox
has a selection.
-
requireToolTip
Asserts that the toolTip in this fixture's
matches the given value.JComboBox
- Specified by:
requireToolTip
in interfaceToolTipDisplayFixture
- Parameters:
expected
- the given value. It can be a regular expression.- Returns:
- this fixture.
- Throws:
AssertionError
- if the toolTip in this fixture'sJComboBox
does not match the given value.- Since:
- 1.2
-
requireToolTip
Asserts that the toolTip in this fixture's
matches the given regular expression pattern.JComboBox
- Specified by:
requireToolTip
in interfaceToolTipDisplayFixture
- Parameters:
pattern
- the regular expression pattern to match.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the toolTip in this fixture'sJComboBox
does not match the given regular expression pattern.- Since:
- 1.2
-
clientProperty
Returns the client property stored in this fixture's
, under the given key.JComboBox
- Specified by:
clientProperty
in interfaceClientPropertyStorageFixture
- 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 isnull
.- Since:
- 1.2
-
showPopupMenu
Shows a pop-up menu using this fixture's
as the invoker of the pop-up menu.JComboBox
- Specified by:
showPopupMenu
in interfaceJPopupMenuInvokerFixture
- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException
- if this fixture'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
showPopupMenuAt
Shows a pop-up menu at the given point using this fixture's
as the invoker of the pop-up menu.JComboBox
- Specified by:
showPopupMenuAt
in interfaceJPopupMenuInvokerFixture
- 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'sJComboBox
is disabled.IllegalStateException
- if this fixture'sJComboBox
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
cellReader
Updates the implementation of
to use when comparing internal values of this fixture'sJComboBoxCellReader
and the values expected in a test. The default implementation to use isJComboBox
.BasicJComboBoxCellReader
- Parameters:
cellReader
- the newJComboBoxCellValueReader
to use.- Returns:
- this fixture.
- Throws:
NullPointerException
- ifcellReader
isnull
.
-