@InternalApi public class JComboBoxDriver extends JComponentDriver
Supports functional testing of JComboBox
es.
Note: This class is intended for internal use only. Please use the classes in the package
org.assertj.swing.fixture
in your tests.
robot
Constructor and Description |
---|
JComboBoxDriver(Robot robot)
Creates a new
JComboBoxDriver . |
Modifier and Type | Method and Description |
---|---|
void |
clearSelection(JComboBox<?> comboBox)
Clears the selection in the given
JComboBox . |
String[] |
contentsOf(JComboBox<?> comboBox)
Returns an array of
String s that represents the contents of the given JComboBox list. |
void |
deleteText(JComboBox<?> comboBox)
Deletes the text of the
JComboBox . |
JList<?> |
dropDownList()
Find the
JList in the pop-up raised by the JComboBox , if the LAF actually uses one. |
void |
enterText(JComboBox<?> comboBox,
String text)
Simulates a user entering the specified text in the
JComboBox . |
void |
pressAndReleaseKeys(JComboBox<?> comboBox,
int... keyCodes)
Simulates a user pressing and releasing the given keys on the
JComboBox . |
void |
replaceCellReader(JComboBoxCellReader newCellReader)
Updates the implementation of
JComboBoxCellReader to use when comparing internal values of a
JComboBox and the values expected in a test. |
void |
replaceText(JComboBox<?> comboBox,
String text)
Simulates a user entering the specified text in the
JComboBox , replacing any text. |
void |
requireEditable(JComboBox<?> comboBox)
Asserts that the given
JComboBox is editable. |
void |
requireItemCount(JComboBox<?> comboBox,
int expected)
Verifies that number of items in the given
JComboBox is equal to the expected one. |
void |
requireNoSelection(JComboBox<?> comboBox)
Verifies that the
JComboBox does not have any selection. |
void |
requireNotEditable(JComboBox<?> comboBox)
Asserts that the given
JComboBox is not editable. |
void |
requireSelection(JComboBox<?> comboBox,
int index)
Verifies that the index of the selected item in the
JComboBox is equal to the given value. |
void |
requireSelection(JComboBox<?> comboBox,
Pattern pattern)
Verifies that the
String representation of the selected item in the JComboBox matches the given
regular expression pattern. |
void |
requireSelection(JComboBox<?> comboBox,
String value)
Verifies that the
String representation of the selected item in the JComboBox matches the given
text. |
void |
selectAllText(JComboBox<?> comboBox)
Simulates a user selecting the text in the
JComboBox . |
String |
selectedItemOf(JComboBox<?> comboBox)
Returns the selected value of the given
JComboBox as plain text. |
void |
selectItem(JComboBox<?> comboBox,
int index)
Selects the item under the given index in the
JComboBox . |
void |
selectItem(JComboBox<?> comboBox,
Pattern pattern)
Selects the first item matching the given regular expression pattern in the
JComboBox . |
void |
selectItem(JComboBox<?> comboBox,
String value)
Selects the first item matching the given text in the
JComboBox . |
String |
value(JComboBox<?> comboBox,
int index)
Returns the
String representation of the element under the given index, using this driver's
JComboBoxCellReader . |
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
doResizeHeight, doResizeWidth, isResizable, move, resize
backgroundOf, checkClickAllowed, checkInEdtEnabledAndShowing, checkInEdtShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, drop, focus, focusAndWaitForFocusGain, fontOf, foregroundOf, invokePopupMenu, invokePopupMenu, moveMouseIgnoringAnyError, moveMouseIgnoringAnyError, performAccessibleActionOf, pressAndReleaseKey, pressAndReleaseKey, pressAndReleaseKeys, pressKey, pressKeyWhileRunning, propertyName, releaseKey, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireSize, requireVisible, rightClick, settings, waitForShowing
public JComboBoxDriver(@Nonnull Robot robot)
JComboBoxDriver
.robot
- the robot to use to simulate user input.@RunsInEDT @Nonnull public String[] contentsOf(@Nonnull JComboBox<?> comboBox)
String
s that represents the contents of the given JComboBox
list. The
String
representation of each element is performed using this driver's JComboBoxCellReader
.comboBox
- the target JComboBox
.String
s that represent the contents of the given JComboBox
list.value(JComboBox, int)
,
replaceCellReader(JComboBoxCellReader)
@RunsInEDT public void selectItem(@Nonnull JComboBox<?> comboBox, @Nullable String value)
JComboBox
. The text of the JComboBox
items is
obtained by this fixture's JComboBoxCellReader
.comboBox
- the target JComboBox
.value
- the value to match. It can be a regular expression.LocationUnavailableException
- if an element matching the given value cannot be found.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.replaceCellReader(JComboBoxCellReader)
@RunsInEDT public void selectItem(@Nonnull JComboBox<?> comboBox, @Nonnull Pattern pattern)
JComboBox
. The text of the
JComboBox
items is obtained by this fixture's JComboBoxCellReader
.comboBox
- the target JComboBox
.pattern
- the regular expression pattern to match.LocationUnavailableException
- if an element matching the given pattern cannot be found.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.NullPointerException
- if the given regular expression pattern is null
.replaceCellReader(JComboBoxCellReader)
@RunsInEDT public void requireSelection(@Nonnull JComboBox<?> comboBox, @Nullable String value)
String
representation of the selected item in the JComboBox
matches the given
text.comboBox
- the target JComboBox
.value
- the text to match. It can be a regular expression.AssertionError
- if the selected item does not match the given value.replaceCellReader(JComboBoxCellReader)
@RunsInEDT public void requireSelection(@Nonnull JComboBox<?> comboBox, @Nonnull Pattern pattern)
String
representation of the selected item in the JComboBox
matches the given
regular expression pattern.comboBox
- the target JComboBox
.pattern
- the regular expression pattern to match.AssertionError
- if the selected item does not match the given regular expression pattern.NullPointerException
- if the given regular expression pattern is null
.replaceCellReader(JComboBoxCellReader)
@RunsInEDT public void requireSelection(@Nonnull JComboBox<?> comboBox, int index)
JComboBox
is equal to the given value.comboBox
- the target JComboBox
.index
- the expected selection index.AssertionError
- if the selection index is not equal to the given value.@RunsInEDT public void requireNoSelection(@Nonnull JComboBox<?> comboBox)
JComboBox
does not have any selection.comboBox
- the target JComboBox
.AssertionError
- if the JComboBox
has a selection.@Nullable public String value(@Nonnull JComboBox<?> comboBox, int index)
String
representation of the element under the given index, using this driver's
JComboBoxCellReader
.comboBox
- the target JComboBox
.index
- the given index.IndexOutOfBoundsException
- if the given index is negative or greater than the index of the last item in the
JComboBox
.replaceCellReader(JComboBoxCellReader)
public void clearSelection(@Nonnull JComboBox<?> comboBox)
JComboBox
. Since this method does not simulate user input, it does not
verifies that the JComboBox
is enabled and showing.comboBox
- the target JComboBox
.@RunsInEDT public void selectItem(@Nonnull JComboBox<?> comboBox, int index)
JComboBox
.comboBox
- the target JComboBox
.index
- the given index.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the 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
.@RunsInEDT public void deleteText(@Nonnull JComboBox<?> comboBox)
JComboBox
.comboBox
- the target JComboBox
.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.@RunsInEDT public void replaceText(@Nonnull JComboBox<?> comboBox, @Nonnull String text)
JComboBox
, replacing any text. This action is executed
only if the JComboBox
is editable.comboBox
- the target JComboBox
.text
- the text to enter.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.IllegalStateException
- if the JComboBox
is not editable.@RunsInEDT public void selectAllText(@Nonnull JComboBox<?> comboBox)
JComboBox
. This action is executed only if the JComboBox
is editable.comboBox
- the target JComboBox
.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.IllegalStateException
- if the JComboBox
is not editable.@RunsInEDT public void enterText(@Nonnull JComboBox<?> comboBox, @Nonnull String text)
JComboBox
. This action is executed only if the
JComboBox
is editable.comboBox
- the target JComboBox
.text
- the text to enter.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.IllegalStateException
- if the JComboBox
is not editable.ActionFailedException
- if the JComboBox
does not have an editor.@RunsInEDT public void pressAndReleaseKeys(@Nonnull JComboBox<?> comboBox, @Nonnull int... keyCodes)
JComboBox
.comboBox
- the target JComboBox
.keyCodes
- one or more codes of the keys to press.NullPointerException
- if the given array of codes is null
.IllegalStateException
- if the JComboBox
is disabled.IllegalStateException
- if the JComboBox
is not showing on the screen.IllegalArgumentException
- if the given code is not a valid key code.KeyEvent
@RunsInEDT @Nonnull public JList<?> dropDownList()
JList
in the pop-up raised by the JComboBox
, if the LAF actually uses one.JList
.ComponentLookupException
- if the JList
in the pop-up could not be found.@RunsInEDT public void requireEditable(@Nonnull JComboBox<?> comboBox)
JComboBox
is editable.comboBox
- the target JComboBox
.AssertionError
- if the JComboBox
is not editable.@RunsInEDT public void requireNotEditable(@Nonnull JComboBox<?> comboBox)
JComboBox
is not editable.comboBox
- the given JComboBox
.AssertionError
- if the JComboBox
is editable.public void replaceCellReader(@Nonnull JComboBoxCellReader newCellReader)
JComboBoxCellReader
to use when comparing internal values of a
JComboBox
and the values expected in a test.newCellReader
- the new JComboBoxCellValueReader
to use.NullPointerException
- if newCellReader
is null
.@RunsInEDT public void requireItemCount(@Nonnull JComboBox<?> comboBox, int expected)
JComboBox
is equal to the expected one.comboBox
- the target JComboBox
.expected
- the expected number of items.AssertionError
- if the number of items in the given JComboBox
is not equal to the expected one.@Nullable public String selectedItemOf(@Nonnull JComboBox<?> comboBox)
JComboBox
as plain text. This method returns null
if the
{code JComboBox} does not have any selection.comboBox
- the target JComboBox
.null
if the {code JComboBox}
does not have any selection.Copyright © 2014–2019 AssertJ. All rights reserved.