public class Matchers extends Object
Constructor and Description |
---|
Matchers() |
Modifier and Type | Method and Description |
---|---|
static <T> Matcher<T> |
allOf(Iterable<Matcher<? super T>> matchers)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<? super T>... matchers)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<T> first,
Matcher<? super T> second)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third,
Matcher<? super T> fourth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third,
Matcher<? super T> fourth,
Matcher<? super T> fifth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
allOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third,
Matcher<? super T> fourth,
Matcher<? super T> fifth,
Matcher<? super T> sixth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
any(Class<T> type)
Is the value an instance of a particular type?
Use this version to make generics conform, for example in
the JMock clause
with(any(Thing.class)) |
static <T> AnyOf<T> |
anyOf(Iterable<Matcher<? super T>> matchers)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> AnyOf<T> |
anyOf(Matcher<? super T>... matchers)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> AnyOf<T> |
anyOf(Matcher<T> first,
Matcher<? super T> second)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> AnyOf<T> |
anyOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> AnyOf<T> |
anyOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third,
Matcher<? super T> fourth)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> AnyOf<T> |
anyOf(Matcher<T> first,
Matcher<? super T> second,
Matcher<? super T> third,
Matcher<? super T> fourth,
Matcher<? super T> fifth)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
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)
Evaluates to true if ANY of the passed in matchers evaluate to true.
|
static <T> Matcher<T> |
anything()
This matcher always evaluates to true.
|
static <T> Matcher<T> |
anything(String description)
This matcher always evaluates to true.
|
static <T> IsArray<T> |
array(Matcher<? super T>... elementMatchers)
Evaluates to true only if each matcher[i] is satisfied by array[i].
|
static <E> Matcher<E[]> |
arrayContaining(E... items) |
static <E> Matcher<E[]> |
arrayContaining(List<Matcher<? super E>> matchers) |
static <E> Matcher<E[]> |
arrayContaining(Matcher<? super E>... matchers) |
static <E> Matcher<E[]> |
arrayContainingInAnyOrder(Collection<Matcher<? super E>> matchers) |
static <E> Matcher<E[]> |
arrayContainingInAnyOrder(E... items) |
static <E> Matcher<E[]> |
arrayContainingInAnyOrder(Matcher<? super E>... matchers) |
static <E> Matcher<E[]> |
arrayWithSize(int size)
This is a shortcut to the frequently used arrayWithSize(equalTo(x)).
|
static <E> Matcher<E[]> |
arrayWithSize(Matcher<? super Integer> sizeMatcher)
Does array size satisfy a given matcher?
|
static <LHS> CombinableMatcher<LHS> |
both(Matcher<? super LHS> matcher)
This is useful for fluently combining matchers that must both pass.
|
static Matcher<Double> |
closeTo(double operand,
double error) |
static <T extends Comparable<T>> |
comparesEqualTo(T value)
Is value = expected?
|
static <E> Matcher<Iterable<E>> |
contains(E... items) |
static <E> Matcher<Iterable<E>> |
contains(List<Matcher<? super E>> contents) |
static <E> Matcher<Iterable<E>> |
contains(Matcher<? super E>... item) |
static <E> Matcher<Iterable<E>> |
contains(Matcher<E> item) |
static <T> Matcher<Iterable<T>> |
containsInAnyOrder(Collection<Matcher<? super T>> matchers) |
static <T> Matcher<Iterable<T>> |
containsInAnyOrder(Matcher<? super T>... item) |
static <E> Matcher<Iterable<E>> |
containsInAnyOrder(Matcher<E> item) |
static <T> Matcher<Iterable<T>> |
containsInAnyOrder(T... items) |
static Matcher<String> |
containsString(String substring) |
static <T> Matcher<T> |
describedAs(String description,
Matcher<T> matcher,
Object... values)
Wraps an existing matcher and overrides the description when it fails.
|
static <LHS> CombinableMatcher<LHS> |
either(Matcher<? super LHS> matcher)
This is useful for fluently combining matchers where either may pass, for example:
|
static <E> Matcher<Collection<E>> |
empty()
Matches an empty collection.
|
static <E> Matcher<E[]> |
emptyArray()
Matches an empty array.
|
static <E> Matcher<Iterable<E>> |
emptyIterable()
Matches an empty iterable.
|
static Matcher<String> |
endsWith(String substring) |
static <T> Matcher<? super T> |
equalTo(T operand)
Is the value equal to another value, as tested by the
Object.equals(java.lang.Object) invokedMethod? |
static Matcher<String> |
equalToIgnoringCase(String string) |
static Matcher<String> |
equalToIgnoringWhiteSpace(String string) |
static Matcher<EventObject> |
eventFrom(Class<? extends EventObject> eventClass,
Object source)
Constructs an IsEventFrom Matcher that returns true for any object
derived from eventClass announced by source.
|
static Matcher<EventObject> |
eventFrom(Object source)
Constructs an IsEventFrom Matcher that returns true for any object
derived from
EventObject announced by source
. |
static <U> Matcher<Iterable<U>> |
everyItem(Matcher<U> itemMatcher) |
static <T extends Comparable<T>> |
greaterThan(T value)
Is value > expected?
|
static <T extends Comparable<T>> |
greaterThanOrEqualTo(T value)
Is value >= expected?
|
static <K,V> Matcher<Map<? extends K,? extends V>> |
hasEntry(K key,
V value) |
static <K,V> Matcher<Map<? extends K,? extends V>> |
hasEntry(Matcher<? super K> keyMatcher,
Matcher<? super V> valueMatcher) |
static <T> Matcher<Iterable<? super T>> |
hasItem(Matcher<? super T> elementMatcher) |
static <T> Matcher<Iterable<? super T>> |
hasItem(T element) |
static <T> Matcher<T[]> |
hasItemInArray(Matcher<? super T> elementMatcher)
Evaluates to true if any item in an array satisfies the given matcher.
|
static <T> Matcher<T[]> |
hasItemInArray(T element)
This is a shortcut to the frequently used hasItemInArray(equalTo(x)).
|
static <T> Matcher<Iterable<T>> |
hasItems(Matcher<? super T>... elementMatchers) |
static <T> Matcher<Iterable<T>> |
hasItems(T... elements) |
static <K> Matcher<Map<? super K,?>> |
hasKey(K key) |
static <K> Matcher<Map<? super K,?>> |
hasKey(Matcher<? super K> keyMatcher) |
static <T> Matcher<T> |
hasProperty(String propertyName) |
static <T> Matcher<T> |
hasProperty(String propertyName,
Matcher<?> value) |
static <E> Matcher<? super Collection<? extends E>> |
hasSize(int size)
This is a shortcut to the frequently used hasSize(equalTo(x)).
|
static <E> Matcher<? super Collection<? extends E>> |
hasSize(Matcher<? super Integer> size)
Does collection size satisfy a given matcher?
|
static <T> Matcher<T> |
hasToString(Matcher<? super String> toStringMatcher)
Evaluates whether item.toString() satisfies a given matcher.
|
static <T> Matcher<T> |
hasToString(String expectedToString)
This is a shortcut to the frequently used has_string(equalTo(x)).
|
static <V> Matcher<? super Map<?,V>> |
hasValue(Matcher<? super V> valueMatcher) |
static <V> Matcher<? super Map<?,V>> |
hasValue(V value) |
static Matcher<Node> |
hasXPath(String xPath) |
static Matcher<Node> |
hasXPath(String xPath,
Matcher<? super String> valueMatcher) |
static Matcher<Node> |
hasXPath(String xPath,
NamespaceContext namespaceContext) |
static Matcher<Node> |
hasXPath(String xPath,
NamespaceContext namespaceContext,
Matcher<? super String> valueMatcher) |
static <T> Matcher<T> |
instanceOf(Class<?> type)
Is the value an instance of a particular type?
This version assumes no relationship between the required type and
the signature of the method that sets it up, for example in
assertThat(anObject, instanceOf(Thing.class)); |
static <T> Matcher<? super T> |
is(Class<T> type)
This is a shortcut to the frequently used is(instanceOf(SomeClass.class)).
|
static <T> Matcher<T> |
is(Matcher<T> matcher)
Decorates another Matcher, retaining the behavior but allowing tests
to be slightly more expressive.
|
static <T> Matcher<? super T> |
is(T value)
This is a shortcut to the frequently used is(equalTo(x)).
|
static <T> Matcher<T> |
isIn(Collection<T> collection) |
static <T> Matcher<T> |
isIn(T[] param1) |
static <T> Matcher<T> |
isOneOf(T... elements) |
static <E> Matcher<Iterable<E>> |
iterableWithSize(int size) |
static <E> Matcher<Iterable<E>> |
iterableWithSize(Matcher<? super Integer> sizeMatcher) |
static <T extends Comparable<T>> |
lessThan(T value)
Is value < expected?
|
static <T extends Comparable<T>> |
lessThanOrEqualTo(T value)
Is value <= expected?
|
static <T> Matcher<T> |
not(Matcher<T> matcher)
Inverts the rule.
|
static <T> Matcher<? super T> |
not(T value)
This is a shortcut to the frequently used not(equalTo(x)).
|
static <T> Matcher<T> |
notNullValue()
Matches if value is not null.
|
static <T> Matcher<T> |
notNullValue(Class<T> type)
Matches if value is not null.
|
static <T> Matcher<T> |
nullValue()
Matches if value is null.
|
static <T> Matcher<T> |
nullValue(Class<T> type)
Matches if value is null.
|
static <T> Matcher<T> |
sameInstance(T object)
Creates a new instance of IsSame
|
static <T> Matcher<T> |
samePropertyValuesAs(T expectedBean) |
static Matcher<String> |
startsWith(String substring) |
static <T> Matcher<Class<?>> |
typeCompatibleWith(Class<T> baseType) |
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth)
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)
public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers)
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers)
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second)
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)
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)
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)
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)
public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers)
public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers)
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second)
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)
public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher)
assertThat(string, both(containsString("a")).and(containsString("b")));
public static <LHS> CombinableMatcher<LHS> either(Matcher<? super LHS> matcher)
assertThat(string, both(containsString("a")).and(containsString("b")));
public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values)
public static <U> Matcher<Iterable<U>> everyItem(Matcher<U> itemMatcher)
itemMatcher
- A matcher to apply to every element in a collection.public static <T> Matcher<T> is(Matcher<T> matcher)
public static <T> Matcher<? super T> is(T value)
public static <T> Matcher<? super T> is(Class<T> type)
public static <T> Matcher<T> anything()
public static <T> Matcher<T> anything(String description)
description
- A meaningful string used when describing itself.public static <T> Matcher<? super T> equalTo(T operand)
Object.equals(java.lang.Object)
invokedMethod?public static <T> Matcher<T> instanceOf(Class<?> type)
assertThat(anObject, instanceOf(Thing.class));
public static <T> Matcher<T> any(Class<T> type)
with(any(Thing.class))
public static <T> Matcher<? super T> not(T value)
public static <T> Matcher<T> nullValue()
public static <T> Matcher<T> nullValue(Class<T> type)
public static <T> Matcher<T> notNullValue()
public static <T> Matcher<T> notNullValue(Class<T> type)
public static <T> Matcher<T> sameInstance(T object)
object
- The predicate evaluates to true only when the argument is
this object.public static <T> IsArray<T> array(Matcher<? super T>... elementMatchers)
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)
public static <T> Matcher<T[]> hasItemInArray(T element)
public static <E> Matcher<E[]> arrayContaining(E... items)
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... matchers)
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> matchers)
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items)
public static <E> Matcher<E[]> arrayWithSize(Matcher<? super Integer> sizeMatcher)
public static <E> Matcher<E[]> arrayWithSize(int size)
public static <E> Matcher<E[]> emptyArray()
public static <E> Matcher<? super Collection<? extends E>> hasSize(Matcher<? super Integer> size)
public static <E> Matcher<? super Collection<? extends E>> hasSize(int size)
public static <E> Matcher<Collection<E>> empty()
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Collection<Matcher<? super T>> matchers)
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<? super T>... item)
public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer> sizeMatcher)
public static <K,V> Matcher<Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)
public static <T> Matcher<T> isIn(Collection<T> collection)
public static <T> Matcher<T> isIn(T[] param1)
public static <T> Matcher<T> isOneOf(T... elements)
public static <T extends Comparable<T>> Matcher<? super T> comparesEqualTo(T value)
public static <T extends Comparable<T>> Matcher<? super T> greaterThan(T value)
public static <T extends Comparable<T>> Matcher<? super T> greaterThanOrEqualTo(T value)
public static <T extends Comparable<T>> Matcher<? super T> lessThan(T value)
public static <T extends Comparable<T>> Matcher<? super T> lessThanOrEqualTo(T value)
public static <T> Matcher<T> hasToString(Matcher<? super String> toStringMatcher)
public static <T> Matcher<T> hasToString(String expectedToString)
public static Matcher<EventObject> eventFrom(Class<? extends EventObject> eventClass, Object source)
public static Matcher<EventObject> eventFrom(Object source)
EventObject
announced by source
.public static <T> Matcher<T> samePropertyValuesAs(T expectedBean)
public static Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<? super String> valueMatcher)
public static Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext)
Copyright © 2016. All rights reserved.