@InternalApi public class JTextComponentDriver extends JComponentDriver implements TextDisplayDriver<JTextComponent>
Supports functional testing of JTextComponent
s.
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 |
---|
JTextComponentDriver(Robot robot)
Creates a new
JTextComponentDriver . |
Modifier and Type | Method and Description |
---|---|
void |
deleteText(JTextComponent textBox)
Deletes the text of the
JTextComponent . |
void |
enterText(JTextComponent textBox,
String text)
Types the given text into the
JTextComponent . |
void |
replaceText(JTextComponent textBox,
String text)
Types the given text into the
JTextComponent , replacing any existing text already there. |
void |
requireEditable(JTextComponent textBox)
Asserts that the given
JTextComponent is editable. |
void |
requireEmpty(JTextComponent textBox)
Asserts that the given
JTextComponent is empty. |
void |
requireNotEditable(JTextComponent textBox)
Asserts that the given
JTextComponent is not editable. |
void |
requireText(JTextComponent textBox,
Pattern pattern)
Asserts that the text in the given
JTextComponent matches the given regular expression pattern. |
void |
requireText(JTextComponent textBox,
String expected)
Asserts that the text in the given
JTextComponent is equal to the specified value. |
void |
selectAll(JTextComponent textBox)
Selects the text in the
JTextComponent . |
void |
selectText(JTextComponent textBox,
int start,
int end)
Select the given text range.
|
void |
selectText(JTextComponent textBox,
String text)
Select the given text range.
|
void |
setText(JTextComponent textBox,
String text)
Sets the given text into the
JTextComponent . |
String |
textOf(JTextComponent textBox)
Returns the text of the given
JTextComponent . |
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 JTextComponentDriver(@Nonnull Robot robot)
JTextComponentDriver
.robot
- the robot to use to simulate user input.@RunsInEDT public void deleteText(@Nonnull JTextComponent textBox)
JTextComponent
.textBox
- the target JTextComponent
.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.@RunsInEDT public void replaceText(@Nonnull JTextComponent textBox, @Nonnull String text)
JTextComponent
, replacing any existing text already there.textBox
- the target JTextComponent
.text
- the text to enter. Uses deleteText(JTextComponent)
if this is an empty string.NullPointerException
- if the text to enter is null
.IllegalArgumentException
- if the text to enter is empty.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.@RunsInEDT public void selectAll(@Nonnull JTextComponent textBox)
JTextComponent
.textBox
- the target JTextComponent
.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.@RunsInEDT public void enterText(@Nonnull JTextComponent textBox, @Nonnull String text)
JTextComponent
.textBox
- the target JTextComponent
.text
- the text to enter.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.@RunsInEDT public void setText(@Nonnull JTextComponent textBox, @Nullable String text)
Sets the given text into the JTextComponent
. Unlike enterText(JTextComponent, String)
, this method
bypasses the event system and allows immediate updating on the underlying document model.
Primarily desired for speeding up tests when precise user event fidelity isn't necessary.
textBox
- the target JTextComponent
.text
- the text to enter.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.@RunsInEDT public void selectText(@Nonnull JTextComponent textBox, @Nonnull String text)
textBox
- the target JTextComponent
.text
- the text to select.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.IllegalArgumentException
- if the JTextComponent
does not contain the given text to select.ActionFailedException
- if selecting the text fails.@RunsInEDT public void selectText(@Nonnull JTextComponent textBox, int start, int end)
textBox
- the target JTextComponent
.start
- the starting index of the selection.end
- the ending index of the selection.IllegalStateException
- if the JTextComponent
is disabled.IllegalStateException
- if the JTextComponent
is not showing on the screen.ActionFailedException
- if selecting the text in the given range fails.@RunsInEDT public void requireText(@Nonnull JTextComponent textBox, @Nullable String expected)
JTextComponent
is equal to the specified value.requireText
in interface TextDisplayDriver<JTextComponent>
textBox
- the given JTextComponent
.expected
- the text to match. It can be a regular expression pattern.AssertionError
- if the text of the JTextComponent
is not equal to the given one.@RunsInEDT public void requireText(@Nonnull JTextComponent textBox, @Nonnull Pattern pattern)
JTextComponent
matches the given regular expression pattern.requireText
in interface TextDisplayDriver<JTextComponent>
textBox
- the given JTextComponent
.pattern
- the regular expression pattern to match.NullPointerException
- if the given regular expression pattern is null
.AssertionError
- if the text of the JTextComponent
is not equal to the given one.@RunsInEDT public void requireEmpty(@Nonnull JTextComponent textBox)
JTextComponent
is empty.textBox
- the given JTextComponent
.AssertionError
- if the JTextComponent
is not empty.@RunsInEDT public void requireEditable(@Nonnull JTextComponent textBox)
JTextComponent
is editable.textBox
- the given JTextComponent
.AssertionError
- if the JTextComponent
is not editable.@RunsInEDT public void requireNotEditable(@Nonnull JTextComponent textBox)
JTextComponent
is not editable.textBox
- the given JTextComponent
.AssertionError
- if the JTextComponent
is editable.@RunsInEDT @Nullable public String textOf(@Nonnull JTextComponent textBox)
JTextComponent
.textOf
in interface TextDisplayDriver<JTextComponent>
textBox
- the given JTextComponent
.JTextComponent
.Copyright © 2014–2019 AssertJ. All rights reserved.