Class HamcrestCondition<T>

  • All Implemented Interfaces:
    Descriptable<Condition<T>>

    public class HamcrestCondition<T>
    extends Condition<T>
    Allows to use a Hamcrest matcher as a condition. Example:
     Condition<String> aStringContainingA = new HamcrestCondition<>(containsString("a"));
     
     // assertions will pass
     assertThat("abc").is(aStringContainingA);
     assertThat("bc").isNot(aStringContainingA);
     
     // assertion will fail
     assertThat("bc").is(aStringContainingA);
    Since:
    2.9.0 / 3.9.0
    • Field Detail

      • matcher

        private org.hamcrest.Matcher<T> matcher
    • Constructor Detail

      • HamcrestCondition

        public HamcrestCondition​(org.hamcrest.Matcher<T> matcher)
        Constructs a Condition using the matcher given as a parameter.
        Parameters:
        matcher - the Hamcrest matcher to use as a condition
    • Method Detail

      • matches

        public boolean matches​(T value)
        Verifies that the given value satisfies this condition.
        Overrides:
        matches in class Condition<T>
        Parameters:
        value - the value to verify.
        Returns:
        true if the given value satisfies this condition; false otherwise.
      • describeMatcher

        private String describeMatcher()