Class FailSafeMatcher<T>

Type Parameters:
T - The type of the matched entity.
All Implemented Interfaces:
ElementMatcher<T>, ElementMatcher.Junction<T>

@Enhance public class FailSafeMatcher<T> extends ElementMatcher.Junction.AbstractBase<T>
A fail-safe matcher catches exceptions that are thrown by a delegate matcher and returns an alternative value.
  • Field Details

    • matcher

      private final ElementMatcher<? super T> matcher
      The delegate matcher that might throw an exception.
    • fallback

      private final boolean fallback
      The fallback value in case of an exception.
  • Constructor Details

    • FailSafeMatcher

      public FailSafeMatcher(ElementMatcher<? super T> matcher, boolean fallback)
      Creates a new fail-safe element matcher.
      Parameters:
      matcher - The delegate matcher that might throw an exception.
      fallback - The fallback value in case of an exception.
  • Method Details

    • matches

      public boolean matches(@MaybeNull T target)
      Matches a target against this element matcher.
      Parameters:
      target - The instance to be matched or null.
      Returns:
      true if the given element is matched by this matcher or false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object