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
JComboBox
es:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JComboBoxCellReader
private final JComboBoxDropDownListFinder
private static final String
private final JListDriver
private static final String
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Component
accessibleEditorOf
(JComboBox comboBox) private void
assertEditable
(JComboBox comboBox, boolean expected) void
cellReader
(JComboBoxCellReader newCellReader) Updates the implementation of
to use when comparing internal values of aJComboBoxCellReader
and the values expected in a test.JComboBox
void
clearSelection
(JComboBox comboBox) Clears the selection in the given
.JComboBox
String[]
contentsOf
(JComboBox comboBox) Returns an array ofString
s that represents the contents of the given
list.JComboBox
private void
dropDownVisibleThroughUIDelegate
(JComboBox comboBox, boolean visible) private static org.fest.assertions.Description
editableProperty
(JComboBox comboBox) private static Component
editorComponent
(JComboBox comboBox) private static Component
editorComponentOf
(JComboBox comboBox) private static Component
editorIfEditable
(JComboBox comboBox) void
Simulates a user entering the specified text in the
.JComboBox
private LocationUnavailableException
failMatchingNotFound
(JComboBox comboBox, TextMatcher matcher) private AssertionError
failNoSelection
(JComboBox comboBox) private void
hideDropDownListIfVisible
(JComboBox comboBox) private static void
inEdtValidateEditorIsAccessible
(JComboBox comboBox) private ComponentLookupException
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
, replacing any text.JComboBox
private String
requiredSelectionOf
(JComboBox comboBox) void
requireEditable
(JComboBox comboBox) Asserts that the given
is editable.JComboBox
void
requireItemCount
(JComboBox comboBox, int expected) Verifies that number of items in the given
is equal to the expected one.JComboBox
void
requireNoSelection
(JComboBox comboBox) Verifies that the
does not have any selection.JComboBox
void
requireNotEditable
(JComboBox comboBox) Asserts that the given
is not editable.JComboBox
void
requireSelection
(JComboBox comboBox, int index) Verifies that the index of the selected item in the
is equal to the given value.JComboBox
void
requireSelection
(JComboBox comboBox, String value) Verifies that theString
representation of the selected item in the
matches the given text.JComboBox
void
requireSelection
(JComboBox comboBox, Pattern pattern) Verifies that theString
representation of the selected item in the
matches the given regular expression pattern.JComboBox
void
selectAllText
(JComboBox comboBox) Simulates a user selecting the text in the
.JComboBox
private org.fest.assertions.Description
selectedIndexProperty
(JComboBox comboBox) void
selectItem
(JComboBox comboBox, int index) Selects the item under the given index in the
.JComboBox
void
selectItem
(JComboBox comboBox, String value) Selects the first item matching the given text in the
.JComboBox
void
selectItem
(JComboBox comboBox, Pattern pattern) Selects the first item matching the given regular expression pattern in the
.JComboBox
private void
selectItem
(JComboBox comboBox, TextMatcher matcher) private void
selectItemAtIndex
(JComboBox comboBox, int index) (package private) void
showDropDownList
(JComboBox comboBox) private static void
validateCanSelectItem
(JComboBox comboBox, int index) Returns theString
representation of the element under the given index, using this driver's
.JComboBoxCellReader
private static String
valueAsText
(JComboBox comboBox, int index, JComboBoxCellReader cellReader) 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
-
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 ofString
s that represents the contents of the given
list. TheJComboBox
String
representation of each element is performed using this driver's
.JComboBoxCellReader
- Parameters:
comboBox
- the targetJComboBox
.- Returns:
- an array of
String
s that represent the contents of the givenJComboBox
list. - See Also:
-
selectItem
Selects the first item matching the given text in the
. The text of theJComboBox
JComboBox
items 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 theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is not showing on the screen.- See Also:
-
selectItem
Selects the first item matching the given regular expression pattern in the
. The text of theJComboBox
JComboBox
items 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 theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is not showing on the screen.NullPointerException
- if the given regular expression pattern isnull
.- Since:
- 1.2
- See Also:
-
selectItem
-
failMatchingNotFound
-
requireSelection
Verifies that theString
representation of the selected item in the
matches 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 theString
representation of the selected item in the
matches 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 the
is 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 the
does not have any selection.JComboBox
- Parameters:
comboBox
- the targetJComboBox
.- Throws:
AssertionError
- if theJComboBox
has a selection.
-
value
Returns theString
representation 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 theJComboBox
JComboBox
is 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 theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is 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 theJComboBox
is editable.JComboBox
- Parameters:
comboBox
- the targetJComboBox
.text
- the text to enter.- Throws:
IllegalStateException
- if theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is not showing on the screen.IllegalStateException
- if theJComboBox
is not editable.
-
selectAllText
Simulates a user selecting the text in the
. This action is executed only if theJComboBox
is editable.JComboBox
- Parameters:
comboBox
- the targetJComboBox
.- Throws:
IllegalStateException
- if theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is not showing on the screen.IllegalStateException
- if theJComboBox
is not editable.
-
accessibleEditorOf
-
enterText
Simulates a user entering the specified text in the
. This action is executed only if theJComboBox
is editable.JComboBox
- Parameters:
comboBox
- the targetJComboBox
.text
- the text to enter.- Throws:
IllegalStateException
- if theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is not showing on the screen.IllegalStateException
- if theJComboBox
is not editable.ActionFailedException
- if theJComboBox
does 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 theJComboBox
is disabled.IllegalStateException
- if theJComboBox
is 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 theJList
in the pop-up could not be found.
-
listNotFound
-
requireEditable
Asserts that the given
is editable.JComboBox
- Parameters:
comboBox
- the targetJComboBox
.- Throws:
AssertionError
- if theJComboBox
is not editable.
-
requireNotEditable
Asserts that the given
is not editable.JComboBox
- Parameters:
comboBox
- the givenJComboBox
.- Throws:
AssertionError
- if theJComboBox
is editable.
-
assertEditable
-
editableProperty
-
cellReader
Updates the implementation of
to use when comparing internal values of aJComboBoxCellReader
and the values expected in a test.JComboBox
- Parameters:
newCellReader
- the newJComboBoxCellValueReader
to use.- Throws:
NullPointerException
- ifnewCellReader
isnull
.
-
requireItemCount
Verifies that number of items in the given
is 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 given
is not equal to the expected one.JComboBox
- Since:
- 1.2
-