org.fest.swing.driver
Class JTextComponentDriver

java.lang.Object
  extended by org.fest.swing.driver.ComponentDriver
      extended by org.fest.swing.driver.ContainerDriver
          extended by org.fest.swing.driver.JComponentDriver
              extended by org.fest.swing.driver.JTextComponentDriver
All Implemented Interfaces:
TextDisplayDriver<JTextComponent>

public class JTextComponentDriver
extends JComponentDriver
implements TextDisplayDriver<JTextComponent>

Understands functional testing of JTextComponents:

This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
 
Constructor Summary
JTextComponentDriver(Robot robot)
          Creates a new JTextComponentDriver.
 
Method Summary
 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.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTextComponentDriver

public JTextComponentDriver(Robot robot)
Creates a new JTextComponentDriver.

Parameters:
robot - the robot to use to simulate user input.
Method Detail

deleteText

@RunsInEDT
public void deleteText(JTextComponent textBox)
Deletes the text of the JTextComponent.

Parameters:
textBox - the target JTextComponent.
Throws:
IllegalStateException - if the JTextComponent is disabled.
IllegalStateException - if the JTextComponent is not showing on the screen.

replaceText

@RunsInEDT
public void replaceText(JTextComponent textBox,
                                  String text)
Types the given text into the JTextComponent, replacing any existing text already there.

Parameters:
textBox - the target JTextComponent.
text - the text to enter.
Throws:
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.

selectAll

@RunsInEDT
public void selectAll(JTextComponent textBox)
Selects the text in the JTextComponent.

Parameters:
textBox - the target JTextComponent.
Throws:
IllegalStateException - if the JTextComponent is disabled.
IllegalStateException - if the JTextComponent is not showing on the screen.

enterText

@RunsInEDT
public void enterText(JTextComponent textBox,
                                String text)
Types the given text into the JTextComponent.

Parameters:
textBox - the target JTextComponent.
text - the text to enter.
Throws:
IllegalStateException - if the JTextComponent is disabled.
IllegalStateException - if the JTextComponent is not showing on the screen.

setText

@RunsInEDT
public void setText(JTextComponent textBox,
                              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.

Parameters:
textBox - the target JTextComponent.
text - the text to enter.
Throws:
IllegalStateException - if the JTextComponent is disabled.
IllegalStateException - if the JTextComponent is not showing on the screen.

selectText

@RunsInEDT
public void selectText(JTextComponent textBox,
                                 String text)
Select the given text range.

Parameters:
textBox - the target JTextComponent.
text - the text to select.
Throws:
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.

selectText

@RunsInEDT
public void selectText(JTextComponent textBox,
                                 int start,
                                 int end)
Select the given text range.

Parameters:
textBox - the target JTextComponent.
start - the starting index of the selection.
end - the ending index of the selection.
Throws:
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.

requireText

@RunsInEDT
public void requireText(JTextComponent textBox,
                                  String expected)
Asserts that the text in the given JTextComponent is equal to the specified value.

Specified by:
requireText in interface TextDisplayDriver<JTextComponent>
Parameters:
textBox - the given JTextComponent.
expected - the text to match. It can be a regular expression pattern.
Throws:
AssertionError - if the text of the JTextComponent is not equal to the given one.

requireText

@RunsInEDT
public void requireText(JTextComponent textBox,
                                  Pattern pattern)
Asserts that the text in the given JTextComponent matches the given regular expression pattern.

Specified by:
requireText in interface TextDisplayDriver<JTextComponent>
Parameters:
textBox - the given JTextComponent.
pattern - the regular expression pattern to match.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the text of the JTextComponent is not equal to the given one.
Since:
1.2

requireEmpty

@RunsInEDT
public void requireEmpty(JTextComponent textBox)
Asserts that the given JTextComponent is empty.

Parameters:
textBox - the given JTextComponent.
Throws:
AssertionError - if the JTextComponent is not empty.

requireEditable

@RunsInEDT
public void requireEditable(JTextComponent textBox)
Asserts that the given JTextComponent is editable.

Parameters:
textBox - the given JTextComponent.
Throws:
AssertionError - if the JTextComponent is not editable.

requireNotEditable

@RunsInEDT
public void requireNotEditable(JTextComponent textBox)
Asserts that the given JTextComponent is not editable.

Parameters:
textBox - the given JTextComponent.
Throws:
AssertionError - if the JTextComponent is editable.

textOf

@RunsInEDT
public String textOf(JTextComponent textBox)
Returns the text of the given JTextComponent.

Specified by:
textOf in interface TextDisplayDriver<JTextComponent>
Parameters:
textBox - the given JTextComponent.
Returns:
the text of the given JTextComponent.
Since:
1.2


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.