package org.hamcrest; public class Matchers { /** * Creates a matcher that matches if the examined object matches ALL of the specified matchers. * For example: *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))*/ public static
assertThat("fab", both(containsString("a")).and(containsString("b")))*/ public static
assertThat("fan", either(containsString("a")).or(containsString("b")))*/ public static
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())* * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static
itemMatcher
.
* For example:
* assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))* * @param itemMatcher * the matcher to apply to every item provided by the examined {@link Iterable} */ public static org.hamcrest.Matcher
assertThat(cheese, is(equalTo(smelly)))* instead of: *
assertThat(cheese, equalTo(smelly))*/ public static
is(equalTo(x))
.
* For example:
* assertThat(cheese, is(smelly))* instead of: *
assertThat(cheese, is(equalTo(smelly)))*/ public static
This method was removed upstream between Hamcrest 1.1 and 1.3 in favour of the
* instanceOf(Class) method. Unfortunately, existing usages of it could still compile against the
* {@link #is(Object)} method instead. Although not every existing usage would compile
* successfully it is possible that some could and that would result in a change in the runtime
* behavior that could be difficult to detect and fix. This change aims to turn any significant
* usage of this method into a compile time error.
*
* @deprecated Use instanceOf(SomeClass.class) instead.
*/
public static void is(java.lang.Class> type) {
}
/**
* A shortcut to the frequently used is(instanceOf(SomeClass.class))
.
* For example:
*
assertThat(cheese, isA(Cheddar.class))* instead of: *
assertThat(cheese, is(instanceOf(Cheddar.class)))*/ public static
itemMatcher
. Whilst matching, the traversal of the examined {@link Iterable}
* will stop as soon as a matching item is found.
* For example:
* assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))* * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} */ public static
item
. Whilst matching, the traversal of the examined {@link Iterable}
* will stop as soon as a matching item is found.
* For example:
* assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))* * @param item * the item to compare against the items provided by the examined {@link Iterable} */ public static
itemMatchers
. Whilst matching, each traversal of
* the examined {@link Iterable} will stop as soon as a matching item is found.
* For example:
* assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))* * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ public static
items
. Whilst matching, each traversal of the
* examined {@link Iterable} will stop as soon as a matching item is found.
* For example:
* assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))* * @param items * the items to compare against the items provided by the examined {@link Iterable} */ public static
operand
, as determined by calling the {@link java.lang.Object#equals} method on
* the examined object.
*
* If the specified operand is null
then the created matcher will only match if
* the examined object's equals
method returns true
when passed a
* null
(which would be a violation of the equals
contract), unless the
* examined object itself is null
, in which case the matcher will return a positive
* match.
The created matcher provides a special behaviour when examining Array
s, whereby
* it will match if both the operand and the examined object are arrays of the same length and
* contain items that are equal to each other (according to the above rules) in the same
* indexes.
* assertThat("foo", equalTo("foo")); * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"})); **/ public static
type
,
* as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the
* the examined object.
*
* The created matcher forces a relationship between specified type and the examined object, and should be
* used when it is necessary to make generics conform, for example in the JMock clause
* with(any(Thing.class))
assertThat(new Canoe(), instanceOf(Canoe.class));*/ public static
type
,
* as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the
* the examined object.
*
* The created matcher assumes no relationship between specified type and the examined object.
* For example: *assertThat(new Canoe(), instanceOf(Paddlable.class));*/ public static
assertThat(cheese, is(not(equalTo(smelly))))* * @param matcher * the matcher whose sense should be inverted */ public static
not(equalTo(x))
.
* For example:
* assertThat(cheese, is(not(smelly)))* instead of: *
assertThat(cheese, is(not(equalTo(smelly))))* * @param value * the value that any examined object should not equal */ public static
not(nullValue())
.
* For example:
* assertThat(cheese, is(notNullValue()))* instead of: *
assertThat(cheese, is(not(nullValue())))*/ public static org.hamcrest.Matcher
not(nullValue(X.class)). Accepts a
* single dummy argument to facilitate type inference.
.
* For example:
* assertThat(cheese, is(notNullValue(X.class)))* instead of: *
assertThat(cheese, is(not(nullValue(X.class))))* * @param type * dummy parameter used to infer the generic type of the returned matcher */ public static
null
.
* For example:
* assertThat(cheese, is(nullValue())*/ public static org.hamcrest.Matcher
null
. Accepts a
* single dummy argument to facilitate type inference.
* For example:
* assertThat(cheese, is(nullValue(Cheese.class))* * @param type * dummy parameter used to infer the generic type of the returned matcher */ public static
assertThat("myStringOfNote", containsString("ring"))* * @param substring * the substring that the returned matcher will expect to find within any examined string */ public static org.hamcrest.Matcher
assertThat("myStringOfNote", containsString("ring"))* * @param substring * the substring that the returned matcher will expect to find within any examined string */ public static org.hamcrest.Matcher
* Creates a matcher that matches if the examined {@link String} starts with the specified * {@link String}. *
* For example: *assertThat("myStringOfNote", startsWith("my"))* * @param prefix * the substring that the returned matcher will expect at the start of any examined string */ public static org.hamcrest.Matcher
* Creates a matcher that matches if the examined {@link String} starts with the specified * {@link String}, ignoring case *
* For example: *assertThat("myStringOfNote", startsWith("my"))* * @param prefix * the substring that the returned matcher will expect at the start of any examined string */ public static org.hamcrest.Matcher
assertThat("myStringOfNote", endsWith("Note"))* * @param suffix * the substring that the returned matcher will expect at the end of any examined string */ public static org.hamcrest.Matcher
assertThat("myStringOfNote", endsWith("Note"))* * @param suffix * the substring that the returned matcher will expect at the end of any examined string */ public static org.hamcrest.Matcher
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))* * @param elementMatchers * the matchers that the elements of examined arrays should satisfy */ public static
elementMatcher
. Whilst matching, the traversal
* of the examined array will stop as soon as a matching element is found.
* For example:
* assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))* * @param elementMatcher * the matcher to apply to elements in examined arrays */ public static
hasItemInArray(equalTo(x))
.
* For example:
* assertThat(hasItemInArray(x))* instead of: *
assertThat(hasItemInArray(equalTo(x)))* * @param element * the element that should be present in examined arrays */ public static
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))* * @param items * the items that must equal the items within an examined array */ public static
assertThat(new String[]{"foo", "bar"}, contains(equalTo("foo"), equalTo("bar")))* * @param itemMatchers * the matchers that must be satisfied by the items in the examined array */ public static
assertThat(new String[]{"foo", "bar"}, contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))* * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item in an examined array */ public static
* Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified matchers. * For a positive match, the examined array must be of the same length as the number of * specified matchers. *
** N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * array. *
** For example: *
*assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))* * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array */ public static
* 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. * For a positive match, the examined array must be of the same length as the specified collection * of matchers. *
** N.B. each matcher in the specified collection will only be used once during a given * examination, so be careful when specifying matchers that may be satisfied by more than * one entry in an examined array. *
** For example: *
*assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))* * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined array */ public static
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. * For a positive match, the examined array must be of the same length as the number of * specified items. *
*N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * array. *
** For example: *
*assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))* * @param items * the items that must equal the entries of an examined array, in any order */ public static
length
of the array
* satisfies the specified matcher.
* For example:
* assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))* * @param sizeMatcher * a matcher for the length of an examined array */ public static
length
of the array
* equals the specified size
.
* For example:
* assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))* * @param size * the length that an examined array must have for a positive match */ public static
length
of the array
* is zero.
* For example:
* assertThat(new String[0], emptyArray())*/ public static
size()
method returns
* a value that satisfies the specified matcher.
* For example:
* assertThat(myMap, is(aMapWithSize(equalTo(2))))* * @param sizeMatcher * a matcher for the size of an examined {@link java.util.Map} */ public static
size()
method returns
* a value equal to the specified size
.
* For example:
* assertThat(myMap, is(aMapWithSize(2)))* * @param size * the expected size of an examined {@link java.util.Map} */ public static
size()
method returns
* zero.
* For example:
* assertThat(myMap, is(anEmptyMap()))*/ public static
size()
method returns
* a value that satisfies the specified matcher.
* For example:
* assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))* * @param sizeMatcher * a matcher for the size of an examined {@link java.util.Collection} */ public static
size()
method returns
* a value equal to the specified size
.
* For example:
* assertThat(Arrays.asList("foo", "bar"), hasSize(2))* * @param size * the expected size of an examined {@link java.util.Collection} */ public static
isEmpty
* method returns true
.
* For example:
* assertThat(new ArrayList<String>(), is(empty()))*/ public static
isEmpty
* method returns true
.
* For example:
* assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))* * @param unusedToForceReturnType * the type of the collection's content */ public static
assertThat(new ArrayList<String>(), is(emptyIterable()))*/ public static
assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))* * @param unusedToForceReturnType * the type of the iterable's content */ public static
assertThat(Arrays.asList("foo", "bar"), contains("foo", "bar"))* * @param items * the items that must equal the items provided by an examined {@link Iterable} */ public static
assertThat(Arrays.asList("foo"), contains(equalTo("foo")))* * @param itemMatcher * the matcher that must be satisfied by the single item provided by an * examined {@link Iterable} */ public static
assertThat(Arrays.asList("foo", "bar"), contains(equalTo("foo"), equalTo("bar")))* * @param itemMatchers * the matchers that must be satisfied by the items provided by an examined {@link Iterable} */ public static
assertThat(Arrays.asList("foo", "bar"), contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))* * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item provided by * an examined {@link Iterable} */ public static
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere * in the specified matchers. For a positive match, the examined iterable must be of the same * length as the number of specified matchers. *
** N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * iterable. *
** For example: *
*assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(equalTo("bar"), equalTo("foo")))* * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} */ public static
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over * the examined {@link Iterable} yields a series of items, each logically equal to one item * anywhere in the specified items. For a positive match, the examined iterable * must be of the same length as the number of specified items. *
** N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * iterable. *
** For example: *
*assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))* * @param items * the items that must equal the items provided by an examined {@link Iterable} in any order */ public static
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere * in the specified collection of matchers. For a positive match, the examined iterable * must be of the same length as the specified collection of matchers. *
** N.B. each matcher in the specified collection will only be used once during a given * examination, so be careful when specifying matchers that may be satisfied by more than * one entry in an examined iterable. *
*For example:
*assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))* * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} */ public static
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))* * @param items * the items that must be contained within items provided by an examined {@link Iterable} in the same relative order */ public static
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))* * @param itemMatchers * the matchers that must be satisfied by the items provided by an examined {@link Iterable} in the same relative order */ public static
assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))* * @param itemMatchers * a list of matchers, each of which must be satisfied by the items provided by * an examined {@link Iterable} in the same relative order */ public static
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))* * @param sizeMatcher * a matcher for the number of items that should be yielded by an examined {@link Iterable} */ public static
size
argument.
* For example:
* assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))* * @param size * the number of items that should be yielded by an examined {@link Iterable} */ public static
keyMatcher
and whose
* value satisfies the specified valueMatcher
.
* For example:
* assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))* * @param keyMatcher * the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry * @param valueMatcher * the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry */ public static
key
and whose value equals the
* specified value
.
* For example:
* assertThat(myMap, hasEntry("bar", "foo"))* * @param key * the key that, in combination with the value, must be describe at least one entry * @param value * the value that, in combination with the key, must be describe at least one entry */ public static
assertThat(myMap, hasKey(equalTo("bar")))* * @param keyMatcher * the matcher that must be satisfied by at least one key */ public static
assertThat(myMap, hasKey("bar"))* * @param key * the key that satisfying maps must contain */ public static
assertThat(myMap, hasValue(equalTo("foo")))* * @param valueMatcher * the matcher that must be satisfied by at least one value */ public static
assertThat(myMap, hasValue("foo"))* * @param value * the value that satisfying maps must contain */ public static
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))* * @param collection * the collection in which matching items must be found */ public static