org.fest.swing.fixture
Class JMenuItemFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JMenuItem>
      extended by org.fest.swing.fixture.JMenuItemFixture
All Implemented Interfaces:
KeyboardInputSimulationFixture, StateVerificationFixture

public class JMenuItemFixture
extends ComponentFixture<JMenuItem>
implements KeyboardInputSimulationFixture, StateVerificationFixture

Understands functional testing of JMenuItems:

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JMenuItemFixture(Robot robot, JMenuItem target)
          Creates a new JMenuItemFixture.
JMenuItemFixture(Robot robot, String menuItemName)
          Creates a new JMenuItemFixture.
 
Method Summary
 JMenuItemFixture click()
          Simulates a user selecting this fixture's JMenuItem.
protected  void driver(JMenuItemDriver newDriver)
          Sets the JMenuItemDriver to be used by this fixture.
 JMenuItemFixture focus()
          Gives input focus to this fixture's JMenuItem.
 JMenuItemFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JMenuItem.
 JMenuItemFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's JMenuItem.
 JMenuItemFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JMenuItem.
 JMenuItemFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JMenuItem.
 JMenuItemFixture requireDisabled()
          Asserts that this fixture's JMenuItem is disabled.
 JMenuItemFixture requireEnabled()
          Asserts that this fixture's JMenuItem is enabled.
 JMenuItemFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JMenuItem is enabled.
 JMenuItemFixture requireNotVisible()
          Asserts that this fixture's JMenuItem is not visible.
 JMenuItemFixture requireVisible()
          Asserts that this fixture's JMenuItem is visible.
 
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

JMenuItemFixture

public JMenuItemFixture(Robot robot,
                        String menuItemName)
Creates a new JMenuItemFixture.

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

JMenuItemFixture

public JMenuItemFixture(Robot robot,
                        JMenuItem target)
Creates a new JMenuItemFixture.

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

driver

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

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

click

public JMenuItemFixture click()
Simulates a user selecting this fixture's JMenuItem.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JMenuItem is disabled.
IllegalStateException - if this fixture's JMenuItem is not showing on the screen.
ActionFailedException - if the menu has a pop-up and it fails to show up.

focus

public JMenuItemFixture focus()
Gives input focus to this fixture's JMenuItem.

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

pressAndReleaseKey

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

pressAndReleaseKeys

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

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - one or more codes of the keys to press.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JMenuItem is disabled.
IllegalStateException - if this fixture's JMenuItem is not showing on the screen.
See Also:
KeyEvent

pressKey

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

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

releaseKey

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

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

requireEnabled

public JMenuItemFixture requireEnabled()
Asserts that this fixture's JMenuItem is enabled.

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

requireEnabled

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

requireDisabled

public JMenuItemFixture requireDisabled()
Asserts that this fixture's JMenuItem is disabled.

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

requireVisible

public JMenuItemFixture requireVisible()
Asserts that this fixture's JMenuItem is visible.

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

requireNotVisible

public JMenuItemFixture requireNotVisible()
Asserts that this fixture's JMenuItem is not visible.

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


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