Class JComponentDriver

Direct Known Subclasses:
AbstractButtonDriver, JComboBoxDriver, JFileChooserDriver, JInternalFrameDriver, JLabelDriver, JListDriver, JMenuItemDriver, JOptionPaneDriver, JPopupMenuDriver, JProgressBarDriver, JScrollBarDriver, JScrollPaneDriver, JSliderDriver, JSpinnerDriver, JSplitPaneDriver, JTabbedPaneDriver, JTableDriver, JTableHeaderDriver, JTextComponentDriver, JToolBarDriver, JTreeDriver

public class JComponentDriver extends ContainerDriver
Understands functional testing of JComponents:
  • 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

    • JComponentDriver

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

    • scrollToVisible

      @RunsInCurrentThread protected final void scrollToVisible(JComponent c, Rectangle r)
      Invoke JComponent.scrollRectToVisible(Rectangle) on the given JComponent.

      Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      c - the given JComponent.
      r - the visible Rectangle.
    • isVisible

      @RunsInCurrentThread protected static boolean isVisible(JComponent c, Rectangle r)
      Indicates whether the given JComponent's visible Rectangle contains the given one.

      Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      c - the given JComponent.
      r - the Rectangle to verify.
      Returns:
      true if the given Rectangle is contained in the given JComponent's visible Rectangle.
    • isVisible

      @RunsInCurrentThread protected final boolean isVisible(JComponent c, Point p)
      Indicates whether the given JComponent's visible Rectangle contains the given Point.

      Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      c - the given JComponent.
      p - the Point to verify.
      Returns:
      true if the given Point is contained in the given JComponent's visible Rectangle.
    • invokeAction

      @RunsInEDT protected final void invokeAction(JComponent c, String name)
      Invoke an Action from the JComponent's ActionMap.
      Parameters:
      c - the given JComponent.
      name - the name of the Action to invoke.
      Throws:
      ActionFailedException - if an Action cannot be found under the given name.
      ActionFailedException - if a KeyStroke cannot be found for the Action under the given name.
      ActionFailedException - if it is not possible to type any of the found KeyStrokes.
    • keyStrokesForAction

      @RunsInCurrentThread private static KeyStroke[] keyStrokesForAction(JComponent component, String actionName)
    • type

      private void type(KeyStroke keyStroke)
    • requireToolTip

      @RunsInEDT public void requireToolTip(JComponent c, String expected)
      Asserts that the toolTip in the given JComponent matches the given value.
      Parameters:
      c - the given JComponent.
      expected - the expected toolTip. It can be a regular expression.
      Throws:
      AssertionError - if the toolTip of the given JComponent does not match the given value.
      Since:
      1.2
    • requireToolTip

      @RunsInEDT public void requireToolTip(JComponent c, Pattern pattern)
      Asserts that the toolTip in the given JComponent matches the given regular expression pattern.
      Parameters:
      c - the given JComponent.
      pattern - the regular expression pattern to match.
      Throws:
      NullPointerException - if the given regular expression pattern is null.
      AssertionError - if the toolTip of the given JComponent does not match the given value.
      Since:
      1.2
    • clientProperty

      @RunsInEDT public Object clientProperty(JComponent c, Object key)
      Returns the client property stored in the given JComponent, under the given key.
      Parameters:
      c - the given JComponent.
      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
    • clientPropertyIn

      private static Object clientPropertyIn(JComponent c, Object key)