org.fest.swing.fixture
Class JTextComponentFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JTextComponent>
      extended by org.fest.swing.fixture.JTextComponentFixture
All Implemented Interfaces:
ClientPropertyStorageFixture, CommonComponentFixture, EditableComponentFixture, FocusableComponentFixture, JComponentFixture, JPopupMenuInvokerFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture, TextDisplayFixture, TextInputFixture, ToolTipDisplayFixture

public class JTextComponentFixture
extends ComponentFixture<JTextComponent>
implements CommonComponentFixture, JComponentFixture, JPopupMenuInvokerFixture, TextInputFixture

Understands functional testing of JTextComponents:

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JTextComponentFixture(Robot robot, JTextComponent target)
          Creates a new JTextComponentFixture.
JTextComponentFixture(Robot robot, String textComponentName)
          Creates a new JTextComponentFixture.
 
Method Summary
 JTextComponentFixture click()
          Simulates a user clicking this fixture's JTextComponent.
 JTextComponentFixture click(MouseButton button)
          Simulates a user clicking this fixture's JTextComponent.
 JTextComponentFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JTextComponent.
 Object clientProperty(Object key)
          Returns the client property stored in this fixture's JTextComponent, under the given key.
 JTextComponentFixture deleteText()
          Simulates a user deleting all the text in this fixture's JTextComponent.
 JTextComponentFixture doubleClick()
          Simulates a user double-clicking this fixture's JTextComponent.
protected  void driver(JTextComponentDriver newDriver)
          Sets the JTextComponentDriver to be used by this fixture.
 JTextComponentFixture enterText(String text)
          Simulates a user entering the given text in this fixture's JTextComponent.
 JTextComponentFixture focus()
          Gives input focus to this fixture's JTextComponent.
 JTextComponentFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JTextComponent.
 JTextComponentFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys in this fixture's JTextComponent.
 JTextComponentFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JTextComponent.
 JTextComponentFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JTextComponent.
 JTextComponentFixture requireDisabled()
          Asserts that this fixture's JTextComponent is disabled.
 JTextComponentFixture requireEditable()
          Asserts that this fixture's JTextComponent is editable.
 JTextComponentFixture requireEmpty()
          Asserts that the target text component does not contain any text.
 JTextComponentFixture requireEnabled()
          Asserts that this fixture's JTextComponent is enabled.
 JTextComponentFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JTextComponent is enabled.
 JTextComponentFixture requireFocused()
          Asserts that this fixture's JTextComponent has input focus.
 JTextComponentFixture requireNotEditable()
          Asserts that this fixture's JTextComponent is not editable.
 JTextComponentFixture requireNotVisible()
          Asserts that this fixture's JTextComponent is not visible.
 JTextComponentFixture requireText(Pattern pattern)
          Asserts that the text of this fixture's JTextComponent matches the given regular expression pattern.
 JTextComponentFixture requireText(String expected)
          Asserts that the text of this fixture's JTextComponent is equal to the specified value.
 JTextComponentFixture requireToolTip(Pattern pattern)
          Asserts that the toolTip in this fixture's JTextComponent matches the given regular expression pattern.
 JTextComponentFixture requireToolTip(String expected)
          Asserts that the toolTip in this fixture's JTextComponent matches the given value.
 JTextComponentFixture requireVisible()
          Asserts that this fixture's JTextComponent is visible.
 JTextComponentFixture rightClick()
          Simulates a user right-clicking this fixture's JTextComponent.
 JTextComponentFixture select(String text)
          Simulates a user selecting the given text contained in this fixture's JTextComponent.
 JTextComponentFixture selectAll()
          Simulates a user selecting all the text contained in this fixture's JTextComponent.
 JTextComponentFixture selectText(int start, int end)
          Simulates a user selecting a portion of the text contained in this fixture's JTextComponent.
 JTextComponentFixture setText(String text)
          Sets the text in this fixture's JTextComponent.
 JPopupMenuFixture showPopupMenu()
          Shows a pop-up menu using this fixture's JTextComponent as the invoker of the pop-up menu.
 JPopupMenuFixture showPopupMenuAt(Point p)
          Shows a pop-up menu at the given point using this fixture's JTextComponent as the invoker of the pop-up menu.
 String text()
          Returns the text of this fixture's JTextComponent.
 
