Package org.fest.swing.fixture
Class JTextComponentFixture
java.lang.Object
org.fest.swing.fixture.ComponentFixture<JTextComponent>
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
JTextComponent
s:
- user input simulation
- state verification
- property value query
-
Field Summary
FieldsFields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
-
Constructor Summary
ConstructorsConstructorDescriptionJTextComponentFixture
(Robot robot, String textComponentName) Creates a new
.JTextComponentFixture
JTextComponentFixture
(Robot robot, JTextComponent target) Creates a new
.JTextComponentFixture
-
Method Summary
Modifier and TypeMethodDescriptionclick()
Simulates a user clicking this fixture's
.JTextComponent
click
(MouseButton button) Simulates a user clicking this fixture's
.JTextComponent
click
(MouseClickInfo mouseClickInfo) Simulates a user clicking this fixture's
.JTextComponent
clientProperty
(Object key) Returns the client property stored in this fixture's
, under the given key.JTextComponent
private void
Simulates a user deleting all the text in this fixture's
.JTextComponent
Simulates a user double-clicking this fixture's
.JTextComponent
protected final void
driver
(JTextComponentDriver newDriver) Sets the
to be used by this fixture.JTextComponentDriver
Simulates a user entering the given text in this fixture's
.JTextComponent
focus()
Gives input focus to this fixture's
.JTextComponent
pressAndReleaseKey
(KeyPressInfo keyPressInfo) Simulates a user pressing given key with the given modifiers on this fixture's
.JTextComponent
pressAndReleaseKeys
(int... keyCodes) Simulates a user pressing and releasing the given keys in this fixture's
.JTextComponent
pressKey
(int keyCode) Simulates a user pressing the given key on this fixture's
.JTextComponent
releaseKey
(int keyCode) Simulates a user releasing the given key on this fixture's
.JTextComponent
Asserts that this fixture's
is disabled.JTextComponent
Asserts that this fixture's
is editable.JTextComponent
Asserts that the target text component does not contain any text.Asserts that this fixture's
is enabled.JTextComponent
requireEnabled
(Timeout timeout) Asserts that this fixture's
is enabled.JTextComponent
Asserts that this fixture's
has input focus.JTextComponent
Asserts that this fixture's
is not editable.JTextComponent
Asserts that this fixture's
is not visible.JTextComponent
requireText
(String expected) Asserts that the text of this fixture's
is equal to the specified value.JTextComponent
requireText
(Pattern pattern) Asserts that the text of this fixture's
matches the given regular expression pattern.JTextComponent
requireToolTip
(String expected) Asserts that the toolTip in this fixture's
matches the given value.JTextComponent
requireToolTip
(Pattern pattern) Asserts that the toolTip in this fixture's
matches the given regular expression pattern.JTextComponent
Asserts that this fixture's
is visible.JTextComponent
Simulates a user right-clicking this fixture's
.JTextComponent
Simulates a user selecting the given text contained in this fixture's
.JTextComponent
Simulates a user selecting all the text contained in this fixture's
.JTextComponent
selectText
(int start, int end) Simulates a user selecting a portion of the text contained in this fixture's
.JTextComponent
Sets the text in this fixture's
.JTextComponent
Shows a pop-up menu using this fixture's
as the invoker of the pop-up menu.JTextComponent
Shows a pop-up menu at the given point using this fixture's
as the invoker of the pop-up menu.JTextComponent
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
-
Field Details
-
driver
-
-
Constructor Details
-
JTextComponentFixture
Creates a new
.JTextComponentFixture
- Parameters:
robot
- performs simulation of user events on the givenJTextComponent
.target
- theJTextComponent
to be managed by this fixture.- Throws:
NullPointerException
- ifrobot
isnull
.NullPointerException
- iftarget
isnull
.
-
JTextComponentFixture
Creates a new
.JTextComponentFixture
- Parameters:
robot
- performs simulation of user events on aJTextComponent
.textComponentName
- the name of theJTextComponent
to find using the givenRobot
.- Throws:
NullPointerException
- ifrobot
isnull
.ComponentLookupException
- if a matchingJTextComponent
could not be found.ComponentLookupException
- if more than one matchingJTextComponent
is found.
-
-
Method Details
-
createDriver
private void createDriver() -
driver
Sets the
to be used by this fixture.JTextComponentDriver
- Parameters:
newDriver
- the newJTextComponentDriver
.- Throws:
NullPointerException
- if the given driver isnull
.
-
text
Returns the text of this fixture's
.JTextComponent
- Specified by:
text
in interfaceTextDisplayFixture
- Returns:
- the text of this fixture's
JTextComponent
.
-
select
Simulates a user selecting the given text contained in this fixture's
.JTextComponent
- Specified by:
select
in interfaceTextInputFixture
- Parameters:
text
- the text to select.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.IllegalArgumentException
- if this fixture'sJTextComponent
does not contain the given text to select.ActionFailedException
- if the selecting the text in the given range fails.
-
selectText
Simulates a user selecting a portion of the text contained in this fixture's
.JTextComponent
- Specified by:
selectText
in interfaceTextInputFixture
- Parameters:
start
- index where selection should start.end
- index where selection should end.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.ActionFailedException
- if the selecting the text in the given range fails.
-
selectAll
Simulates a user selecting all the text contained in this fixture's
.JTextComponent
- Specified by:
selectAll
in interfaceTextInputFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
click
Simulates a user clicking this fixture's
.JTextComponent
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
click
Simulates a user clicking this fixture's
.JTextComponent
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
button
- the button to click.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenMouseButton
isnull
.IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
click
Simulates a user clicking this fixture's
.JTextComponent
- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
mouseClickInfo
- specifies the button to click and the times the button should be clicked.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenMouseClickInfo
isnull
.IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
doubleClick
Simulates a user double-clicking this fixture's
.JTextComponent
- Specified by:
doubleClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
rightClick
Simulates a user right-clicking this fixture's
.JTextComponent
- Specified by:
rightClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
deleteText
Simulates a user deleting all the text in this fixture's
.JTextComponent
- Specified by:
deleteText
in interfaceTextInputFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
enterText
Simulates a user entering the given text in this fixture's
.JTextComponent
- Specified by:
enterText
in interfaceTextInputFixture
- Parameters:
text
- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
setText
Sets the text in this fixture's
. UnlikeJTextComponent
, this method bypasses the event system and allows immediate updating on the underlying document model.enterText(String)
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'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
focus
Gives input focus to this fixture's
.JTextComponent
- Specified by:
focus
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.
-
pressAndReleaseKey
Simulates a user pressing given key with the given modifiers on this fixture's
. Modifiers is a mask from the availableJTextComponent
masks.InputEvent
- Specified by:
pressAndReleaseKey
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyPressInfo
- specifies the key and modifiers to press.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the givenKeyPressInfo
isnull
.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.- See Also:
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys in this fixture's
. This method does not affect the current focus.JTextComponent
- Specified by:
pressAndReleaseKeys
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyCodes
- the codes of the keys to press.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given array of codes isnull
.IllegalArgumentException
- if any of the given code is not a valid key code.IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.- See Also:
-
pressKey
Simulates a user pressing the given key on this fixture's
.JTextComponent
- Specified by:
pressKey
in interfaceKeyboardInputSimulationFixture
- 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'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.- See Also:
-
releaseKey
Simulates a user releasing the given key on this fixture's
.JTextComponent
- Specified by:
releaseKey
in interfaceKeyboardInputSimulationFixture
- 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'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.- See Also:
-
requireText
Asserts that the text of this fixture's
is equal to the specified value.JTextComponent
- Specified by:
requireText
in interfaceTextDisplayFixture
- Parameters:
expected
- the text to match. It can be a regular expression pattern.- Returns:
- this fixture.
- Throws:
AssertionError
- if the text of this fixture'sJTextComponent
is not equal to the given one.
-
requireText
Asserts that the text of this fixture's
matches the given regular expression pattern.JTextComponent
- Specified by:
requireText
in interfaceTextDisplayFixture
- Parameters:
pattern
- the regular expression pattern to match.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the text of this fixture'sJTextComponent
is not eual to the given one.- Since:
- 1.2
-
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
Asserts that this fixture's
has input focus.JTextComponent
- Specified by:
requireFocused
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
does not have input focus.
-
requireEnabled
Asserts that this fixture's
is enabled.JTextComponent
- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is disabled.
-
requireEnabled
Asserts that this fixture's
is enabled.JTextComponent
- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Parameters:
timeout
- the time this fixture will wait for the component to be enabled.- Returns:
- this fixture.
- Throws:
WaitTimedOutError
- if this fixture'sJTextComponent
is never enabled.
-
requireDisabled
Asserts that this fixture's
is disabled.JTextComponent
- Specified by:
requireDisabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is enabled.
-
requireVisible
Asserts that this fixture's
is visible.JTextComponent
- Specified by:
requireVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is not visible.
-
requireNotVisible
Asserts that this fixture's
is not visible.JTextComponent
- Specified by:
requireNotVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is visible.
-
requireEditable
Asserts that this fixture's
is editable.JTextComponent
- Specified by:
requireEditable
in interfaceEditableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is not editable.
-
requireNotEditable
Asserts that this fixture's
is not editable.JTextComponent
- Specified by:
requireNotEditable
in interfaceEditableComponentFixture
- Returns:
- this fixture.
- Throws:
AssertionError
- if this fixture'sJTextComponent
is editable.
-
requireToolTip
Asserts that the toolTip in this fixture's
matches the given value.JTextComponent
- Specified by:
requireToolTip
in interfaceToolTipDisplayFixture
- Parameters:
expected
- the given value. It can be a regular expression.- Returns:
- this fixture.
- Throws:
AssertionError
- if the toolTip in this fixture'sJTextComponent
does not match the given value.- Since:
- 1.2
-
requireToolTip
Asserts that the toolTip in this fixture's
matches the given regular expression pattern.JTextComponent
- Specified by:
requireToolTip
in interfaceToolTipDisplayFixture
- Parameters:
pattern
- the regular expression pattern to match.- Returns:
- this fixture.
- Throws:
NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the toolTip in this fixture'sJTextComponent
does not match the given regular expression pattern.- Since:
- 1.2
-
clientProperty
Returns the client property stored in this fixture's
, under the given key.JTextComponent
- Specified by:
clientProperty
in interfaceClientPropertyStorageFixture
- 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 isnull
.- Since:
- 1.2
-
showPopupMenu
Shows a pop-up menu using this fixture's
as the invoker of the pop-up menu.JTextComponent
- Specified by:
showPopupMenu
in interfaceJPopupMenuInvokerFixture
- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException
- if this fixture'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
showPopupMenuAt
Shows a pop-up menu at the given point using this fixture's
as the invoker of the pop-up menu.JTextComponent
- Specified by:
showPopupMenuAt
in interfaceJPopupMenuInvokerFixture
- 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'sJTextComponent
is disabled.IllegalStateException
- if this fixture'sJTextComponent
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-