Class JOptionPaneDriver


public class JOptionPaneDriver extends JComponentDriver
Understands functional testing of JOptionPanes:
  • user input simulation
  • state verification
  • property value query
This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.
  • Field Details

  • Constructor Details

    • JOptionPaneDriver

      public JOptionPaneDriver(Robot robot)
      Creates a new JOptionPaneDriver.
      Parameters:
      robot - the robot to use to simulate user input.
  • Method Details

    • requireTitle

      @RunsInEDT public void requireTitle(JOptionPane optionPane, String title)
      Asserts that the title in the given JOptionPane matches the given value.
      Parameters:
      optionPane - the target JOptionPane.
      title - the title to match. It can be a regular expression.
      Throws:
      AssertionError - if the JOptionPane does not have the given title.
    • requireTitle

      @RunsInEDT public void requireTitle(JOptionPane optionPane, Pattern pattern)
      Asserts that the title in the given JOptionPane matches the given regular expression pattern.
      Parameters:
      optionPane - the target JOptionPane.
      pattern - the regular expression pattern to match.
      Throws:
      NullPointerException - if the given regular expression pattern is null.
      AssertionError - if the JOptionPane does not have the given title.
      Since:
      1.2
    • title

      @RunsInEDT public String title(JOptionPane optionPane)
      Returns the title of the given JOptionPane.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the title of the given JOptionPane.
      Since:
      1.2
    • requireMessage

      @RunsInEDT public void requireMessage(JOptionPane optionPane, Object message)
      Asserts that the title of the JOptionPane matches the given value. If the given value is a regular expression and the message in the JOptionPane is not a String, this method will use the toString representation of such message. message in the JOptionPane is not a String, this method will use the toString representation of such message.
      Parameters:
      optionPane - the target JOptionPane.
      message - the message to verify. If it is a String, it can be specified as a regular expression.
      Throws:
      AssertionError - if the message in the JOptionPane is not equal to or does not match the given message.
    • requireMessage

      @RunsInEDT private void requireMessage(JOptionPane optionPane, String expected, String actual)
    • requireMessage

      @RunsInEDT public void requireMessage(JOptionPane optionPane, Pattern pattern)
      Asserts that the title of the 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:
      optionPane - the target JOptionPane.
      pattern - the regular expression to match.
      Throws:
      NullPointerException - if the given regular expression pattern is null.
      AssertionError - if the message in the JOptionPaneFixture does not match the given regular expression pattern.
      Since:
      1.2
    • toStringOf

      private String toStringOf(Object o)
    • messageProperty

      private org.fest.assertions.Description messageProperty(JOptionPane optionPane)
    • requireOptions

      @RunsInEDT public void requireOptions(JOptionPane optionPane, Object[] options)
      Asserts that the JOptionPane has the given options.
      Parameters:
      optionPane - the target JOptionPane.
      options - the options to verify.
      Throws:
      AssertionError - if the JOptionPane does not have the given options.
    • okButton

      @RunsInEDT public JButton okButton(JOptionPane optionPane)
      Finds the "OK" button in the JOptionPane. This method is independent of locale and platform.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the "OK" button.
      Throws:
      ComponentLookupException - if the a "OK" button cannot be found.
    • cancelButton

      @RunsInEDT public JButton cancelButton(JOptionPane optionPane)
      Finds the "Cancel" button in the JOptionPane. This method is independent of locale and platform.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the "Cancel" button.
      Throws:
      ComponentLookupException - if the a "Cancel" button cannot be found.
    • yesButton

      @RunsInEDT public JButton yesButton(JOptionPane optionPane)
      Finds the "Yes" button in the JOptionPane. This method is independent of locale and platform.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the "Yes" button.
      Throws:
      ComponentLookupException - if the a "Yes" button cannot be found.
    • noButton

      @RunsInEDT public JButton noButton(JOptionPane optionPane)
      Finds the "No" button in the JOptionPane. This method is independent of locale and platform.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the "No" button.
      Throws:
      ComponentLookupException - if the a "No" button cannot be found.
    • buttonWithTextFromUIManager

      @RunsInEDT private JButton buttonWithTextFromUIManager(JOptionPane optionPane, String key)
    • buttonWithText

      @RunsInEDT public JButton buttonWithText(JOptionPane optionPane, String text)
      Finds a button in the JOptionPane containing the given text.
      Parameters:
      optionPane - the target JOptionPane.
      text - the text of the button to find and return. It can be a regular expression.
      Returns:
      a button containing the given text.
      Throws:
      ComponentLookupException - if the a button with the given text cannot be found.
    • buttonWithText

      @RunsInEDT public JButton buttonWithText(JOptionPane optionPane, Pattern pattern)
      Finds a button in the JOptionPane whose text matches the given regular expression pattern.
      Parameters:
      optionPane - the target JOptionPane.
      pattern - the regular expression pattern to match.
      Returns:
      a button containing the given text.
      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
    • button

      @RunsInEDT @Deprecated public JButton button(JOptionPane optionPane)
      Deprecated.
      in 1.2
      Finds a JButton in the JOptionPane (assuming it has only one button.)
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the only JButton contained in the JOptionPane.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
    • textBox

      @RunsInEDT @Deprecated public JTextComponent textBox(JOptionPane optionPane)
      Deprecated.
      in 1.2
      Returns the JTextComponent in the given message only if the message is of type input.
      Parameters:
      optionPane - the target JOptionPane.
      Returns:
      the text component in the given message.
      Throws:
      ComponentLookupException - if the message type is not input and therefore it does not contain a text component.
    • requireErrorMessage

      @RunsInEDT public void requireErrorMessage(JOptionPane optionPane)
      Asserts that the JOptionPane is displaying an error message.
      Parameters:
      optionPane - the target JOptionPane.
    • requireInformationMessage

      @RunsInEDT public void requireInformationMessage(JOptionPane optionPane)
      Asserts that the JOptionPane is displaying an information message.
      Parameters:
      optionPane - the target JOptionPane.
    • requireWarningMessage

      @RunsInEDT public void requireWarningMessage(JOptionPane optionPane)
      Asserts that the JOptionPane is displaying a warning message.
      Parameters:
      optionPane - the target JOptionPane.
    • requireQuestionMessage

      @RunsInEDT public void requireQuestionMessage(JOptionPane optionPane)
      Asserts that the JOptionPane is displaying a question.
      Parameters:
      optionPane - the target JOptionPane.
    • requirePlainMessage

      @RunsInEDT public void requirePlainMessage(JOptionPane optionPane)
      Asserts that the JOptionPane is displaying a plain message.
      Parameters:
      optionPane - the target JOptionPane.
    • assertEqualMessageType

      @RunsInEDT private void assertEqualMessageType(JOptionPane optionPane, int expected)
    • actualMessageTypeAsText

      @RunsInEDT private String actualMessageTypeAsText(JOptionPane optionPane)