org.fest.swing.fixture
Class JSpinnerFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JSpinner>
      extended by org.fest.swing.fixture.JSpinnerFixture
All Implemented Interfaces:
ClientPropertyStorageFixture, CommonComponentFixture, FocusableComponentFixture, JComponentFixture, JPopupMenuInvokerFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture, ToolTipDisplayFixture

public class JSpinnerFixture
extends ComponentFixture<JSpinner>
implements CommonComponentFixture, JComponentFixture, JPopupMenuInvokerFixture

Understands functional testing of JSpinners:

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JSpinnerFixture(Robot robot, JSpinner target)
          Creates a new JSpinnerFixture.
JSpinnerFixture(Robot robot, String spinnerName)
          Creates a new JSpinnerFixture.
 
Method Summary
 JSpinnerFixture click()
          Simulates a user clicking this fixture's JSpinner.
 JSpinnerFixture click(MouseButton button)
          Simulates a user clicking this fixture's JSpinner.
 JSpinnerFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JSpinner.
 Object clientProperty(Object key)
          Returns the client property stored in this fixture's JSpinner, under the given key.
 JSpinnerFixture decrement()
          Simulates a user decrementing the value of this fixture's JSpinner one time.
 JSpinnerFixture decrement(int times)
          Simulates a user decrementing the value of this fixture's JSpinner the given number of times.
 JSpinnerFixture doubleClick()
          Simulates a user double-clicking this fixture's JSpinner.
protected  void driver(JSpinnerDriver newDriver)
          Sets the JSpinnerDriver to be used by this fixture.
 JSpinnerFixture enterText(String text)
          Simulates a user entering the given text in this fixture's JSpinner (assuming its editor has a JTextComponent under it.)
 JSpinnerFixture enterTextAndCommit(String text)
          Simulates a user entering and committing the given text in this fixture's JSpinner (assuming its editor has a JTextComponent under it.)
 JSpinnerFixture focus()
          Gives input focus to this fixture's JSpinner.
 JSpinnerFixture increment()
          Simulates a user incrementing the value of this fixture's JSpinner one time.
 JSpinnerFixture increment(int times)
          Simulates a user incrementing the value of this fixture's JSpinner the given number of times.
 JSpinnerFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JSpinner.
 JSpinnerFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's JSpinner.
 JSpinnerFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JSpinner.
 JSpinnerFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JSpinner.
 JSpinnerFixture requireDisabled()
          Asserts that this fixture's JSpinner is disabled.
 JSpinnerFixture requireEnabled()
          Asserts that this fixture's JSpinner is enabled.
 JSpinnerFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JSpinner is enabled.
 JSpinnerFixture requireFocused()
          Asserts that this fixture's JSpinner has input focus.
 JSpinnerFixture requireNotVisible()
          Asserts that this fixture's JSpinner is not visible.
 JSpinnerFixture requireToolTip(Pattern pattern)
          Asserts that the toolTip in this fixture's JSpinner matches the given regular expression pattern.
 JSpinnerFixture requireToolTip(String expected)
          Asserts that the toolTip in this fixture's JSpinner matches the given value.
 JSpinnerFixture requireValue(Object value)
          Verifies that the value of this fixture's JSpinner is equal to the given one.
 JSpinnerFixture requireVisible()
          Asserts that this fixture's JSpinner is visible.
 JSpinnerFixture rightClick()
          Simulates a user right-clicking this fixture's JSpinner.
 Object select(Object value)
          Selects the given value in this fixture's JSpinner.
 JPopupMenuFixture showPopupMenu()
          Shows a pop-up menu using this fixture's JSpinner 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 JSpinner as the invoker of the pop-up menu.
 String text()
          Returns the text displayed by this fixture's JSpinner.
 
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

JSpinnerFixture

public JSpinnerFixture(Robot robot,
                       String spinnerName)
Creates a new JSpinnerFixture.

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

JSpinnerFixture

public JSpinnerFixture(Robot robot,
                       JSpinner target)
Creates a new JSpinnerFixture.

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

driver

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

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

increment

public JSpinnerFixture increment(int times)
Simulates a user incrementing the value of this fixture's JSpinner the given number of times.

Parameters:
times - how many times the value of this fixture's JSpinner should be incremented.
Returns:
this fixture.
Throws:
IllegalArgumentException - if times is less than or equal to zero.
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

increment

public JSpinnerFixture increment()
Simulates a user incrementing the value of this fixture's JSpinner one time.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

