Class AllOf<T>

Type Parameters:
T - the matched value type
All Implemented Interfaces:
Matcher<T>, SelfDescribing

public class AllOf<T> extends DiagnosingMatcher<T>
Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so subsequent matchers are not called if an earlier matcher returns false.
  • Constructor Details

  • Method Details

    • matches

      public boolean matches(Object o, Description mismatch)
      Description copied from class: DiagnosingMatcher
      Evaluates the matcher for argument item.
      Specified by:
      matches in class DiagnosingMatcher<T>
      Parameters:
      o - the value to check
      mismatch - the description for the matcher
      Returns:
      true if item matches, otherwise false.
    • describeTo

      public void describeTo(Description description)
      Description copied from interface: SelfDescribing
      Generates a description of the object. The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
      Parameters:
      description - The description to be built or appended to.
    • allOf

      public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers)
      Creates a matcher that matches if the examined object matches ALL of the specified matchers. For example:
      assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
      Type Parameters:
      T - the matcher type.
      Parameters:
      matchers - all the matchers must pass.
      Returns:
      The matcher.
    • allOf

      @SafeVarargs public static <T> Matcher<T> allOf(Matcher<? super T>... matchers)
      Creates a matcher that matches if the examined object matches ALL of the specified matchers. For example:
      assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
      Type Parameters:
      T - the matcher type.
      Parameters:
      matchers - all the matchers must pass.
      Returns:
      The matcher.