Package org.hamcrest.collection
Class IsIn<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.collection.IsIn<T>
- Type Parameters:
T
- the type of the objects in the collection
- All Implemented Interfaces:
Matcher<T>
,SelfDescribing
Tests if a collection contains a matching object.
-
Constructor Summary
ConstructorDescriptionIsIn
(Collection<T> collection) Constructor, best called fromin(Collection)
.Constructor, best called fromin(Object[])
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
describeTo
(Description buffer) Generates a description of the object.static <T> Matcher
<T> in
(Collection<T> collection) Creates a matcher that matches when the examined object is found within the specified collection.static <T> Matcher
<T> in
(T[] elements) Creates a matcher that matches when the examined object is found within the specified array.static <T> Matcher
<T> isIn
(Collection<T> collection) Deprecated.use is(in(...)) insteadstatic <T> Matcher
<T> isIn
(T[] elements) Deprecated.use is(in(...)) insteadstatic <T> Matcher
<T> isOneOf
(T... elements) Deprecated.use is(oneOf(...)) insteadboolean
Evaluates the matcher for argument item.static <T> Matcher
<T> oneOf
(T... elements) Creates a matcher that matches when the examined object is equal to one of the specified elements.Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
-
Constructor Details
-
IsIn
Constructor, best called fromin(Collection)
.- Parameters:
collection
- the expected element matchers
-
IsIn
Constructor, best called fromin(Object[])
.- Parameters:
elements
- the expected elements
-
-
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.- Parameters:
o
- the object against which the matcher is evaluated.- Returns:
true
if item matches, otherwisefalse
.- See Also:
-
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.- Parameters:
buffer
- The description to be built or appended to.
-
isIn
Deprecated.use is(in(...)) insteadCreates a matcher that matches when the examined object is found within the specified collection. For example:assertThat("foo", isIn(Arrays.asList("bar", "foo")))
- Type Parameters:
T
- the matcher type.- Parameters:
collection
- the collection in which matching items must be found- Returns:
- The matcher.
-
in
Creates a matcher that matches when the examined object is found within the specified collection. For example:assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
- Type Parameters:
T
- the matcher type.- Parameters:
collection
- the collection in which matching items must be found- Returns:
- The matcher.
-
isIn
Deprecated.use is(in(...)) insteadCreates a matcher that matches when the examined object is found within the specified array. For example:assertThat("foo", isIn(new String[]{"bar", "foo"}))
- Type Parameters:
T
- the matcher type.- Parameters:
elements
- the array in which matching items must be found- Returns:
- The matcher.
-
in
Creates a matcher that matches when the examined object is found within the specified array. For example:assertThat("foo", is(in(new String[]{"bar", "foo"})))
- Type Parameters:
T
- the matcher type.- Parameters:
elements
- the array in which matching items must be found- Returns:
- The matcher.
-
isOneOf
Deprecated.use is(oneOf(...)) insteadCreates a matcher that matches when the examined object is equal to one of the specified elements. For example:assertThat("foo", isOneOf("bar", "foo"))
- Type Parameters:
T
- the matcher type.- Parameters:
elements
- the elements amongst which matching items will be found- Returns:
- The matcher.
-
oneOf
Creates a matcher that matches when the examined object is equal to one of the specified elements. For example:assertThat("foo", is(oneOf("bar", "foo")))
- Type Parameters:
T
- the matcher type.- Parameters:
elements
- the elements amongst which matching items will be found- Returns:
- The matcher.
-