org.fest.swing.fixture
Class JOptionPaneFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<T>
      extended by org.fest.swing.fixture.ContainerFixture<JOptionPane>
          extended by org.fest.swing.fixture.JOptionPaneFixture
All Implemented Interfaces:
CommonComponentFixture, ComponentContainerFixture, FocusableComponentFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture

public class JOptionPaneFixture
extends ContainerFixture<JOptionPane>
implements CommonComponentFixture

Understands functional testing of JOptionPanes:

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Fields inherited from interface org.fest.swing.fixture.ComponentContainerFixture
DEFAULT_DIALOG_LOOKUP_TIMEOUT
 
Constructor Summary
JOptionPaneFixture(Robot robot)
          Creates a new JOptionPaneFixture.
JOptionPaneFixture(Robot robot, JOptionPane target)
          Creates a new JOptionPaneFixture.
 
Method Summary
 JButtonFixture buttonWithText(Pattern pattern)
          Finds and returns a fixture wrapping a button (this fixture's JOptionPane) matching the given text.
 JButtonFixture buttonWithText(String text)
          Finds and returns a fixture wrapping a button (this fixture's JOptionPane) matching the given text.
 JButtonFixture cancelButton()
          Returns a fixture wrapping the "Cancel" button in this fixture's JOptionPane.
 JOptionPaneFixture click()
          Simulates a user clicking this fixture's JOptionPane.
 JOptionPaneFixture click(MouseButton button)
          Simulates a user clicking this fixture's JOptionPane.
 JOptionPaneFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JOptionPane.
 JOptionPaneFixture doubleClick()
          Simulates a user double-clicking this fixture's JOptionPane.
protected  void driver(JOptionPaneDriver newDriver)
          Sets the JOptionPaneDriver to be used by this fixture.
 JOptionPaneFixture focus()
          Gives input focus to this fixture's JOptionPane.
 JButtonFixture noButton()
          Returns a fixture wrapping the "No" button in this fixture's JOptionPane.
 JButtonFixture okButton()
          Returns a fixture wrapping the "OK" button in this fixture's JOptionPane.
 JOptionPaneFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JOptionPane.
 JOptionPaneFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys this fixture's JOptionPane.
 JOptionPaneFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JOptionPane.
 JOptionPaneFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JOptionPane.
 JOptionPaneFixture requireDisabled()
          Asserts that this fixture's JOptionPane is disabled.
 JOptionPaneFixture requireEnabled()
          Asserts that this fixture's JOptionPane is enabled.
 JOptionPaneFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JOptionPane is enabled.
 JOptionPaneFixture requireErrorMessage()
          Asserts that this fixture's JOptionPane is displaying an error message.
 JOptionPaneFixture requireFocused()
          Asserts that this fixture's JOptionPane has input focus.
 JOptionPaneFixture requireInformationMessage()
          Asserts that this fixture's JOptionPane is displaying an information message.
 JOptionPaneFixture requireMessage(Object message)
          Asserts that the message of this fixture's JOptionPane matches the given value.
 JOptionPaneFixture requireMessage(Pattern pattern)
          Asserts that the message of this fixture's JOptionPane matches the given regular expression pattern.
 JOptionPaneFixture requireNotVisible()
          Asserts that this fixture's JOptionPane is not visible.
 JOptionPaneFixture requireOptions(Object[] options)
          Asserts that this fixture's JOptionPane has the given options.
 JOptionPaneFixture requirePlainMessage()
          Asserts that this fixture's JOptionPane is displaying a plain message.
 JOptionPaneFixture requireQuestionMessage()
          Asserts that this fixture's JOptionPane is displaying a question.
 JOptionPaneFixture requireTitle(Pattern pattern)
          Asserts that the title of this fixture's JOptionPane matches the given regular expression pattern.
 JOptionPaneFixture requireTitle(String title)
          Asserts that the title of this fixture's JOptionPane matches the given value.
 JOptionPaneFixture requireVisible()
          Asserts that this fixture's JOptionPane is visible.
 JOptionPaneFixture requireWarningMessage()
          Asserts that this fixture's JOptionPane is displaying a warning message.
 JOptionPaneFixture rightClick()
          Simulates a user right-clicking this fixture's JOptionPane.
 String title()
          Returns the title of this fixture's JOptionPane.
 JButtonFixture yesButton()
          Returns a fixture wrapping the "Yes" button in this fixture's JOptionPane.
 
Methods inherited from class org.fest.swing.fixture.ContainerFixture
button, button, button, checkBox, checkBox, checkBox, comboBox, comboBox, comboBox, dialog, dialog, dialog, dialog, dialog, dialog, fileChooser, fileChooser, fileChooser, fileChooser, fileChooser, fileChooser, find, findByName, findByType, finder, label, label, label, list, list, list, menuItem, menuItem, menuItemWithPath, optionPane, optionPane, panel, panel, panel, progressBar, progressBar, progressBar, radioButton, radioButton, radioButton, scrollBar, scrollBar, scrollBar, scrollPane, scrollPane, scrollPane, slider, slider, slider, spinner, spinner, spinner, splitPane, splitPane, splitPane, tabbedPane, tabbedPane, tabbedPane, table, table, table, textBox, textBox, textBox, toggleButton, toggleButton, toggleButton, toolBar, toolBar, toolBar, tree, tree, tree, with
 
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

JOptionPaneFixture

public JOptionPaneFixture(Robot robot)
Creates a new JOptionPaneFixture.

Parameters:
robot - finds a showing JOptionPane, which will be managed by this fixture.
Throws:
NullPointerException - if robot is null.
ComponentLookupException - if a showing JOptionPane could not be found.
ComponentLookupException - if more than one showing JOptionPane is found.

JOptionPaneFixture

public JOptionPaneFixture(Robot robot,
                          JOptionPane target)
Creates a new JOptionPaneFixture.

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

driver

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

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

title

public String title()
Returns the title of this fixture's JOptionPane.

Returns:
the title of this fixture's JOptionPane.
Since:
1.2

okButton

public JButtonFixture okButton()
Returns a fixture wrapping the "OK" button in this fixture's JOptionPane. This method is locale-independent and platform-independent.

Returns:
a fixture wrapping the "OK" button.
Throws:
ComponentLookupException - if the a "OK" button cannot be found.

cancelButton

public JButtonFixture cancelButton()
Returns a fixture wrapping the "Cancel" button in this fixture's JOptionPane. This method is locale-independent and platform-independent.

Returns:
a fixture wrapping the "Cancel" button.
Throws:
ComponentLookupException - if the a "Cancel" button cannot be found.

yesButton

public JButtonFixture yesButton()
Returns a fixture wrapping the "Yes" button in this fixture's JOptionPane. This method is locale-independent and platform-independent.

Returns:
a fixture wrapping the "Yes" button.
Throws:
ComponentLookupException - if the a "Yes" button cannot be found.

noButton

public JButtonFixture noButton()
Returns a fixture wrapping the "No" button in this fixture's JOptionPane. This method is locale-independent and platform-independent.

Returns:
a fixture wrapping the "No" button.
Throws:
ComponentLookupException - if the a "No" button cannot be found.

buttonWithText

public JButtonFixture buttonWithText(String text)
Finds and returns a fixture wrapping a button (this fixture's JOptionPane) matching the given text.

Parameters:
text - the text of the button to find. It can be a regular expression.
Returns:
a fixture wrapping a button matching the given text.
Throws:
ComponentLookupException - if the a button with the given text cannot be found.

buttonWithText

public JButtonFixture buttonWithText(Pattern pattern)
Finds and returns a fixture wrapping a button (this fixture's JOptionPane) matching the given text.

Parameters:
pattern - the regular expression pattern to match.
Returns:
a fixture wrapping a button matching the given regular expression pattern.
Throws:
NullPointerException - if the given regular expression pattern is null.
ComponentLookupException - if the a button with the given text cannot be found.
Since:
1.2

click

public JOptionPaneFixture click()
Simulates a user clicking this fixture's JOptionPane.

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

click

public JOptionPaneFixture click(MouseButton button)
Simulates a user clicking this fixture's JOptionPane.

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

click

public JOptionPaneFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JOptionPane.

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

rightClick

public JOptionPaneFixture rightClick()
Simulates a user right-clicking this fixture's JOptionPane.

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

doubleClick

public JOptionPaneFixture doubleClick()
Simulates a user double-clicking this fixture's JOptionPane.

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

focus

public JOptionPaneFixture focus()
Gives input focus to this fixture's JOptionPane.

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

requireErrorMessage

public JOptionPaneFixture requireErrorMessage()
Asserts that this fixture's JOptionPane is displaying an error message.

Returns:
this fixture.

requireInformationMessage

public JOptionPaneFixture requireInformationMessage()
Asserts that this fixture's JOptionPane is displaying an information message.

Returns:
this fixture.

requireWarningMessage

public JOptionPaneFixture requireWarningMessage()
Asserts that this fixture's JOptionPane is displaying a warning message.

Returns:
this fixture.

requireQuestionMessage

public JOptionPaneFixture requireQuestionMessage()
Asserts that this fixture's JOptionPane is displaying a question.

Returns:
this fixture.

requirePlainMessage

public JOptionPaneFixture requirePlainMessage()
Asserts that this fixture's JOptionPane is displaying a plain message.

Returns:
this fixture.

pressAndReleaseKey

public JOptionPaneFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's JOptionPane. 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.
See Also:
KeyPressInfo

pressAndReleaseKeys

public JOptionPaneFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys this fixture's JOptionPane. 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.
See Also:
KeyEvent

pressKey

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

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.
See Also:
KeyEvent

releaseKey

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

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.
See Also:
KeyEvent

requireTitle

public JOptionPaneFixture requireTitle(String title)
Asserts that the title of this fixture's JOptionPane matches the given value.

Parameters:
title - the title to match. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JOptionPaneFixture does not have the given title.

requireTitle

public JOptionPaneFixture requireTitle(Pattern pattern)
Asserts that the title of this fixture's JOptionPane matches the given regular expression pattern.

Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression is null.
AssertionError - if this fixture's JOptionPaneFixture does not have the given title.
Since:
1.2

requireMessage

public JOptionPaneFixture requireMessage(Object message)
Asserts that the message of this fixture's JOptionPane matches the given value.

Parameters:
message - the message to verify. If it is a String, it can be specified as a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the message in this fixture's JOptionPaneFixture is not equal to or does not match the given message.

requireMessage

public JOptionPaneFixture requireMessage(Pattern pattern)
Asserts that the message of this fixture's JOptionPane matches the given regular expression pattern. If the message in the JOptionPane is not a String, this method will use the toString representation of such message.

Parameters:
pattern - the regular expression to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the message in this fixture's JOptionPaneFixture does not match the given regular expression pattern.
Since:
1.2

requireOptions

public JOptionPaneFixture requireOptions(Object[] options)
Asserts that this fixture's JOptionPane has the given options.

Parameters:
options - the options to verify.
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JOptionPaneFixture does not have the given options.

requireFocused

public JOptionPaneFixture requireFocused()
Asserts that this fixture's JOptionPane has input focus.

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

requireEnabled

public JOptionPaneFixture requireEnabled()
Asserts that this fixture's JOptionPane is enabled.

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

requireEnabled

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

requireDisabled

public JOptionPaneFixture requireDisabled()
Asserts that this fixture's JOptionPane is disabled.

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

requireVisible

public JOptionPaneFixture requireVisible()
Asserts that this fixture's JOptionPane is visible.

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

requireNotVisible

public JOptionPaneFixture requireNotVisible()
Asserts that this fixture's JOptionPane is not visible.

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


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