Package org.hamcrest
Class Condition<T>
java.lang.Object
org.hamcrest.Condition<T>
- Type Parameters:
T
- the matched value type
A Condition implements part of a multi-step match. We sometimes need to write matchers
that have a sequence of steps, where each step depends on the result of the previous
step, and we can stop processing as soon as a step fails. These classes provide
infrastructure for writing such a sequence.
Based on Nat Pryce's maybe-java.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Represents a single step in a multi-step sequence -
Method Summary
Modifier and TypeMethodDescriptionabstract <U> Condition
<U> and
(Condition.Step<? super T, U> mapping) Applies the mapping to the current value in the sequencestatic <T> Condition
<T> matched
(T theValue, Description mismatch) Called by steps when a match occursfinal boolean
Applies the matcher as the final step in the sequenceabstract boolean
Applies the matcher as the final step in the sequencestatic <T> Condition
<T> Called by steps when a mismatch occurs.final <U> Condition
<U> then
(Condition.Step<? super T, U> mapping) An alias forand(Step)
, which applies the mapping to the current value in the sequence.
-
Method Details
-
matching
Applies the matcher as the final step in the sequence- Parameters:
match
- the value matchermessage
- a description of the value- Returns:
- true if the matcher matches the value, otherwise false
-
matching
Applies the matcher as the final step in the sequence- Parameters:
match
- the value matcher- Returns:
- true if the matcher matches the value, otherwise false
-
and
Applies the mapping to the current value in the sequence- Type Parameters:
U
- the type of the next value- Parameters:
mapping
- the current step in the sequence- Returns:
- the condition for the next step in the sequence
-
then
An alias forand(Step)
, which applies the mapping to the current value in the sequence.- Type Parameters:
U
- the type of the next value- Parameters:
mapping
- the current step in the sequence- Returns:
- the condition for the next step in the sequence
-
notMatched
Called by steps when a mismatch occurs.- Type Parameters:
T
- the type of the unmatched value- Returns:
- a condition in the not matched state
-
matched
Called by steps when a match occurs- Type Parameters:
T
- the type of the matched value- Parameters:
theValue
- the value that was matchedmismatch
- a description for potential future mismatches- Returns:
- the condition in a matched state
-