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
JComboBoxes:
- 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.JComboBoxFixtureJComboBoxFixture(Robot robot, JComboBox target) Creates a new.JComboBoxFixture -
Method Summary
Modifier and TypeMethodDescriptioncellReader(JComboBoxCellReader cellReader) Updates the implementation ofto use when comparing internal values of this fixture'sJComboBoxCellReaderand the values expected in a test.JComboBoxClears the selection in this fixture's.JComboBoxclick()Simulates a user clicking this fixture's.JComboBoxclick(MouseButton button) Simulates a user clicking this fixture's.JComboBoxclick(MouseClickInfo mouseClickInfo) Simulates a user clicking this fixture's.JComboBoxclientProperty(Object key) Returns the client property stored in this fixture's, under the given key.JComboBoxString[]contents()Returns theStringrepresentation of the elements in this fixture's, using this fixture'sJComboBox.JComboBoxCellReaderprivate voidSimulates a user double-clicking this fixture's.JComboBoxprotected final voiddriver(JComboBoxDriver newDriver) Sets theto be used by this fixture.JComboBoxDriverSimulates a user entering the specified text in this fixture's.JComboBoxfocus()Gives input focus to this fixture's.JComboBoxlist()pressAndReleaseKey(KeyPressInfo keyPressInfo) Simulates a user pressing given key with the given modifiers on this fixture's.JComboBoxpressAndReleaseKeys(int... keyCodes) Simulates a user pressing and releasing the given keys on this fixture's.JComboBoxpressKey(int keyCode) Simulates a user pressing the given key on this fixture's.JComboBoxreleaseKey(int keyCode) Simulates a user releasing the given key on this fixture's.JComboBoxreplaceText(String text) Simulates a user entering the specified text in the, replacing any text.JComboBoxAsserts that this fixture'sis disabled.JComboBoxAsserts that this fixture'sis editable.JComboBoxAsserts that this fixture'sis enabled.JComboBoxrequireEnabled(Timeout timeout) Asserts that this fixture'sis enabled.JComboBoxAsserts that this fixture'shas input focus.JComboBoxrequireItemCount(int expected) Verifies that this fixture'shas the expected number of itemsJComboBoxVerifies that this fixture'sdoes not have any selection.JComboBoxAsserts that this fixture'sis not editable.JComboBoxAsserts that this fixture'sis not visible.JComboBoxrequireSelection(int index) Verifies that the index of the selected item in this fixture'sis equal to the given value.JComboBoxrequireSelection(String value) Verifies that theStringrepresentation of the selected item in this fixture'smatches the given text.JComboBoxrequireSelection(Pattern pattern) Verifies that theStringrepresentation of the selected item in this fixture'smatches the given regular expression pattern.JComboBoxrequireToolTip(String expected) Asserts that the toolTip in this fixture'smatches the given value.JComboBoxrequireToolTip(Pattern pattern) Asserts that the toolTip in this fixture'smatches the given regular expression pattern.JComboBoxAsserts that this fixture'sis visible.JComboBoxSimulates a user right-clicking this fixture's.JComboBoxSimulates a user selecting the text in the.JComboBoxselectItem(int index) Simulates a user selecting an item in this fixture's.JComboBoxselectItem(String text) Simulates a user selecting an item in this fixture's.JComboBoxselectItem(Pattern pattern) Simulates a user selecting an item in this fixture's.JComboBoxShows a pop-up menu using this fixture'sas the invoker of the pop-up menu.JComboBoxShows a pop-up menu at the given point using this fixture'sas the invoker of the pop-up menu.JComboBoxvalueAt(int index) Returns theStringrepresentation of the value of an item in this fixture's, using this fixture'sJComboBox.JComboBoxCellReaderMethods 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- theJComboBoxto be managed by this fixture.- Throws:
NullPointerException- ifrobotisnull.NullPointerException- iftargetisnull.
-
JComboBoxFixture
Creates a new.JComboBoxFixture- Parameters:
robot- performs simulation of user events on aJComboBox.comboBoxName- the name of theJComboBoxto find using the givenRobot.- Throws:
NullPointerException- ifrobotisnull.ComponentLookupException- if a matchingJComboBoxcould not be found.ComponentLookupException- if more than one matchingJComboBoxis found.
-
-
Method Details
-
createDriver
private void createDriver() -
driver
Sets theto 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:
clickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
click
Simulates a user clicking this fixture's.JComboBox- Specified by:
clickin interfaceMouseInputSimulationFixture- Parameters:
button- the button to click.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenMouseButtonisnull.IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
click
Simulates a user clicking this fixture's.JComboBox- Specified by:
clickin interfaceMouseInputSimulationFixture- Parameters:
mouseClickInfo- specifies the button to click and the times the button should be clicked.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenMouseClickInfoisnull.IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
doubleClick
Simulates a user double-clicking this fixture's.JComboBox- Specified by:
doubleClickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
rightClick
Simulates a user right-clicking this fixture's.JComboBox- Specified by:
rightClickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
contents
Returns theStringrepresentation of the elements in this fixture's, using this fixture'sJComboBox.JComboBoxCellReader- Specified by:
contentsin interfaceItemGroupFixture- Returns:
- the
Stringrepresentation 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 theJComboBoxis editable.JComboBox- Parameters:
text- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.IllegalStateException- if this fixture'sJComboBoxis not editable.
-
selectAllText
Simulates a user selecting the text in the. This action is executed only if theJComboBoxis editable.JComboBox- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.IllegalStateException- if this fixture'sJComboBoxis not editable.
-
enterText
Simulates a user entering the specified text in this fixture's. This action is executed only if theJComboBoxis editable.JComboBox- Parameters:
text- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.IllegalStateException- if this fixture'sJComboBoxis not editable.ActionFailedException- if this fixture'sJComboBoxdoes not have an editor.
-
focus
Gives input focus to this fixture's.JComboBox- Specified by:
focusin interfaceFocusableComponentFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.
-
list
- Returns:
- the
JListin the pop-up raised by this fixture'sJComboBox. - Throws:
ComponentLookupException- if theJListin 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 availableJComboBoxmasks.InputEvent- Specified by:
pressAndReleaseKeyin interfaceKeyboardInputSimulationFixture- Parameters:
keyPressInfo- specifies the key and modifiers to press.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenKeyPressInfoisnull.IllegalArgumentException- if the given code is not a valid key code.IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.- See Also:
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys on this fixture's.JComboBox- Specified by:
pressAndReleaseKeysin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.- See Also:
-
pressKey
Simulates a user pressing the given key on this fixture's.JComboBox- Specified by:
pressKeyin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.- See Also:
-
releaseKey
Simulates a user releasing the given key on this fixture's.JComboBox- Specified by:
releaseKeyin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis 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'sJComboBoxJComboBoxis enabled and showing.- Specified by:
clearSelectionin interfaceItemGroupFixture- Returns:
- this fixture.
- Since:
- 1.2
-
selectItem
Simulates a user selecting an item in this fixture's.JComboBox- Specified by:
selectItemin interfaceItemGroupFixture- Parameters:
index- the index of the item to select.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis 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 givenJComboBoxString. Such text is retrieved by this fixture's.JComboBoxCellReader- Specified by:
selectItemin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis 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:
selectItemin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.NullPointerException- if the given regular expression pattern isnull.- Since:
- 1.2
- See Also:
-
valueAt
Returns theStringrepresentation of the value of an item in this fixture's, using this fixture'sJComboBox.JComboBoxCellReader- Specified by:
valueAtin interfaceItemGroupFixture- Parameters:
index- the index of the item to return.- Returns:
- the
Stringrepresentation 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'sis enabled.JComboBox- Specified by:
requireEnabledin interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis disabled.
-
requireFocused
Asserts that this fixture'shas input focus.JComboBox- Specified by:
requireFocusedin interfaceFocusableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxdoes not have input focus.
-
requireEnabled
Asserts that this fixture'sis enabled.JComboBox- Specified by:
requireEnabledin interfaceStateVerificationFixture- Parameters:
timeout- the time this fixture will wait for the component to be enabled.- Returns:
- this fixture.
- Throws:
WaitTimedOutError- if this fixture'sJComboBoxis never enabled.
-
requireDisabled
Asserts that this fixture'sis disabled.JComboBox- Specified by:
requireDisabledin interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis enabled.
-
requireVisible
Asserts that this fixture'sis visible.JComboBox- Specified by:
requireVisiblein interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis not visible.
-
requireNotVisible
Asserts that this fixture'sis not visible.JComboBox- Specified by:
requireNotVisiblein interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis visible.
-
requireEditable
Asserts that this fixture'sis editable.JComboBox- Specified by:
requireEditablein interfaceEditableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis not editable.
-
requireNotEditable
Asserts that this fixture'sis not editable.JComboBox- Specified by:
requireNotEditablein interfaceEditableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxis editable.
-
requireSelection
Verifies that theStringrepresentation of the selected item in this fixture'smatches the given text.JComboBox- Specified by:
requireSelectionin 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'shas the expected number of itemsJComboBox- Specified by:
requireItemCountin interfaceItemGroupFixture- Parameters:
expected- the expected number of items.- Returns:
- this fixture.
- Throws:
AssertionError- if the number of items in this fixture'sJComboBoxis not equal to the expected one.- Since:
- 1.2
-
requireSelection
Verifies that theStringrepresentation of the selected item in this fixture'smatches the given regular expression pattern.JComboBox- Specified by:
requireSelectionin 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'sis equal to the given value.JComboBox- Specified by:
requireSelectionin 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'sdoes not have any selection.JComboBox- Specified by:
requireNoSelectionin interfaceItemGroupFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJComboBoxhas a selection.
-
requireToolTip
Asserts that the toolTip in this fixture'smatches the given value.JComboBox- Specified by:
requireToolTipin interfaceToolTipDisplayFixture- Parameters:
expected- the given value. It can be a regular expression.- Returns:
- this fixture.
- Throws:
AssertionError- if the toolTip in this fixture'sJComboBoxdoes not match the given value.- Since:
- 1.2
-
requireToolTip
Asserts that the toolTip in this fixture'smatches the given regular expression pattern.JComboBox- Specified by:
requireToolTipin 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'sJComboBoxdoes 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:
clientPropertyin 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
nullif the property was not found. - Throws:
NullPointerException- if the given key isnull.- Since:
- 1.2
-
showPopupMenu
Shows a pop-up menu using this fixture'sas the invoker of the pop-up menu.JComboBox- Specified by:
showPopupMenuin interfaceJPopupMenuInvokerFixture- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException- if this fixture'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis 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'sas the invoker of the pop-up menu.JComboBox- Specified by:
showPopupMenuAtin 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'sJComboBoxis disabled.IllegalStateException- if this fixture'sJComboBoxis not showing on the screen.ComponentLookupException- if a pop-up menu cannot be found.
-
cellReader
Updates the implementation ofto use when comparing internal values of this fixture'sJComboBoxCellReaderand the values expected in a test. The default implementation to use isJComboBox.BasicJComboBoxCellReader- Parameters:
cellReader- the newJComboBoxCellValueReaderto use.- Returns:
- this fixture.
- Throws:
NullPointerException- ifcellReaderisnull.
-