Methods inherited from class org.fest.swing.fixture.ComponentFixture
background, component, font, foreground, requireShowing, targetCastedTo, validateNotNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTextComponentFixture

public JTextComponentFixture(Robot robot,
                             JTextComponent target)
Creates a new JTextComponentFixture.

Parameters:
robot - performs simulation of user events on the given JTextComponent.
target - the JTextComponent to be managed by this fixture.
Throws:
NullPointerException - if robot is null.
NullPointerException - if target is null.

JTextComponentFixture

public JTextComponentFixture(Robot robot,
                             String textComponentName)
Creates a new JTextComponentFixture.

Parameters:
robot - performs simulation of user events on a JTextComponent.
textComponentName - the name of the JTextComponent to find using the given Robot.
Throws:
NullPointerException - if robot is null.
ComponentLookupException - if a matching JTextComponent could not be found.
ComponentLookupException - if more than one matching JTextComponent is found.
Method Detail

driver

protected final void driver(JTextComponentDriver newDriver)
Sets the JTextComponentDriver to be used by this fixture.

Parameters:
newDriver - the new JTextComponentDriver.
Throws:
NullPointerException - if the given driver is null.

text

public String text()
Returns the text of this fixture's JTextComponent.

Specified by:
text in interface TextDisplayFixture
Returns:
the text of this fixture's JTextComponent.

select

public JTextComponentFixture select(String text)
Simulates a user selecting the given text contained in this fixture's JTextComponent.

Specified by:
select in interface TextInputFixture
Parameters:
text - the text to select.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
IllegalArgumentException - if this fixture's JTextComponent does not contain the given text to select.
ActionFailedException - if the selecting the text in the given range fails.

selectText

public JTextComponentFixture selectText(int start,
                                        int end)
Simulates a user selecting a portion of the text contained in this fixture's JTextComponent.

Specified by:
selectText in interface TextInputFixture
Parameters:
start - index where selection should start.
end - index where selection should end.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
ActionFailedException - if the selecting the text in the given range fails.

selectAll

public JTextComponentFixture selectAll()
Simulates a user selecting all the text contained in this fixture's JTextComponent.

Specified by:
selectAll in interface TextInputFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

click

public JTextComponentFixture click()
Simulates a user clicking this fixture's JTextComponent.

Specified by:
click in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

click

public JTextComponentFixture click(MouseButton button)
Simulates a user clicking this fixture's JTextComponent.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
button - the button to click.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseButton is null.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

click

public JTextComponentFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JTextComponent.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
mouseClickInfo - specifies the button to click and the times the button should be clicked.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

doubleClick

public JTextComponentFixture doubleClick()
Simulates a user double-clicking this fixture's JTextComponent.

Specified by:
doubleClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

rightClick

public JTextComponentFixture rightClick()
Simulates a user right-clicking this fixture's JTextComponent.

Specified by:
rightClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

deleteText

public JTextComponentFixture deleteText()
Simulates a user deleting all the text in this fixture's JTextComponent.

Specified by:
deleteText in interface TextInputFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

enterText

public JTextComponentFixture enterText(String text)
Simulates a user entering the given text in this fixture's JTextComponent.

Specified by:
enterText in interface TextInputFixture
Parameters:
text - the text to enter.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

setText

public JTextComponentFixture setText(String text)
Sets the text in this fixture's JTextComponent. Unlike enterText(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:
text - the text to set.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

focus

public JTextComponentFixture focus()
Gives input focus to this fixture's JTextComponent.

Specified by:
focus in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.

pressAndReleaseKey

public JTextComponentFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's JTextComponent. Modifiers is a mask from the available InputEvent masks.

Specified by:
pressAndReleaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyPressInfo - specifies the key and modifiers to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given KeyPressInfo is null.
IllegalArgumentException - if the given code is not a valid key code.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
See Also:
KeyPressInfo

pressAndReleaseKeys

public JTextComponentFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys in this fixture's JTextComponent. This method does not affect the current focus.

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - the codes of the keys to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given array of codes is null.
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
See Also:
KeyEvent

pressKey

public JTextComponentFixture pressKey(int keyCode)
Simulates a user pressing the given key on this fixture's JTextComponent.

Specified by:
pressKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to press.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
See Also:
KeyEvent

releaseKey

