Package org.fest.swing.driver
Class JTextComponentDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
org.fest.swing.driver.ContainerDriver
org.fest.swing.driver.JComponentDriver
org.fest.swing.driver.JTextComponentDriver
- All Implemented Interfaces:
TextDisplayDriver<JTextComponent>
public class JTextComponentDriver
extends JComponentDriver
implements TextDisplayDriver<JTextComponent>
Understands functional testing of
JTextComponent
s:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsFields inherited from class org.fest.swing.driver.ComponentDriver
robot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Rectangle
private void
assertEditable
(JTextComponent textBox, boolean editable) private static ActionFailedException
cannotGetLocation
(JTextComponent textBox, int index) private static Point
void
deleteText
(JTextComponent textBox) Deletes the text of the
.JTextComponent
private static org.fest.assertions.Description
editableProperty
(JTextComponent textBox) void
enterText
(JTextComponent textBox, String text) Types the given text into the
.JTextComponent
private static String
private static int
indexOfText
(JTextComponent textBox, String text) private static boolean
isRectangleVisible
(JTextComponent textBox, Rectangle r) private static Rectangle
locationOf
(JTextComponent textBox, int index) private static void
performAndValidateTextSelection
(JTextComponent textBox, int start, int end) void
replaceText
(JTextComponent textBox, String text) Types the given text into the
, replacing any existing text already there.JTextComponent
void
requireEditable
(JTextComponent textBox) Asserts that the given
is editable.JTextComponent
void
requireEmpty
(JTextComponent textBox) Asserts that the given
is empty.JTextComponent
void
requireNotEditable
(JTextComponent textBox) Asserts that the given
is not editable.JTextComponent
void
requireText
(JTextComponent textBox, String expected) Asserts that the text in the given
is equal to the specified value.JTextComponent
void
requireText
(JTextComponent textBox, Pattern pattern) Asserts that the text in the given
matches the given regular expression pattern.JTextComponent
private static Point
scrollToPosition
(JTextComponent textBox, int index) private static Point
scrollToVisible
(JTextComponent textBox, int index) Move the pointer to the location of the given index.private static void
scrollToVisible
(JTextComponent textBox, Rectangle r) private static void
scrollToVisibleIfIsTextField
(JTextComponent textBox, Rectangle r) 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
textOf
(JTextComponent textBox) Returns the text of the given
.JTextComponent
private static org.fest.assertions.Description
textProperty
(JTextComponent textBox) private static Point
validateAndScrollToPosition
(JTextComponent textBox, int index) private static void
verifyTextWasSelected
(JTextComponent textBox, int start, int end) 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:
-
TEXT_PROPERTY
- See Also:
-
-
Constructor Details
-
JTextComponentDriver
Creates a newJTextComponentDriver
.- Parameters:
robot
- the robot to use to simulate user input.
-
-
Method Details
-
deleteText
Deletes the text of the
.JTextComponent
- Parameters:
textBox
- the targetJTextComponent
.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.
-
replaceText
Types the given text into the
, replacing any existing text already there.JTextComponent
- Parameters:
textBox
- the targetJTextComponent
.text
- the text to enter.- Throws:
NullPointerException
- if the text to enter isnull
.IllegalArgumentException
- if the text to enter is empty.IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.
-
selectAll
Selects the text in the
.JTextComponent
- Parameters:
textBox
- the targetJTextComponent
.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.
-
enterText
Types the given text into the
.JTextComponent
- Parameters:
textBox
- the targetJTextComponent
.text
- the text to enter.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.
-
setText
Sets the given text into the
. UnlikeJTextComponent
, this method bypasses the event system and allows immediate updating on the underlying document model.enterText(JTextComponent, String)
Primarily desired for speeding up tests when precise user event fidelity isn't necessary.
- Parameters:
textBox
- the targetJTextComponent
.text
- the text to enter.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.
-
selectText
Select the given text range.- Parameters:
textBox
- the targetJTextComponent
.text
- the text to select.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.IllegalArgumentException
- if theJTextComponent
does not contain the given text to select.ActionFailedException
- if selecting the text fails.
-
indexOfText
-
selectText
Select the given text range.- Parameters:
textBox
- the targetJTextComponent
.start
- the starting index of the selection.end
- the ending index of the selection.- Throws:
IllegalStateException
- if theJTextComponent
is disabled.IllegalStateException
- if theJTextComponent
is not showing on the screen.ActionFailedException
- if selecting the text in the given range fails.
-
validateAndScrollToPosition
-
scrollToPosition
-
scrollToVisible
Move the pointer to the location of the given index. Takes care of auto-scrolling through text.- Parameters:
textBox
- the targetJTextComponent
.index
- the given location.- Returns:
- the position of the pointer after being moved.
- Throws:
ActionFailedException
- if it was not possible to scroll to the location of the given index.
-
locationOf
-
cannotGetLocation
-
isRectangleVisible
-
formatOriginOf
-
scrollToVisible
-
scrollToVisibleIfIsTextField
@RunsInCurrentThread private static void scrollToVisibleIfIsTextField(JTextComponent textBox, Rectangle r) -
addPointToRectangle
-
centerOf
-
performAndValidateTextSelection
@RunsInEDT private static void performAndValidateTextSelection(JTextComponent textBox, int start, int end) -
verifyTextWasSelected
@RunsInCurrentThread private static void verifyTextWasSelected(JTextComponent textBox, int start, int end) -
requireText
Asserts that the text in the given
is equal to the specified value.JTextComponent
- Specified by:
requireText
in interfaceTextDisplayDriver<JTextComponent>
- Parameters:
textBox
- the givenJTextComponent
.expected
- the text to match. It can be a regular expression pattern.- Throws:
AssertionError
- if the text of theJTextComponent
is not equal to the given one.
-
requireText
Asserts that the text in the given
matches the given regular expression pattern.JTextComponent
- Specified by:
requireText
in interfaceTextDisplayDriver<JTextComponent>
- Parameters:
textBox
- the givenJTextComponent
.pattern
- the regular expression pattern to match.- Throws:
NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the text of theJTextComponent
is not equal to the given one.- Since:
- 1.2
-
requireEmpty
Asserts that the given
is empty.JTextComponent
- Parameters:
textBox
- the givenJTextComponent
.- Throws:
AssertionError
- if theJTextComponent
is not empty.
-
textProperty
-
requireEditable
Asserts that the given
is editable.JTextComponent
- Parameters:
textBox
- the givenJTextComponent
.- Throws:
AssertionError
- if theJTextComponent
is not editable.
-
requireNotEditable
Asserts that the given
is not editable.JTextComponent
- Parameters:
textBox
- the givenJTextComponent
.- Throws:
AssertionError
- if theJTextComponent
is editable.
-
assertEditable
-
editableProperty
-
textOf
Returns the text of the given
.JTextComponent
- Specified by:
textOf
in interfaceTextDisplayDriver<JTextComponent>
- Parameters:
textBox
- the givenJTextComponent
.- Returns:
- the text of the given
JTextComponent
. - Since:
- 1.2
-