Top Fields Constructors Methods
org.hamcrest.collection

public Class IsIn<T>

extends BaseMatcher<T>
Class Inheritance
Imports
org.hamcrest.BaseMatcher, .Description, .Factory, .Matcher, java.util.Arrays, .Collection

Field Summary

Modifier and TypeField and Description
private final Collection<T>

Constructor Summary

AccessConstructor and Description
public
IsIn(Collection<T> collection)

public
IsIn(T[] elements)

Method Summary

Modifier and TypeMethod and Description
public void
describeTo(Description
The description to be built or appended to.
buffer
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <T> Matcher<T>
isIn(Collection<T>
the collection in which matching items must be found
collection
)

Creates a matcher that matches when the examined object is found within the specified collection.

public static <T> Matcher<T>
isIn(T[]
the array in which matching items must be found
elements
)

Creates a matcher that matches when the examined object is found within the specified array.

public static <T> Matcher<T>
isOneOf(T...
the elements amongst which matching items will be found
elements
)

Creates a matcher that matches when the examined object is equal to one of the specified elements.

public boolean
matches(Object
the object against which the matcher is evaluated.
o
)

Implements org.hamcrest.Matcher.matches.

Evaluates the matcher for argument item.
Inherited from org.hamcrest.BaseMatcher:
_dont_implement_Matcher___instead_extend_BaseMatcher_describeMismatchtoString

Field Detail

collectionback to summary
private final Collection<T> collection

Constructor Detail

IsInback to summary
public IsIn(Collection<T> collection)
IsInback to summary
public IsIn(T[] elements)

Method Detail

describeToback to summary
public void describeTo(Description buffer)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
buffer:Description

The description to be built or appended to.

Annotations
@Override
isInback to summary
public static <T> Matcher<T> isIn(Collection<T> collection)

Creates a matcher that matches when the examined object is found within the specified collection.

For example:

assertThat("foo", isIn(Arrays.asList("bar", "foo")))
Parameters
collection:Collection<T>

the collection in which matching items must be found

Annotations
@Factory
isInback to summary
public static <T> Matcher<T> isIn(T[] elements)

Creates a matcher that matches when the examined object is found within the specified array.

For example:

assertThat("foo", isIn(new String[]{"bar", "foo"}))
Parameters
elements:T[]

the array in which matching items must be found

Annotations
@Factory
isOneOfback to summary
public static <T> Matcher<T> isOneOf(T... elements)

Creates a matcher that matches when the examined object is equal to one of the specified elements.

For example:

assertThat("foo", isIn("bar", "foo"))
Parameters
elements:T[]

the elements amongst which matching items will be found

Annotations
@Factory
matchesback to summary
public boolean matches(Object o)

Implements org.hamcrest.Matcher.matches.

Doc from org.hamcrest.Matcher.matches.

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:Object

the object against which the matcher is evaluated.

Returns:boolean

true if item matches, otherwise false.

Annotations
@Override