org.fest.swing.fixture
Class JButtonFixture

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

public class JButtonFixture
extends ComponentFixture<JButton>
implements CommonComponentFixture, JComponentFixture, JPopupMenuInvokerFixture, TextDisplayFixture

Understands functional testing of JButtons:

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
JButtonFixture(Robot robot, JButton target)
          Creates a new JButtonFixture.
JButtonFixture(Robot robot, String buttonName)
          Creates a new JButtonFixture.
 
Method Summary
 JButtonFixture click()
          Simulates a user clicking this fixture's JButton.
 JButtonFixture click(MouseButton button)
          Simulates a user clicking this fixture's JButton.
 JButtonFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JButton.
 Object clientProperty(Object key)
          Returns the client property stored in this fixture's JButton, under the given key.
 JButtonFixture doubleClick()
          Simulates a user double-clicking this fixture's JButton.
protected  void driver(AbstractButtonDriver newDriver)
          Sets the AbstractButtonDriver to be used by this fixture.
 JButtonFixture focus()
          Gives input focus to this fixture's JButton.
 JButtonFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JButton.
 JButtonFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's JButton.
 JButtonFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JButton.
 JButtonFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JButton.
 JButtonFixture requireDisabled()
          Asserts that this fixture's JButton is disabled.
 JButtonFixture requireEnabled()
          Asserts that this fixture's JButton is enabled.
 JButtonFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JButton is enabled.
 JButtonFixture requireFocused()
          Asserts that this fixture's JButton has input focus.
 JButtonFixture requireNotVisible()
          Asserts that this fixture's JButton is not visible.
 JButtonFixture requireText(Pattern pattern)
          Asserts that the text of this fixture's JButton matches the given regular expression pattern.
 JButtonFixture requireText(String expected)
          Asserts that the text of this fixture's JButton matches the specified value.
 JButtonFixture requireToolTip(Pattern pattern)
          Asserts that the toolTip in this fixture's JButton matches the given regular expression pattern.
 JButtonFixture requireToolTip(String expected)
          Asserts that the toolTip in this fixture's JButton matches the given value.
 JButtonFixture requireVisible()
          Asserts that this fixture's JButton is visible.
 JButtonFixture rightClick()
          Simulates a user right-clicking this fixture's JButton.
 JPopupMenuFixture showPopupMenu()
          Shows a pop-up menu using this fixture's JButton 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 JButton as the invoker of the pop-up menu.
 String text()
          Returns the text of this fixture's JButton.
 
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

JButtonFixture

public JButtonFixture(Robot robot,
                      JButton target)
Creates a new JButtonFixture.

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

JButtonFixture

public JButtonFixture(Robot robot,
                      String buttonName)
Creates a new JButtonFixture.

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

driver

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

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

text

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

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

click

public JButtonFixture click()
Simulates a user clicking this fixture's JButton.

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

click

public JButtonFixture click(MouseButton button)
Simulates a user clicking this fixture's JButton.

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

click

public JButtonFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JButton.

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

doubleClick

public JButtonFixture doubleClick()
Simulates a user double-clicking this fixture's JButton.

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

rightClick

public JButtonFixture rightClick()
Simulates a user right-clicking this fixture's JButton.

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

focus

public JButtonFixture focus()
Gives input focus to this fixture's JButton.

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

pressAndReleaseKey

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

pressAndReleaseKeys

public JButtonFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys on this fixture's JButton.

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

pressKey

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

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

releaseKey

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

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

requireFocused

public JButtonFixture requireFocused()
Asserts that this fixture's JButton has input focus.

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

requireEnabled

public JButtonFixture requireEnabled()
Asserts that this fixture's JButton is enabled.

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

requireEnabled

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

requireDisabled

public JButtonFixture requireDisabled()
Asserts that this fixture's JButton is disabled.

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

requireVisible

public JButtonFixture requireVisible()
Asserts that this fixture's JButton is visible.

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

requireNotVisible

public JButtonFixture requireNotVisible()
Asserts that this fixture's JButton is not visible.

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

requireText

public JButtonFixture requireText(String expected)
Asserts that the text of this fixture's JButton matches the specified value.

Specified by:
requireText in interface TextDisplayFixture
Parameters:
expected - the text to match. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the text of the target JButton does not match the given one.

requireText

public JButtonFixture requireText(Pattern pattern)
Asserts that the text of this fixture's JButton 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 the target JButton does not match the given regular expression pattern.
Since:
1.2

requireToolTip

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

requireToolTip

public JButtonFixture requireToolTip(Pattern pattern)
Asserts that the toolTip in this fixture's JButton 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 JButton 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 JButton, 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 JButton 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 JButton is disabled.
IllegalStateException - if this fixture's JButton 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 JButton 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 JButton is disabled.
IllegalStateException - if this fixture's JButton 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.