org.fest.swing.fixture
Class JPopupMenuFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JPopupMenu>
      extended by org.fest.swing.fixture.JPopupMenuFixture
All Implemented Interfaces:
CommonComponentFixture, FocusableComponentFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture

public class JPopupMenuFixture
extends ComponentFixture<JPopupMenu>
implements CommonComponentFixture

Understands functional testing of JPopupMenus:

Author:
Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JPopupMenuFixture(Robot robot, JPopupMenu target)
          Creates a new JPopupMenuFixture.
 
Method Summary
 JPopupMenuFixture click()
          Simulates a user clicking this fixture's JPopupMenu.
 JPopupMenuFixture click(MouseButton button)
          Simulates a user clicking this fixture's JPopupMenu.
 JPopupMenuFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JPopupMenu.
 JPopupMenuFixture doubleClick()
          Simulates a user double-clicking this fixture's JPopupMenu.
protected  void driver(JPopupMenuDriver newDriver)
          Sets the JPopupMenuDriver to be used by this fixture.
 JPopupMenuFixture focus()
          Gives input focus to this fixture's JPopupMenu.
 JMenuItemFixture menuItem(GenericTypeMatcher<? extends JMenuItem> matcher)
          Finds a JMenuItem, contained in this fixture's JPopupMenu, that matches the specified search criteria.
 JMenuItemFixture menuItem(String name)
          Finds a JMenuItem, contained in this fixture's JPopupMenu, which name matches the specified one.
 JMenuItemFixture menuItemWithPath(String... path)
          Finds a JMenuItem in this fixture's JPopupMenu, which path matches the given one.
 String[] menuLabels()
          Returns the contents of this fixture's JPopupMenu.
 JPopupMenuFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JPopupMenu.
 JPopupMenuFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's JPopupMenu.
 JPopupMenuFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JPopupMenu.
 JPopupMenuFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JPopupMenu.
 JPopupMenuFixture requireDisabled()
          Asserts that this fixture's JPopupMenu is disabled.
 JPopupMenuFixture requireEnabled()
          Asserts that this fixture's JPopupMenu is enabled.
 JPopupMenuFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JPopupMenu is enabled.
 JPopupMenuFixture requireFocused()
          Asserts that this fixture's JPopupMenu has input focus.
 JPopupMenuFixture requireNotVisible()
          Asserts that this fixture's JPopupMenu is not visible.
 JPopupMenuFixture requireVisible()
          Asserts that this fixture's JPopupMenu is visible.
 JPopupMenuFixture rightClick()
          Simulates a user right-clicking this fixture's JPopupMenu.
 
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

JPopupMenuFixture

public JPopupMenuFixture(Robot robot,
                         JPopupMenu target)
Creates a new JPopupMenuFixture.

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

driver

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

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

menuItem

public JMenuItemFixture menuItem(String name)
Finds a JMenuItem, contained in this fixture's JPopupMenu, which name matches the specified one.

Parameters:
name - the name to match.
Returns:
a fixture that manages the JMenuItem found.
Throws:
ComponentLookupException - if a JMenuItem having a matching name could not be found.
ComponentLookupException - if more than one JMenuItem having a matching name is found.

menuItem

public JMenuItemFixture menuItem(GenericTypeMatcher<? extends JMenuItem> matcher)
Finds a JMenuItem, contained in this fixture's JPopupMenu, that matches the specified search criteria.

Parameters:
matcher - contains the search criteria for finding a JMenuItem.
Returns:
a fixture that manages the JMenuItem found.
Throws:
ComponentLookupException - if a JMenuItem that matches the given search criteria could not be found.
ComponentLookupException - if more than one JMenuItem that matches the given search criteria is found.

menuItemWithPath

public JMenuItemFixture menuItemWithPath(String... path)
Finds a JMenuItem in this fixture's JPopupMenu, which path matches the given one.

For example, if we are looking for the menu with text "New" contained under the menu with text "File", we can simply call

 JPopupMenuFixture popupMenu = tree.showPopupMenu();
 JMenuItemFixture menuItem = popupMenu.menuItemWithPath("File", "Menu");
 

Parameters:
path - the path of the menu to find.
Returns:
a fixture that manages the JMenuItem found.
Throws:
ComponentLookupException - if a JMenuItem under the given path could not be found.
AssertionError - if the Component found under the given path is not a JMenuItem.

menuLabels

public String[] menuLabels()
Returns the contents of this fixture's JPopupMenu.

Returns:
a String array representing the contents of this fixture's JPopupMenu.

click

public JPopupMenuFixture click()
Simulates a user clicking this fixture's JPopupMenu.

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

click

public JPopupMenuFixture click(MouseButton button)
Simulates a user clicking this fixture's JPopupMenu.

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

click

public JPopupMenuFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JPopupMenu.

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

rightClick

public JPopupMenuFixture rightClick()
Simulates a user right-clicking this fixture's JPopupMenu.

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

doubleClick

public JPopupMenuFixture doubleClick()
Simulates a user double-clicking this fixture's JPopupMenu.

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

focus

public JPopupMenuFixture focus()
Gives input focus to this fixture's JPopupMenu.

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

pressAndReleaseKey

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

pressAndReleaseKeys

public JPopupMenuFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys on this fixture's JPopupMenu. 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 JPopupMenu is disabled.
IllegalStateException - if this fixture's JPopupMenu is not showing on the screen.
See Also:
KeyEvent

pressKey

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

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

releaseKey

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

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

requireFocused

public JPopupMenuFixture requireFocused()
Asserts that this fixture's JPopupMenu has input focus.

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

requireEnabled

public JPopupMenuFixture requireEnabled()
Asserts that this fixture's JPopupMenu is enabled.

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

requireEnabled

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

requireDisabled

public JPopupMenuFixture requireDisabled()
Asserts that this fixture's JPopupMenu is disabled.

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

requireVisible

public JPopupMenuFixture requireVisible()
Asserts that this fixture's JPopupMenu is visible.

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

requireNotVisible

public JPopupMenuFixture requireNotVisible()
Asserts that this fixture's JPopupMenu is not visible.

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


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