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
JTextComponents:
- 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 Rectangleprivate voidassertEditable(JTextComponent textBox, boolean editable) private static ActionFailedExceptioncannotGetLocation(JTextComponent textBox, int index) private static PointvoiddeleteText(JTextComponent textBox) Deletes the text of the.JTextComponentprivate static org.fest.assertions.DescriptioneditableProperty(JTextComponent textBox) voidenterText(JTextComponent textBox, String text) Types the given text into the.JTextComponentprivate static Stringprivate static intindexOfText(JTextComponent textBox, String text) private static booleanisRectangleVisible(JTextComponent textBox, Rectangle r) private static RectanglelocationOf(JTextComponent textBox, int index) private static voidperformAndValidateTextSelection(JTextComponent textBox, int start, int end) voidreplaceText(JTextComponent textBox, String text) Types the given text into the, replacing any existing text already there.JTextComponentvoidrequireEditable(JTextComponent textBox) Asserts that the givenis editable.JTextComponentvoidrequireEmpty(JTextComponent textBox) Asserts that the givenis empty.JTextComponentvoidrequireNotEditable(JTextComponent textBox) Asserts that the givenis not editable.JTextComponentvoidrequireText(JTextComponent textBox, String expected) Asserts that the text in the givenis equal to the specified value.JTextComponentvoidrequireText(JTextComponent textBox, Pattern pattern) Asserts that the text in the givenmatches the given regular expression pattern.JTextComponentprivate static PointscrollToPosition(JTextComponent textBox, int index) private static PointscrollToVisible(JTextComponent textBox, int index) Move the pointer to the location of the given index.private static voidscrollToVisible(JTextComponent textBox, Rectangle r) private static voidscrollToVisibleIfIsTextField(JTextComponent textBox, Rectangle r) voidselectAll(JTextComponent textBox) Selects the text in the.JTextComponentvoidselectText(JTextComponent textBox, int start, int end) Select the given text range.voidselectText(JTextComponent textBox, String text) Select the given text range.voidsetText(JTextComponent textBox, String text) Sets the given text into the.JTextComponenttextOf(JTextComponent textBox) Returns the text of the given.JTextComponentprivate static org.fest.assertions.DescriptiontextProperty(JTextComponent textBox) private static PointvalidateAndScrollToPosition(JTextComponent textBox, int index) private static voidverifyTextWasSelected(JTextComponent textBox, int start, int end) 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:
-
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 theJTextComponentis disabled.IllegalStateException- if theJTextComponentis 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 theJTextComponentis disabled.IllegalStateException- if theJTextComponentis not showing on the screen.
-
selectAll
Selects the text in the.JTextComponent- Parameters:
textBox- the targetJTextComponent.- Throws:
IllegalStateException- if theJTextComponentis disabled.IllegalStateException- if theJTextComponentis 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 theJTextComponentis disabled.IllegalStateException- if theJTextComponentis 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 theJTextComponentis disabled.IllegalStateException- if theJTextComponentis not showing on the screen.
-
selectText
Select the given text range.- Parameters:
textBox- the targetJTextComponent.text- the text to select.- Throws:
IllegalStateException- if theJTextComponentis disabled.IllegalStateException- if theJTextComponentis not showing on the screen.IllegalArgumentException- if theJTextComponentdoes 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 theJTextComponentis disabled.IllegalStateException- if theJTextComponentis 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 givenis equal to the specified value.JTextComponent- Specified by:
requireTextin interfaceTextDisplayDriver<JTextComponent>- Parameters:
textBox- the givenJTextComponent.expected- the text to match. It can be a regular expression pattern.- Throws:
AssertionError- if the text of theJTextComponentis not equal to the given one.
-
requireText
Asserts that the text in the givenmatches the given regular expression pattern.JTextComponent- Specified by:
requireTextin 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 theJTextComponentis not equal to the given one.- Since:
- 1.2
-
requireEmpty
Asserts that the givenis empty.JTextComponent- Parameters:
textBox- the givenJTextComponent.- Throws:
AssertionError- if theJTextComponentis not empty.
-
textProperty
-
requireEditable
Asserts that the givenis editable.JTextComponent- Parameters:
textBox- the givenJTextComponent.- Throws:
AssertionError- if theJTextComponentis not editable.
-
requireNotEditable
Asserts that the givenis not editable.JTextComponent- Parameters:
textBox- the givenJTextComponent.- Throws:
AssertionError- if theJTextComponentis editable.
-
assertEditable
-
editableProperty
-
textOf
Returns the text of the given.JTextComponent- Specified by:
textOfin interfaceTextDisplayDriver<JTextComponent>- Parameters:
textBox- the givenJTextComponent.- Returns:
- the text of the given
JTextComponent. - Since:
- 1.2
-