Package org.fest.swing.driver
Class JComboBoxDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
org.fest.swing.driver.ContainerDriver
org.fest.swing.driver.JComponentDriver
org.fest.swing.driver.JComboBoxDriver
Understands functional testing of
JComboBoxes:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JComboBoxCellReaderprivate final JComboBoxDropDownListFinderprivate static final Stringprivate final JListDriverprivate static final StringFields inherited from class org.fest.swing.driver.ComponentDriver
robot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ComponentaccessibleEditorOf(JComboBox comboBox) private voidassertEditable(JComboBox comboBox, boolean expected) voidcellReader(JComboBoxCellReader newCellReader) Updates the implementation ofto use when comparing internal values of aJComboBoxCellReaderand the values expected in a test.JComboBoxvoidclearSelection(JComboBox comboBox) Clears the selection in the given.JComboBoxString[]contentsOf(JComboBox comboBox) Returns an array ofStrings that represents the contents of the givenlist.JComboBoxprivate voiddropDownVisibleThroughUIDelegate(JComboBox comboBox, boolean visible) private static org.fest.assertions.DescriptioneditableProperty(JComboBox comboBox) private static ComponenteditorComponent(JComboBox comboBox) private static ComponenteditorComponentOf(JComboBox comboBox) private static ComponenteditorIfEditable(JComboBox comboBox) voidSimulates a user entering the specified text in the.JComboBoxprivate LocationUnavailableExceptionfailMatchingNotFound(JComboBox comboBox, TextMatcher matcher) private AssertionErrorfailNoSelection(JComboBox comboBox) private voidhideDropDownListIfVisible(JComboBox comboBox) private static voidinEdtValidateEditorIsAccessible(JComboBox comboBox) private ComponentLookupExceptionvoidpressAndReleaseKeys(JComboBox comboBox, int... keyCodes) Simulates a user pressing and releasing the given keys on the.JComboBoxvoidreplaceText(JComboBox comboBox, String text) Simulates a user entering the specified text in the, replacing any text.JComboBoxprivate StringrequiredSelectionOf(JComboBox comboBox) voidrequireEditable(JComboBox comboBox) Asserts that the givenis editable.JComboBoxvoidrequireItemCount(JComboBox comboBox, int expected) Verifies that number of items in the givenis equal to the expected one.JComboBoxvoidrequireNoSelection(JComboBox comboBox) Verifies that thedoes not have any selection.JComboBoxvoidrequireNotEditable(JComboBox comboBox) Asserts that the givenis not editable.JComboBoxvoidrequireSelection(JComboBox comboBox, int index) Verifies that the index of the selected item in theis equal to the given value.JComboBoxvoidrequireSelection(JComboBox comboBox, String value) Verifies that theStringrepresentation of the selected item in thematches the given text.JComboBoxvoidrequireSelection(JComboBox comboBox, Pattern pattern) Verifies that theStringrepresentation of the selected item in thematches the given regular expression pattern.JComboBoxvoidselectAllText(JComboBox comboBox) Simulates a user selecting the text in the.JComboBoxprivate org.fest.assertions.DescriptionselectedIndexProperty(JComboBox comboBox) voidselectItem(JComboBox comboBox, int index) Selects the item under the given index in the.JComboBoxvoidselectItem(JComboBox comboBox, String value) Selects the first item matching the given text in the.JComboBoxvoidselectItem(JComboBox comboBox, Pattern pattern) Selects the first item matching the given regular expression pattern in the.JComboBoxprivate voidselectItem(JComboBox comboBox, TextMatcher matcher) private voidselectItemAtIndex(JComboBox comboBox, int index) (package private) voidshowDropDownList(JComboBox comboBox) private static voidvalidateCanSelectItem(JComboBox comboBox, int index) Returns theStringrepresentation of the element under the given index, using this driver's.JComboBoxCellReaderprivate static StringvalueAsText(JComboBox comboBox, int index, JComboBoxCellReader cellReader) Methods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisibleMethods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidthMethods 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
-
Field Details
-
EDITABLE_PROPERTY
- See Also:
-
SELECTED_INDEX_PROPERTY
- See Also:
-
listDriver
-
dropDownListFinder
-
cellReader
-
-
Constructor Details
-
JComboBoxDriver
Creates a newJComboBoxDriver.- Parameters:
robot- the robot to use to simulate user input.
-
-
Method Details
-
contentsOf
Returns an array ofStrings that represents the contents of the givenlist. TheJComboBoxStringrepresentation of each element is performed using this driver's.JComboBoxCellReader- Parameters:
comboBox- the targetJComboBox.- Returns:
- an array of
Strings that represent the contents of the givenJComboBoxlist. - See Also:
-
selectItem
Selects the first item matching the given text in the. The text of theJComboBoxJComboBoxitems is obtained by this fixture's.JComboBoxCellReader- Parameters:
comboBox- the targetJComboBox.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 theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.- See Also:
-
selectItem
Selects the first item matching the given regular expression pattern in the. The text of theJComboBoxJComboBoxitems is obtained by this fixture's.JComboBoxCellReader- Parameters:
comboBox- the targetJComboBox.pattern- the regular expression pattern to match.- Throws:
LocationUnavailableException- if an element matching the given pattern cannot be found.IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.NullPointerException- if the given regular expression pattern isnull.- Since:
- 1.2
- See Also:
-
selectItem
-
failMatchingNotFound
-
requireSelection
Verifies that theStringrepresentation of the selected item in thematches the given text.JComboBox- Parameters:
comboBox- the targetJComboBox.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:
-
requireSelection
Verifies that theStringrepresentation of the selected item in thematches the given regular expression pattern.JComboBox- Parameters:
comboBox- the targetJComboBox.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 isnull.- Since:
- 1.2
- See Also:
-
requiredSelectionOf
- Throws:
AssertionError
-
requireSelection
Verifies that the index of the selected item in theis equal to the given value.JComboBox- Parameters:
comboBox- the targetJComboBox.index- the expected selection index.- Throws:
AssertionError- if the selection index is not equal to the given value.- Since:
- 1.2
-
failNoSelection
-
requireNoSelection
Verifies that thedoes not have any selection.JComboBox- Parameters:
comboBox- the targetJComboBox.- Throws:
AssertionError- if theJComboBoxhas a selection.
-
value
Returns theStringrepresentation of the element under the given index, using this driver's.JComboBoxCellReader- Parameters:
comboBox- the targetJComboBox.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 theJComboBox.- See Also:
-
valueAsText
@RunsInEDT private static String valueAsText(JComboBox comboBox, int index, JComboBoxCellReader cellReader) -
selectedIndexProperty
-
clearSelection
Clears the selection in the given. Since this method does not simulate user input, it does not verifies that theJComboBoxJComboBoxis enabled and showing.- Parameters:
comboBox- the targetJComboBox.- Since:
- 1.2
-
selectItem
Selects the item under the given index in the.JComboBox- Parameters:
comboBox- the targetJComboBox.index- the given index.- Throws:
IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.IndexOutOfBoundsException- if the given index is negative or greater than the index of the last item in theJComboBox.
-
validateCanSelectItem
-
showDropDownList
-
selectItemAtIndex
-
hideDropDownListIfVisible
-
dropDownVisibleThroughUIDelegate
-
replaceText
Simulates a user entering the specified text in the, replacing any text. This action is executed only if theJComboBoxis editable.JComboBox- Parameters:
comboBox- the targetJComboBox.text- the text to enter.- Throws:
IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.IllegalStateException- if theJComboBoxis not editable.
-
selectAllText
Simulates a user selecting the text in the. This action is executed only if theJComboBoxis editable.JComboBox- Parameters:
comboBox- the targetJComboBox.- Throws:
IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.IllegalStateException- if theJComboBoxis not editable.
-
accessibleEditorOf
-
enterText
Simulates a user entering the specified text in the. This action is executed only if theJComboBoxis editable.JComboBox- Parameters:
comboBox- the targetJComboBox.text- the text to enter.- Throws:
IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.IllegalStateException- if theJComboBoxis not editable.ActionFailedException- if theJComboBoxdoes not have an editor.
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys on the.JComboBox- Parameters:
comboBox- the targetJComboBox.keyCodes- one or more codes of the keys to press.- Throws:
NullPointerException- if the given array of codes isnull.IllegalStateException- if theJComboBoxis disabled.IllegalStateException- if theJComboBoxis not showing on the screen.IllegalArgumentException- if the given code is not a valid key code.- See Also:
-
editorIfEditable
-
inEdtValidateEditorIsAccessible
-
editorComponentOf
-
editorComponent
-
dropDownList
- Returns:
- the found
JList. - Throws:
ComponentLookupException- if theJListin the pop-up could not be found.
-
listNotFound
-
requireEditable
Asserts that the givenis editable.JComboBox- Parameters:
comboBox- the targetJComboBox.- Throws:
AssertionError- if theJComboBoxis not editable.
-
requireNotEditable
Asserts that the givenis not editable.JComboBox- Parameters:
comboBox- the givenJComboBox.- Throws:
AssertionError- if theJComboBoxis editable.
-
assertEditable
-
editableProperty
-
cellReader
Updates the implementation ofto use when comparing internal values of aJComboBoxCellReaderand the values expected in a test.JComboBox- Parameters:
newCellReader- the newJComboBoxCellValueReaderto use.- Throws:
NullPointerException- ifnewCellReaderisnull.
-
requireItemCount
Verifies that number of items in the givenis equal to the expected one.JComboBox- Parameters:
comboBox- the targetJComboBox.expected- the expected number of items.- Throws:
AssertionError- if the number of items in the givenis not equal to the expected one.JComboBox- Since:
- 1.2
-