Package org.assertj.core.api
Class HamcrestCondition<T>
- java.lang.Object
-
- org.assertj.core.api.Condition<T>
-
- org.assertj.core.api.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:
By static-importing theCondition<String> aStringContainingA = new HamcrestCondition<>(containsString("a")); // assertions will pass assertThat("abc").is(aStringContainingA); assertThat("bc").isNot(aStringContainingA); // assertion will fail assertThat("bc").is(aStringContainingA);
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 org.assertj.core.api.Condition
Condition.Status
-
-
Field Summary
Fields Modifier and Type Field Description private org.hamcrest.Matcher<? extends T>
matcher
-
Fields inherited from class org.assertj.core.api.Condition
description
-
-
Constructor Summary
Constructors Constructor Description HamcrestCondition(org.hamcrest.Matcher<? extends T> matcher)
Constructs aCondition
using the matcher given as a parameter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private String
describeMatcher()
boolean
matches(T value)
Verifies that the given value satisfies this condition.static <T> HamcrestCondition<T>
matching(org.hamcrest.Matcher<? extends T> matcher)
Constructs aCondition
using the matcher given as a parameter.-
Methods inherited from class org.assertj.core.api.Condition
conditionDescriptionWithStatus, describedAs, description, status, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs
-
-
-
-
Field Detail
-
matcher
private org.hamcrest.Matcher<? extends T> matcher
-
-
Method Detail
-
matching
public static <T> HamcrestCondition<T> matching(org.hamcrest.Matcher<? extends T> matcher)
Constructs aCondition
using 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
public boolean matches(T value)
Verifies that the given value satisfies this condition.
-
describeMatcher
private String describeMatcher()
-
-