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
JTextComponents:
- 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.JTextComponentFixtureJTextComponentFixture(Robot robot, JTextComponent target) Creates a new.JTextComponentFixture -
Method Summary
Modifier and TypeMethodDescriptionclick()Simulates a user clicking this fixture's.JTextComponentclick(MouseButton button) Simulates a user clicking this fixture's.JTextComponentclick(MouseClickInfo mouseClickInfo) Simulates a user clicking this fixture's.JTextComponentclientProperty(Object key) Returns the client property stored in this fixture's, under the given key.JTextComponentprivate voidSimulates a user deleting all the text in this fixture's.JTextComponentSimulates a user double-clicking this fixture's.JTextComponentprotected final voiddriver(JTextComponentDriver newDriver) Sets theto be used by this fixture.JTextComponentDriverSimulates a user entering the given text in this fixture's.JTextComponentfocus()Gives input focus to this fixture's.JTextComponentpressAndReleaseKey(KeyPressInfo keyPressInfo) Simulates a user pressing given key with the given modifiers on this fixture's.JTextComponentpressAndReleaseKeys(int... keyCodes) Simulates a user pressing and releasing the given keys in this fixture's.JTextComponentpressKey(int keyCode) Simulates a user pressing the given key on this fixture's.JTextComponentreleaseKey(int keyCode) Simulates a user releasing the given key on this fixture's.JTextComponentAsserts that this fixture'sis disabled.JTextComponentAsserts that this fixture'sis editable.JTextComponentAsserts that the target text component does not contain any text.Asserts that this fixture'sis enabled.JTextComponentrequireEnabled(Timeout timeout) Asserts that this fixture'sis enabled.JTextComponentAsserts that this fixture'shas input focus.JTextComponentAsserts that this fixture'sis not editable.JTextComponentAsserts that this fixture'sis not visible.JTextComponentrequireText(String expected) Asserts that the text of this fixture'sis equal to the specified value.JTextComponentrequireText(Pattern pattern) Asserts that the text of this fixture'smatches the given regular expression pattern.JTextComponentrequireToolTip(String expected) Asserts that the toolTip in this fixture'smatches the given value.JTextComponentrequireToolTip(Pattern pattern) Asserts that the toolTip in this fixture'smatches the given regular expression pattern.JTextComponentAsserts that this fixture'sis visible.JTextComponentSimulates a user right-clicking this fixture's.JTextComponentSimulates a user selecting the given text contained in this fixture's.JTextComponentSimulates a user selecting all the text contained in this fixture's.JTextComponentselectText(int start, int end) Simulates a user selecting a portion of the text contained in this fixture's.JTextComponentSets the text in this fixture's.JTextComponentShows a pop-up menu using this fixture'sas the invoker of the pop-up menu.JTextComponentShows a pop-up menu at the given point using this fixture'sas the invoker of the pop-up menu.JTextComponenttext()Returns the text of this fixture's.JTextComponentMethods 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- theJTextComponentto be managed by this fixture.- Throws:
NullPointerException- ifrobotisnull.NullPointerException- iftargetisnull.
-
JTextComponentFixture
Creates a new.JTextComponentFixture- Parameters:
robot- performs simulation of user events on aJTextComponent.textComponentName- the name of theJTextComponentto find using the givenRobot.- Throws:
NullPointerException- ifrobotisnull.ComponentLookupException- if a matchingJTextComponentcould not be found.ComponentLookupException- if more than one matchingJTextComponentis found.
-
-
Method Details
-
createDriver
private void createDriver() -
driver
Sets theto 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:
textin 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:
selectin interfaceTextInputFixture- Parameters:
text- the text to select.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.IllegalArgumentException- if this fixture'sJTextComponentdoes 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:
selectTextin interfaceTextInputFixture- Parameters:
start- index where selection should start.end- index where selection should end.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis 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:
selectAllin interfaceTextInputFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
click
Simulates a user clicking this fixture's.JTextComponent- Specified by:
clickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
click
Simulates a user clicking this fixture's.JTextComponent- Specified by:
clickin interfaceMouseInputSimulationFixture- Parameters:
button- the button to click.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenMouseButtonisnull.IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
click
Simulates a user clicking this fixture's.JTextComponent- Specified by:
clickin interfaceMouseInputSimulationFixture- Parameters:
mouseClickInfo- specifies the button to click and the times the button should be clicked.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenMouseClickInfoisnull.IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
doubleClick
Simulates a user double-clicking this fixture's.JTextComponent- Specified by:
doubleClickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
rightClick
Simulates a user right-clicking this fixture's.JTextComponent- Specified by:
rightClickin interfaceMouseInputSimulationFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
deleteText
Simulates a user deleting all the text in this fixture's.JTextComponent- Specified by:
deleteTextin interfaceTextInputFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
enterText
Simulates a user entering the given text in this fixture's.JTextComponent- Specified by:
enterTextin interfaceTextInputFixture- Parameters:
text- the text to enter.- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis 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'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.
-
focus
Gives input focus to this fixture's.JTextComponent- Specified by:
focusin interfaceFocusableComponentFixture- Returns:
- this fixture.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis 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 availableJTextComponentmasks.InputEvent- Specified by:
pressAndReleaseKeyin interfaceKeyboardInputSimulationFixture- Parameters:
keyPressInfo- specifies the key and modifiers to press.- Returns:
- this fixture.
- Throws:
NullPointerException- if the givenKeyPressInfoisnull.IllegalArgumentException- if the given code is not a valid key code.IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis 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:
pressAndReleaseKeysin 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'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.- See Also:
-
pressKey
Simulates a user pressing the given key on this fixture's.JTextComponent- Specified by:
pressKeyin 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'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.- See Also:
-
releaseKey
Simulates a user releasing the given key on this fixture's.JTextComponent- Specified by:
releaseKeyin 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'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.- See Also:
-
requireText
Asserts that the text of this fixture'sis equal to the specified value.JTextComponent- Specified by:
requireTextin 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'sJTextComponentis not equal to the given one.
-
requireText
Asserts that the text of this fixture'smatches the given regular expression pattern.JTextComponent- Specified by:
requireTextin 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'sJTextComponentis 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'shas input focus.JTextComponent- Specified by:
requireFocusedin interfaceFocusableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentdoes not have input focus.
-
requireEnabled
Asserts that this fixture'sis enabled.JTextComponent- Specified by:
requireEnabledin interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis disabled.
-
requireEnabled
Asserts that this fixture'sis enabled.JTextComponent- Specified by:
requireEnabledin interfaceStateVerificationFixture- Parameters:
timeout- the time this fixture will wait for the component to be enabled.- Returns:
- this fixture.
- Throws:
WaitTimedOutError- if this fixture'sJTextComponentis never enabled.
-
requireDisabled
Asserts that this fixture'sis disabled.JTextComponent- Specified by:
requireDisabledin interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis enabled.
-
requireVisible
Asserts that this fixture'sis visible.JTextComponent- Specified by:
requireVisiblein interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis not visible.
-
requireNotVisible
Asserts that this fixture'sis not visible.JTextComponent- Specified by:
requireNotVisiblein interfaceStateVerificationFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis visible.
-
requireEditable
Asserts that this fixture'sis editable.JTextComponent- Specified by:
requireEditablein interfaceEditableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis not editable.
-
requireNotEditable
Asserts that this fixture'sis not editable.JTextComponent- Specified by:
requireNotEditablein interfaceEditableComponentFixture- Returns:
- this fixture.
- Throws:
AssertionError- if this fixture'sJTextComponentis editable.
-
requireToolTip
Asserts that the toolTip in this fixture'smatches the given value.JTextComponent- Specified by:
requireToolTipin interfaceToolTipDisplayFixture- Parameters:
expected- the given value. It can be a regular expression.- Returns:
- this fixture.
- Throws:
AssertionError- if the toolTip in this fixture'sJTextComponentdoes not match the given value.- Since:
- 1.2
-
requireToolTip
Asserts that the toolTip in this fixture'smatches the given regular expression pattern.JTextComponent- Specified by:
requireToolTipin 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'sJTextComponentdoes 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:
clientPropertyin 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
nullif the property was not found. - Throws:
NullPointerException- if the given key isnull.- Since:
- 1.2
-
showPopupMenu
Shows a pop-up menu using this fixture'sas the invoker of the pop-up menu.JTextComponent- Specified by:
showPopupMenuin interfaceJPopupMenuInvokerFixture- Returns:
- a fixture that manages the displayed pop-up menu.
- Throws:
IllegalStateException- if this fixture'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis 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'sas the invoker of the pop-up menu.JTextComponent- Specified by:
showPopupMenuAtin 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'sJTextComponentis disabled.IllegalStateException- if this fixture'sJTextComponentis not showing on the screen.ComponentLookupException- if a pop-up menu cannot be found.
-