Top Constructors Methods
org.hamcrest

public Class Matchers

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <T> Matcher<T>
allOf(Iterable<Matcher<? super T>> matchers)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T>... matchers)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T> first, Matcher<? super T> second)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth)

Creates a matcher that matches if the examined object matches ALL of the specified matchers.

public static <T> Matcher<T>
any(Class<T> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#isInstance(Object) method on that type, passing the the examined object.

public static <T> AnyOf<T>
anyOf(Iterable<Matcher<? super T>> matchers)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static <T> AnyOf<T>
anyOf(Matcher<? super T>... matchers)

Creates a matcher that matches if the examined object matches ANY of the specified matchers.

public static Matcher<Object>
anything()

Creates a matcher that always matches, regardless of the examined object.

public static Matcher<Object>
anything(String
a meaningful String used when describing itself
description
)

Creates a matcher that always matches, regardless of the examined object, but describes itself with the specified String.

public static <T> IsArray<T>
array(Matcher<? super T>...
the matchers that the elements of examined arrays should satisfy
elementMatchers
)

Creates a matcher that matches arrays whose elements are satisfied by the specified matchers.

public static <E> Matcher<E[]>
arrayContaining(List<Matcher<? super E>>
a list of matchers, each of which must be satisfied by the corresponding item in an examined array
itemMatchers
)

Creates a matcher for arrays that matches when each item in the examined array satisfies the corresponding matcher in the specified list of matchers.

public static <E> Matcher<E[]>
arrayContaining(E...
the items that must equal the items within an examined array
items
)

Creates a matcher for arrays that matcheswhen each item in the examined array is logically equal to the corresponding item in the specified items.

public static <E> Matcher<E[]>
arrayContaining(Matcher<? super E>...
the matchers that must be satisfied by the items in the examined array
itemMatchers
)

Creates a matcher for arrays that matches when each item in the examined array satisfies the corresponding matcher in the specified matchers.

public static <E> Matcher<E[]>
arrayContainingInAnyOrder(E...
the items that must equal the entries of an examined array, in any order
items
)

Creates an order agnostic matcher for arrays that matches when each item in the examined array is logically equal to one item anywhere in the specified items.

public static <E> Matcher<E[]>
arrayContainingInAnyOrder(Matcher<? super E>...
a list of matchers, each of which must be satisfied by an entry in an examined array
itemMatchers
)

Creates an order agnostic matcher for arrays that matches when each item in the examined array satisfies one matcher anywhere in the specified matchers.

public static <E> Matcher<E[]>
arrayContainingInAnyOrder(Collection<Matcher<? super E>>
a list of matchers, each of which must be satisfied by an item provided by an examined array
itemMatchers
)

Creates an order agnostic matcher for arrays that matches when each item in the examined array satisfies one matcher anywhere in the specified collection of matchers.

public static <E> Matcher<E[]>
arrayWithSize(Matcher<? super Integer>
a matcher for the length of an examined array
sizeMatcher
)

Creates a matcher for arrays that matches when the length of the array satisfies the specified matcher.

public static <E> Matcher<E[]>
arrayWithSize(int
the length that an examined array must have for a positive match
size
)

Creates a matcher for arrays that matches when the length of the array equals the specified size.

public static <LHS> CombinableMatcher.CombinableBothMatcher<LHS>
both(Matcher<? super LHS> matcher)

Creates a matcher that matches when both of the specified matchers match the examined object.

public static Matcher<Double>
closeTo(double
the expected value of matching doubles
operand
,
double
the delta (+/-) within which matches will be allowed
error
)

Creates a matcher of Doubles that matches when an examined double is equal to the specified operand, within a range of +/- error.

public static Matcher<BigDecimal>
closeTo(BigDecimal
the expected value of matching BigDecimals
operand
,
BigDecimal
the delta (+/-) within which matches will be allowed
error
)

Creates a matcher of java.math.BigDecimals that matches when an examined BigDecimal is equal to the specified operand, within a range of +/- error.

public static <T extends Comparable<T>> Matcher<T>
comparesEqualTo(T
the value which, when passed to the compareTo method of the examined object, should return zero
value
)

Creates a matcher of Comparable object that matches when the examined object is equal to the specified value, as reported by the compareTo method of the examined object.

public static <E> Matcher<Iterable<? extends E>>
contains(Matcher<? super E>...
the matchers that must be satisfied by the items provided by an examined Iterable
itemMatchers
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each satisfying the corresponding matcher in the specified matchers.

public static <E> Matcher<Iterable<? extends E>>
contains(E...
the items that must equal the items provided by an examined Iterable
items
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each logically equal to the corresponding item in the specified items.

public static <E> Matcher<Iterable<? extends E>>
contains(Matcher<? super E>
the matcher that must be satisfied by the single item provided by an examined Iterable
itemMatcher
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a single item that satisfies the specified matcher.

public static <E> Matcher<Iterable<? extends E>>
contains(List<Matcher<? super E>>
a list of matchers, each of which must be satisfied by the corresponding item provided by an examined Iterable
itemMatchers
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each satisfying the corresponding matcher in the specified list of matchers.

public static <T> Matcher<Iterable<? extends T>>
containsInAnyOrder(T...
the items that must equal the items provided by an examined Iterable in any order
items
)

Creates an order agnostic matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each logically equal to one item anywhere in the specified items.

public static <T> Matcher<Iterable<? extends T>>
containsInAnyOrder(Collection<Matcher<? super T>>
a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
itemMatchers
)

Creates an order agnostic matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each satisfying one matcher anywhere in the specified collection of matchers.

public static <T> Matcher<Iterable<? extends T>>
containsInAnyOrder(Matcher<? super T>...
a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
itemMatchers
)

Creates an order agnostic matcher for Iterables that matches when a single pass over the examined Iterable yields a series of items, each satisfying one matcher anywhere in the specified matchers.

public static <E> Matcher<Iterable<? extends E>>
containsInAnyOrder(Matcher<? super E>
the matcher that must be satisfied by the single item provided by an examined Iterable
itemMatcher
)

Deprecated use contains(Matcher itemMatcher) instead
Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a single item that satisfies the specified matcher.
public static Matcher<String>
containsString(String
the substring that the returned matcher will expect to find within any examined string
substring
)

Creates a matcher that matches if the examined String contains the specified String anywhere.

public static <T> Matcher<T>
describedAs(String
the new description for the wrapped matcher
description
,
Matcher<T>
the matcher to wrap
matcher
,
Object...
optional values to insert into the tokenised description
values
)

Wraps an existing matcher, overriding its description with that specified.

public static <LHS> CombinableMatcher.CombinableEitherMatcher<LHS>
either(Matcher<? super LHS> matcher)

Creates a matcher that matches when either of the specified matchers match the examined object.

public static <E> Matcher<Collection<? extends E>>
empty()

Creates a matcher for java.util.Collections matching examined collections whose isEmpty method returns true.

public static <E> Matcher<E[]>
emptyArray()

Creates a matcher for arrays that matches when the length of the array is zero.

public static <E> Matcher<Collection<E>>
emptyCollectionOf(Class<E>
the type of the collection's content
type
)

Creates a matcher for java.util.Collections matching examined collections whose isEmpty method returns true.

public static <E> Matcher<Iterable<? extends E>>
emptyIterable()

Creates a matcher for Iterables matching examined iterables that yield no items.

public static <E> Matcher<Iterable<E>>
emptyIterableOf(Class<E>
the type of the iterable's content
type
)

Creates a matcher for Iterables matching examined iterables that yield no items.

public static Matcher<String>
endsWith(String
the substring that the returned matcher will expect at the end of any examined string
suffix
)

Creates a matcher that matches if the examined String ends with the specified String.

public static <T> Matcher<T>
equalTo(T operand)

Creates a matcher that matches when the examined object is logically equal to the specified operand, as determined by calling the java.lang.Object#equals method on the examined object.

public static Matcher<String>
equalToIgnoringCase(String
the expected value of matched strings
expectedString
)

Creates a matcher of String that matches when the examined string is equal to the specified expectedString, ignoring case.

public static Matcher<String>
equalToIgnoringWhiteSpace(String
the expected value of matched strings
expectedString
)

Creates a matcher of String that matches when the examined string is equal to the specified expectedString, when whitespace differences are (mostly) ignored.

public static Matcher<EventObject>
eventFrom(Class<? extends EventObject>
the class of the event to match on
eventClass
,
Object
the source of the event
source
)

Creates a matcher of java.util.EventObject that matches any object derived from eventClass announced by source.

public static Matcher<EventObject>
eventFrom(Object
the source of the event
source
)

Creates a matcher of java.util.EventObject that matches any EventObject announced by source.

public static <U> Matcher<Iterable<U>>
everyItem(Matcher<U>
the matcher to apply to every item provided by the examined Iterable
itemMatcher
)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields items that are all matched by the specified itemMatcher.

public static <T extends Comparable<T>> Matcher<T>
greaterThan(T
the value which, when passed to the compareTo method of the examined object, should return greater than zero
value
)

Creates a matcher of Comparable object that matches when the examined object is greater than the specified value, as reported by the compareTo method of the examined object.

public static <T extends Comparable<T>> Matcher<T>
greaterThanOrEqualTo(T
the value which, when passed to the compareTo method of the examined object, should return greater than or equal to zero
value
)

Creates a matcher of Comparable object that matches when the examined object is greater than or equal to the specified value, as reported by the compareTo method of the examined object.

public static <K, V> Matcher<Map<? extends K, ? extends V>>
hasEntry(K
the key that, in combination with the value, must be describe at least one entry
key
,
V
the value that, in combination with the key, must be describe at least one entry
value
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key equals the specified key and whose value equals the specified value.

public static <K, V> Matcher<Map<? extends K, ? extends V>>
hasEntry(Matcher<? super K>
the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
keyMatcher
,
Matcher<? super V>
the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
valueMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key satisfies the specified keyMatcher and whose value satisfies the specified valueMatcher.

public static <T> Matcher<Iterable<? super T>>
hasItem(T
the item to compare against the items provided by the examined Iterable
item
)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is equal to the specified item.

public static <T> Matcher<Iterable<? super T>>
hasItem(Matcher<? super T>
the matcher to apply to items provided by the examined Iterable
itemMatcher
)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is matched by the specified itemMatcher.

public static <T> Matcher<T[]>
hasItemInArray(T
the element that should be present in examined arrays
element
)

A shortcut to the frequently used hasItemInArray(equalTo(x)).

public static <T> Matcher<T[]>
hasItemInArray(Matcher<? super T>
the matcher to apply to elements in examined arrays
elementMatcher
)

Creates a matcher for arrays that matches when the examined array contains at least one item that is matched by the specified elementMatcher.

public static <T> Matcher<Iterable<T>>
hasItems(T...
the items to compare against the items provided by the examined Iterable
items
)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is equal to the corresponding item from the specified items.

public static <T> Matcher<Iterable<T>>
hasItems(Matcher<? super T>...
the matchers to apply to items provided by the examined Iterable
itemMatchers
)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is matched by the corresponding matcher from the specified itemMatchers.

public static <K> Matcher<Map<? extends K, ?>>
hasKey(Matcher<? super K>
the matcher that must be satisfied by at least one key
keyMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that satisfies the specified matcher.

public static <K> Matcher<Map<? extends K, ?>>
hasKey(K
the key that satisfying maps must contain
key
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that is equal to the specified key.

public static <T> Matcher<T>
hasProperty(String
the name of the JavaBean property that examined beans should possess
propertyName
)

Creates a matcher that matches when the examined object has a JavaBean property with the specified name.

public static <T> Matcher<T>
hasProperty(String
the name of the JavaBean property that examined beans should possess
propertyName
,
Matcher<?>
a matcher for the value of the specified property of the examined bean
valueMatcher
)

Creates a matcher that matches when the examined object has a JavaBean property with the specified name whose value satisfies the specified matcher.

public static <E> Matcher<Collection<? extends E>>
hasSize(Matcher<? super Integer>
a matcher for the size of an examined java.util.Collection
sizeMatcher
)

Creates a matcher for java.util.Collections that matches when the size() method returns a value that satisfies the specified matcher.

public static <E> Matcher<Collection<? extends E>>
hasSize(int
the expected size of an examined java.util.Collection
size
)

Creates a matcher for java.util.Collections that matches when the size() method returns a value equal to the specified size.

public static <T> Matcher<T>
hasToString(Matcher<? super String>
the matcher used to verify the toString result
toStringMatcher
)

Creates a matcher that matches any examined object whose toString method returns a value that satisfies the specified matcher.

public static <T> Matcher<T>
hasToString(String
the expected toString result
expectedToString
)

Creates a matcher that matches any examined object whose toString method returns a value equalTo the specified string.

public static <V> Matcher<Map<?, ? extends V>>
hasValue(V
the value that satisfying maps must contain
value
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that is equal to the specified value.

public static <V> Matcher<Map<?, ? extends V>>
hasValue(Matcher<? super V>
the matcher that must be satisfied by at least one value
valueMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that satisfies the specified valueMatcher.

public static Matcher<Node>
hasXPath(String
the target xpath
xPath
,
NamespaceContext
the namespace for matching nodes
namespaceContext
)

Creates a matcher of org.w3c.dom.Nodes that matches when the examined node contains a node at the specified xPath within the specified namespace context, with any content.

public static Matcher<Node>
hasXPath(String
the target xpath
xPath
)

Creates a matcher of org.w3c.dom.Nodes that matches when the examined node contains a node at the specified xPath, with any content.

public static Matcher<Node>
hasXPath(String
the target xpath
xPath
,
NamespaceContext
the namespace for matching nodes
namespaceContext
,
Matcher<String>
matcher for the value at the specified xpath
valueMatcher
)

Creates a matcher of org.w3c.dom.Nodes that matches when the examined node has a value at the specified xPath, within the specified namespaceContext, that satisfies the specified valueMatcher.

public static Matcher<Node>
hasXPath(String
the target xpath
xPath
,
Matcher<String>
matcher for the value at the specified xpath
valueMatcher
)

Creates a matcher of org.w3c.dom.Nodes that matches when the examined node has a value at the specified xPath that satisfies the specified valueMatcher.

public static <T> Matcher<T>
instanceOf(Class<?> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#isInstance(Object) method on that type, passing the the examined object.

public static <T> Matcher<T>
is(T value)

A shortcut to the frequently used is(equalTo(x)).

public static <T> Matcher<T>
is(Matcher<T> matcher)

Decorates another Matcher, retaining its behaviour, but allowing tests to be slightly more expressive.

public static <T> Matcher<T>
is(Class<T> type)

Deprecated use isA(Class type) instead.
A shortcut to the frequently used is(instanceOf(SomeClass.class)).
public static <T> Matcher<T>
isA(Class<T> type)

A shortcut to the frequently used is(instanceOf(SomeClass.class)).

public static Matcher<String>
isEmptyOrNullString()

Creates a matcher of String that matches when the examined string is null, or has zero length.

public static Matcher<String>
isEmptyString()

Creates a matcher of String that matches when the examined string has zero length.

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[] param1)

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 static <E> Matcher<Iterable<E>>
iterableWithSize(Matcher<? super Integer>
a matcher for the number of items that should be yielded by an examined Iterable
sizeMatcher
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields an item count that satisfies the specified matcher.

public static <E> Matcher<Iterable<E>>
iterableWithSize(int
the number of items that should be yielded by an examined Iterable
size
)

Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields an item count that is equal to the specified size argument.

public static <T extends Comparable<T>> Matcher<T>
lessThan(T
the value which, when passed to the compareTo method of the examined object, should return less than zero
value
)

Creates a matcher of Comparable object that matches when the examined object is less than the specified value, as reported by the compareTo method of the examined object.

public static <T extends Comparable<T>> Matcher<T>
lessThanOrEqualTo(T
the value which, when passed to the compareTo method of the examined object, should return less than or equal to zero
value
)

Creates a matcher of Comparable object that matches when the examined object is less than or equal to the specified value, as reported by the compareTo method of the examined object.

public static <T> Matcher<T>
not(Matcher<T>
the matcher whose sense should be inverted
matcher
)

Creates a matcher that wraps an existing matcher, but inverts the logic by which it will match.

public static <T> Matcher<T>
not(T
the value that any examined object should not equal
value
)

A shortcut to the frequently used not(equalTo(x)).

public static Matcher<Object>
notNullValue()

A shortcut to the frequently used not(nullValue()).

public static <T> Matcher<T>
notNullValue(Class<T>
dummy parameter used to infer the generic type of the returned matcher
type
)

A shortcut to the frequently used not(nullValue(X.class)).

public static Matcher<Object>
nullValue()

Creates a matcher that matches if examined object is null.

public static <T> Matcher<T>
nullValue(Class<T>
dummy parameter used to infer the generic type of the returned matcher
type
)

Creates a matcher that matches if examined object is null.

public static <T> Matcher<T>
sameInstance(T
the target instance against which others should be assessed
target
)

Creates a matcher that matches only when the examined object is the same instance as the specified target object.

public static <T> Matcher<T>
samePropertyValuesAs(T
the bean against which examined beans are compared
expectedBean
)

Creates a matcher that matches when the examined object has values for all of its JavaBean properties that are equal to the corresponding values of the specified bean.

public static Matcher<String>
startsWith(String
the substring that the returned matcher will expect at the start of any examined string
prefix
)

Creates a matcher that matches if the examined String starts with the specified String.

public static Matcher<String>
stringContainsInOrder(Iterable<String>
the substrings that must be contained within matching strings
substrings
)

Creates a matcher of String that matches when the examined string contains all of the specified substrings, regardless of the order of their appearance.

public static <T> Matcher<T>
theInstance(T
the target instance against which others should be assessed
target
)

Creates a matcher that matches only when the examined object is the same instance as the specified target object.

public static <T> Matcher<Class<?>>
typeCompatibleWith(Class<T>
the base class to examine classes against
baseType
)

Creates a matcher of Class that matches when the specified baseType is assignable from the examined class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait