Package org.hamcrest.core
Class AnyOf<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.core.AnyOf<T>
- Type Parameters:
T
- the matched value type
- All Implemented Interfaces:
Matcher<T>
,SelfDescribing
Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so
subsequent matchers are not called if an earlier matcher returns
true
.-
Constructor Summary
ConstructorDescriptionConstructor, best called fromanyOf(Iterable)
.Constructor, best called fromanyOf(Matcher[])
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AnyOf
<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.static <T> AnyOf
<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.void
describeTo
(Description description) Generates a description of the object.void
describeTo
(Description description, String operator) Describe this matcher to descriptionboolean
Evaluates the matcher for argument item.protected boolean
Evaluates the argument o against the delegate matchers.Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
-
Constructor Details
-
AnyOf
Constructor, best called fromanyOf(Matcher[])
.- Parameters:
matchers
- the matchers- See Also:
-
AnyOf
Constructor, best called fromanyOf(Iterable)
.- Parameters:
matchers
- the matchers- See Also:
-
-
Method Details
-
matches
Description copied from interface:Matcher
Evaluates the matcher for argument item. This method matches against Object, instead of the generic type T. This is because the caller of the Matcher does not know at runtime what the type is (because of type erasure with Java generics). It is down to the implementations to check the correct type. -
describeTo
Description copied from interface:SelfDescribing
Generates a description of the object. The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.- Specified by:
describeTo
in interfaceSelfDescribing
- Parameters:
description
- The description to be built or appended to.
-
anyOf
Creates a matcher that matches if the examined object matches ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- Type Parameters:
T
- the matcher type.- Parameters:
matchers
- any the matchers must pass.- Returns:
- The matcher.
-
anyOf
Creates a matcher that matches if the examined object matches ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- Type Parameters:
T
- the matcher type.- Parameters:
matchers
- any the matchers must pass.- Returns:
- The matcher.
-
matches
Evaluates the argument o against the delegate matchers. Evaluation will stop at the first matcher that evaluates to the value of theshortcut
argument.- Parameters:
o
- the value to checkshortcut
- the match result to be checked against all delegate matchers- Returns:
- the value of shortcut if all delegate matchers give the same value
-
describeTo
Describe this matcher to description- Parameters:
description
- the description targetoperator
- the separate to use when joining the matcher descriptions
-