public JTextComponentFixture releaseKey(int keyCode)
Simulates a user releasing the given key on this fixture's JTextComponent.

Specified by:
releaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to release.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
See Also:
KeyEvent

requireText

public JTextComponentFixture requireText(String expected)
Asserts that the text of this fixture's JTextComponent is equal to the specified value.

Specified by:
requireText in interface TextDisplayFixture
Parameters:
expected - the text to match. It can be a regular expression pattern.
Returns:
this fixture.
Throws:
AssertionError - if the text of this fixture's JTextComponent is not equal to the given one.

requireText

public JTextComponentFixture requireText(Pattern pattern)
Asserts that the text of this fixture's JTextComponent matches the given regular expression pattern.

Specified by:
requireText in interface TextDisplayFixture
Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the text of this fixture's JTextComponent is not eual to the given one.
Since:
1.2

requireEmpty

public JTextComponentFixture requireEmpty()
Asserts that the target text component does not contain any text.

Returns:
this fixture.
Throws:
AssertionError - if the target text component is not empty.

requireFocused

public JTextComponentFixture requireFocused()
Asserts that this fixture's JTextComponent has input focus.

Specified by:
requireFocused in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent does not have input focus.

requireEnabled

public JTextComponentFixture requireEnabled()
Asserts that this fixture's JTextComponent is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is disabled.

requireEnabled

public JTextComponentFixture requireEnabled(Timeout timeout)
Asserts that this fixture's JTextComponent is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Parameters:
timeout - the time this fixture will wait for the component to be enabled.
Returns:
this fixture.
Throws:
WaitTimedOutError - if this fixture's JTextComponent is never enabled.

requireDisabled

public JTextComponentFixture requireDisabled()
Asserts that this fixture's JTextComponent is disabled.

Specified by:
requireDisabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is enabled.

requireVisible

public JTextComponentFixture requireVisible()
Asserts that this fixture's JTextComponent is visible.

Specified by:
requireVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is not visible.

requireNotVisible

public JTextComponentFixture requireNotVisible()
Asserts that this fixture's JTextComponent is not visible.

Specified by:
requireNotVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is visible.

requireEditable

public JTextComponentFixture requireEditable()
Asserts that this fixture's JTextComponent is editable.

Specified by:
requireEditable in interface EditableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is not editable.

requireNotEditable

public JTextComponentFixture requireNotEditable()
Asserts that this fixture's JTextComponent is not editable.

Specified by:
requireNotEditable in interface EditableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JTextComponent is editable.

requireToolTip

public JTextComponentFixture requireToolTip(String expected)
Asserts that the toolTip in this fixture's JTextComponent matches the given value.

Specified by:
requireToolTip in interface ToolTipDisplayFixture
Parameters:
expected - the given value. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the toolTip in this fixture's JTextComponent does not match the given value.
Since:
1.2

requireToolTip

public JTextComponentFixture requireToolTip(Pattern pattern)
Asserts that the toolTip in this fixture's JTextComponent matches the given regular expression pattern.

Specified by:
requireToolTip in interface ToolTipDisplayFixture
Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the toolTip in this fixture's JTextComponent does not match the given regular expression pattern.
Since:
1.2

clientProperty

public Object clientProperty(Object key)
Returns the client property stored in this fixture's JTextComponent, under the given key.

Specified by:
clientProperty in interface ClientPropertyStorageFixture
Parameters:
key - the key to use to retrieve the client property.
Returns:
the value of the client property stored under the given key, or null if the property was not found.
Throws:
NullPointerException - if the given key is null.
Since:
1.2

showPopupMenu

public JPopupMenuFixture showPopupMenu()
Shows a pop-up menu using this fixture's JTextComponent as the invoker of the pop-up menu.

Specified by:
showPopupMenu in interface JPopupMenuInvokerFixture
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.

showPopupMenuAt

public JPopupMenuFixture showPopupMenuAt(Point p)
Shows a pop-up menu at the given point using this fixture's JTextComponent as the invoker of the pop-up menu.

Specified by:
showPopupMenuAt in interface JPopupMenuInvokerFixture
Parameters:
p - the given point where to show the pop-up menu.
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
IllegalStateException - if this fixture's JTextComponent is disabled.
IllegalStateException - if this fixture's JTextComponent is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.


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