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")));
| Modifier and Type | Field and Description |
|---|---|
| private Matcher |
| Access | Constructor and Description |
|---|---|
| public | HamcrestCondition(Matcher<? extends T>
the Hamcrest matcher to use as a condition matcher)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| private String | |
| public boolean | matches(T
the value to verify. value)Overrides org. |
| public static < the type the condition is about T> HamcrestCondition | Returns: the builtHamcrestConditionthe Hamcrest matcher to use as a condition matcher)Constructs a |
| matcher | back to summary |
|---|---|
| private Matcher<? extends T> matcher | |
| HamcrestCondition | back to summary |
|---|---|
| public HamcrestCondition(Matcher<? extends T> matcher) Constructs a
| |
| describeMatcher | back to summary |
|---|---|
| private String describeMatcher() | |
| matches | back to summary |
|---|---|
| public boolean matches(T value) Overrides org. Doc from org. Verifies that the given value satisfies this condition.
| |
| matching | back to summary |
|---|---|
| public static <T> HamcrestCondition Constructs a Example:
| |