Class HamcrestCondition<T>
java.lang.Object
org.assertj.core.api.Condition<T>
org.assertj.core.api.HamcrestCondition<T>
- All Implemented Interfaces:
Descriptable<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);
By static-importing the matching(Matcher) method you can do:
assertThat("abc").is(matching(containsString("a")));- Since:
- 2.9.0 / 3.9.0
-
Nested Class Summary
Nested classes/interfaces inherited from class Condition
Condition.Status -
Constructor Summary
ConstructorsConstructorDescriptionHamcrestCondition(org.hamcrest.Matcher<? extends T> matcher) Constructs aConditionusing the matcher given as a parameter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanVerifies that the given value satisfies this condition.static <T> HamcrestCondition<T> matching(org.hamcrest.Matcher<? extends T> matcher) Constructs aConditionusing the matcher given as a parameter.Methods inherited from class Condition
conditionDescriptionWithStatus, describedAs, description, status, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
HamcrestCondition
-
-
Method Details
-
matching
Constructs aConditionusing the matcher given as a parameter.Example:
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.HamcrestCondition.matching; import static org.hamcrest.core.StringContains.containsString; assertThat("abc").is(matching(containsString("a")));- Type Parameters:
T- the type the condition is about- Parameters:
matcher- the Hamcrest matcher to use as a condition- Returns:
- the built
HamcrestCondition
-
matches
-