decrement

public JSpinnerFixture decrement(int times)
Simulates a user decrementing the value of this fixture's JSpinner the given number of times.

Parameters:
times - how many times the value of this fixture's JSpinner should be decremented.
Returns:
this fixture.
Throws:
IllegalArgumentException - if times is less than or equal to zero.
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

decrement

public JSpinnerFixture decrement()
Simulates a user decrementing the value of this fixture's JSpinner one time.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

enterText

public JSpinnerFixture enterText(String text)
Simulates a user entering the given text in this fixture's JSpinner (assuming its editor has a JTextComponent under it.) This method does not commit the value to the JSpinner.

Parameters:
text - the text to enter.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
ActionFailedException - if the editor of the JSpinner is not a JTextComponent or cannot be found.
UnexpectedException - if the entering the text in the JSpinner's editor fails.

enterTextAndCommit

public JSpinnerFixture enterTextAndCommit(String text)
Simulates a user entering and committing the given text in this fixture's JSpinner (assuming its editor has a JTextComponent under it.)

Parameters:
text - the text to enter.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
ActionFailedException - if the editor of the JSpinner is not a JTextComponent or cannot be found.
UnexpectedException - if the entering the text in the JSpinner's editor fails.

select

public Object select(Object value)
Selects the given value in this fixture's JSpinner.

Parameters:
value - the value to select.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
IllegalArgumentException - if the JSpinner does not support the specified value.

click

public JSpinnerFixture click()
Simulates a user clicking this fixture's JSpinner.

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

click

public JSpinnerFixture click(MouseButton button)
Simulates a user clicking this fixture's JSpinner.

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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

click

public JSpinnerFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JSpinner.

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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.

rightClick

public JSpinnerFixture rightClick()
Simulates a user right-clicking this fixture's JSpinner.

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

doubleClick

public JSpinnerFixture doubleClick()
Simulates a user double-clicking this fixture's JSpinner.

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

focus

public JSpinnerFixture focus()
Gives input focus to this fixture's JSpinner.

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

pressAndReleaseKey

public JSpinnerFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's JSpinner. 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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
See Also:
KeyPressInfo

pressAndReleaseKeys

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

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - one or more 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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
See Also:
KeyEvent

pressKey

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

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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
See Also:
KeyEvent

releaseKey

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

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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner is not showing on the screen.
See Also:
KeyEvent

requireFocused

public JSpinnerFixture requireFocused()
Asserts that this fixture's JSpinner has input focus.

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

requireEnabled

public JSpinnerFixture requireEnabled()
Asserts that this fixture's JSpinner is enabled.

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

requireEnabled

public JSpinnerFixture requireEnabled(Timeout timeout)
Asserts that this fixture's JSpinner 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 JSpinner is never enabled.

requireDisabled

public JSpinnerFixture requireDisabled()
Asserts that this fixture's JSpinner is disabled.

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

requireVisible

public JSpinnerFixture requireVisible()
Asserts that this fixture's JSpinner is visible.

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

requireNotVisible

public JSpinnerFixture requireNotVisible()
Asserts that this fixture's JSpinner is not visible.

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

requireValue

public JSpinnerFixture requireValue(Object value)
Verifies that the value of this fixture's JSpinner is equal to the given one.

Parameters:
value - the expected value of this fixture's JSpinner.
Returns:
this fixture.
Throws:
AssertionError - if the value of this fixture's JSpinner is not equal to the given one.

text

public String text()
Returns the text displayed by this fixture's JSpinner. This method first tries to get the text displayed in the JSpinner's editor, assuming it is a JTextComponent. If the text from the editor cannot be retrieved, it will return the String representation of the value in the JSpinner's model.

Returns:
the text displayed by this fixture's JSpinner.
Since:
1.2

requireToolTip

public JSpinnerFixture requireToolTip(String expected)
Asserts that the toolTip in this fixture's JSpinner 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 JSpinner does not match the given value.
Since:
1.2

requireToolTip

public JSpinnerFixture requireToolTip(Pattern pattern)
Asserts that the toolTip in this fixture's JSpinner 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 JSpinner does not match the given regular expression.
Since:
1.2

clientProperty

public Object clientProperty(Object key)
Returns the client property stored in this fixture's JSpinner, 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 JSpinner 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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner 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 JSpinner 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 JSpinner is disabled.
IllegalStateException - if this fixture's JSpinner 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.