Class DialogMatcher

All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher

public final class DialogMatcher extends NamedComponentMatcherTemplate<Dialog>
Understands matching a Dialog by name, title and visibility on the screen.
  • Field Details

    • title

      private Object title
  • Constructor Details

    • DialogMatcher

      private DialogMatcher(Object name, Object title)
  • Method Details

    • withName

      public static DialogMatcher withName(String name)
      Creates a new DialogMatcher that matches a Dialog that:
      1. has a matching name
      2. (optionally) has matching title
      3. (optionally) is showing on the screen
      4. The following code listing shows how to match a Dialog by name and title:

         DialogMatcher m = withName("saveFile").andTitle("Save File");
         

        The following code listing shows how to match a Dialog, that should be showing on the screen, by name and title:

         DialogMatcher m = withName("saveFile").andTitle("Save File").andShowing();
         

      Parameters:
      name - the id to match.
      Returns:
      the created matcher.
    • withTitle

      public static DialogMatcher withTitle(String title)
      Creates a new DialogMatcher that matches a Dialog by its title.

      The following code listing shows how to match a Dialog title:

       DialogMatcher m = withTitle("Save File");
       

      The following code listing shows how to match a Dialog, that should be showing on the screen, by title:

       DialogMatcher m = withTitle("Save File").andShowing();
       

      Parameters:
      title - the title to match. It can be a regular expression.
      Returns:
      the created matcher.
    • withTitle

      public static DialogMatcher withTitle(Pattern titlePattern)
      Creates a new DialogMatcher that matches a Dialog by its title.

      The following code listing shows how to match a Dialog title, using a regular expression pattern:

       DialogMatcher m = withTitle(Pattern.compile("Sav.*"));
       

      The following code listing shows how to match a Dialog, that should be showing on the screen, by title, using a regular expression pattern:

       DialogMatcher m = withTitle(Pattern.compile("Sav.*")).andShowing();
       

      Parameters:
      titlePattern - the regular expression pattern to match.
      Returns:
      the created matcher.
      Since:
      1.2
    • any

      public static DialogMatcher any()
      Creates a new DialogMatcher that matches any Dialog.
      Returns:
      the created matcher.
    • andTitle

      public DialogMatcher andTitle(String newTitle)
      Specifies the title to match. If this matcher was created using withTitle(String) or withTitle(Pattern), this method will simply update the title to match.
      Parameters:
      newTitle - the new title to match. It can be a regular expression.
      Returns:
      this matcher.
    • andTitle

      public DialogMatcher andTitle(Pattern titlePattern)
      Specifies the title to match. If this matcher was created using withTitle(String), or withTitle(Pattern) this method will simply update the title to match.
      Parameters:
      titlePattern - the regular expression pattern to match.
      Returns:
      this matcher.
      Since:
      1.2
    • andShowing

      public DialogMatcher andShowing()
      Indicates that the Dialog to match should be showing on the screen.
      Returns:
      this matcher.
    • isMatching

      @RunsInCurrentThread protected boolean isMatching(Dialog dialog)
      Indicates whether:
      • the name of the given Dialog is equal to the name in this matcher, and
      • the title of the given Dialog matches the text (or pattern) in this matcher

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

      Specified by:
      isMatching in class GenericTypeMatcher<Dialog>
      Parameters:
      dialog - the Dialog to match.
      Returns:
      true if the Dialog matches the search criteria in this matcher.
    • toString

      public String toString()
      Overrides:
      toString in class Object