All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hamcrest.Matchers Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
// Generated source.
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 org.hamcrest.Matcher allOf(java.lang.Iterable> matchers) { return org.hamcrest.core.AllOf.allOf(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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher... matchers) { return org.hamcrest.core.AllOf.allOf(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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second) { return org.hamcrest.core.AllOf.allOf(first, second); } /** * 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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third) { return org.hamcrest.core.AllOf.allOf(first, second, third); } /** * 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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth) { return org.hamcrest.core.AllOf.allOf(first, second, third, fourth); } /** * 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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth) { return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth); } /** * 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 org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth, org.hamcrest.Matcher sixth) { return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth, sixth); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(java.lang.Iterable> matchers) { return org.hamcrest.core.AnyOf.anyOf(matchers); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third) { return org.hamcrest.core.AnyOf.anyOf(first, second, third); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth) { return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth) { return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth, org.hamcrest.Matcher sixth) { return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth, sixth); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second) { return org.hamcrest.core.AnyOf.anyOf(first, second); } /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. *

* For example: *

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/ public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher... matchers) { return org.hamcrest.core.AnyOf.anyOf(matchers); } /** * Creates a matcher that matches when both of the specified matchers match the examined object. *

* For example: *

assertThat("fab", both(containsString("a")).and(containsString("b")))
*/ public static org.hamcrest.core.CombinableMatcher.CombinableBothMatcher both(org.hamcrest.Matcher matcher) { return org.hamcrest.core.CombinableMatcher.both(matcher); } /** * Creates a matcher that matches when either of the specified matchers match the examined object. *

* For example: *

assertThat("fan", either(containsString("a")).and(containsString("b")))
*/ public static org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher either(org.hamcrest.Matcher matcher) { return org.hamcrest.core.CombinableMatcher.either(matcher); } /** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. *

* For example: *

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 org.hamcrest.Matcher describedAs(java.lang.String description, org.hamcrest.Matcher matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); } /** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields items that are all matched by the specified * 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> everyItem(org.hamcrest.Matcher itemMatcher) { return org.hamcrest.core.Every.everyItem(itemMatcher); } /** * A shortcut to the frequently used is(equalTo(x)). *

* For example: *

assertThat(cheese, is(smelly))
* instead of: *
assertThat(cheese, is(equalTo(smelly)))
*/ public static org.hamcrest.Matcher is(T value) { return org.hamcrest.core.Is.is(value); } /** * Decorates another Matcher, retaining its behaviour, but allowing tests * to be slightly more expressive. *

* For example: *

assertThat(cheese, is(equalTo(smelly)))
* instead of: *
assertThat(cheese, equalTo(smelly))
*/ public static org.hamcrest.Matcher is(org.hamcrest.Matcher matcher) { return org.hamcrest.core.Is.is(matcher); } /** * A shortcut to the frequently used is(instanceOf(SomeClass.class)). *

* For example: *

assertThat(cheese, is(Cheddar.class))
* instead of: *
assertThat(cheese, is(instanceOf(Cheddar.class)))
* * @deprecated use isA(Class type) instead. */ public static org.hamcrest.Matcher is(java.lang.Class type) { return org.hamcrest.core.Is.is(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 org.hamcrest.Matcher isA(java.lang.Class type) { return org.hamcrest.core.Is.isA(type); } /** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher anything() { return org.hamcrest.core.IsAnything.anything(); } /** * Creates a matcher that always matches, regardless of the examined object, but describes * itself with the specified {@link String}. * * @param description * a meaningful {@link String} used when describing itself */ public static org.hamcrest.Matcher anything(java.lang.String description) { return org.hamcrest.core.IsAnything.anything(description); } /** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is equal to the specified * 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 org.hamcrest.Matcher> hasItem(T item) { return org.hamcrest.core.IsCollectionContaining.hasItem(item); } /** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified * 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 org.hamcrest.Matcher> hasItem(org.hamcrest.Matcher itemMatcher) { return org.hamcrest.core.IsCollectionContaining.hasItem(itemMatcher); } /** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified 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 org.hamcrest.Matcher> hasItems(T... items) { return org.hamcrest.core.IsCollectionContaining.hasItems(items); } /** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified 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 org.hamcrest.Matcher> hasItems(org.hamcrest.Matcher... itemMatchers) { return org.hamcrest.core.IsCollectionContaining.hasItems(itemMatchers); } /** * Creates a matcher that matches when the examined object is logically equal to the specified * 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 Arrays, 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.

*

* For example: *

   * assertThat("foo", equalTo("foo"));
   * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
   * 
*/ public static org.hamcrest.Matcher equalTo(T operand) { return org.hamcrest.core.IsEqual.equalTo(operand); } /** * Creates a matcher that matches when the examined object is an instance of the specified 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))

*

* For example: *

assertThat(new Canoe(), instanceOf(Canoe.class));
*/ public static org.hamcrest.Matcher any(java.lang.Class type) { return org.hamcrest.core.IsInstanceOf.any(type); } /** * Creates a matcher that matches when the examined object is an instance of the specified 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 org.hamcrest.Matcher instanceOf(java.lang.Class type) { return org.hamcrest.core.IsInstanceOf.instanceOf(type); } /** * Creates a matcher that wraps an existing matcher, but inverts the logic by which * it will match. *

* For example: *

assertThat(cheese, is(not(equalTo(smelly))))
* * @param matcher * the matcher whose sense should be inverted */ public static org.hamcrest.Matcher not(org.hamcrest.Matcher matcher) { return org.hamcrest.core.IsNot.not(matcher); } /** * A shortcut to the frequently used 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 org.hamcrest.Matcher not(T value) { return org.hamcrest.core.IsNot.not(value); } /** * Creates a matcher that matches if examined object is null. *

* For example: *

assertThat(cheese, is(nullValue())
*/ public static org.hamcrest.Matcher nullValue() { return org.hamcrest.core.IsNull.nullValue(); } /** * Creates a matcher that matches if examined object is 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 org.hamcrest.Matcher nullValue(java.lang.Class type) { return org.hamcrest.core.IsNull.nullValue(type); } /** * A shortcut to the frequently used not(nullValue()). *

* For example: *

assertThat(cheese, is(notNullValue()))
* instead of: *
assertThat(cheese, is(not(nullValue())))
*/ public static org.hamcrest.Matcher notNullValue() { return org.hamcrest.core.IsNull.notNullValue(); } /** * A shortcut to the frequently used 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 org.hamcrest.Matcher notNullValue(java.lang.Class type) { return org.hamcrest.core.IsNull.notNullValue(type); } /** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * * @param target * the target instance against which others should be assessed */ public static org.hamcrest.Matcher sameInstance(T target) { return org.hamcrest.core.IsSame.sameInstance(target); } /** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * * @param target * the target instance against which others should be assessed */ public static org.hamcrest.Matcher theInstance(T target) { return org.hamcrest.core.IsSame.theInstance(target); } /** * Creates a matcher that matches if the examined {@link String} contains the specified * {@link String} anywhere. *

* For example: *

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 containsString(java.lang.String substring) { return org.hamcrest.core.StringContains.containsString(substring); } /** * 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 startsWith(java.lang.String prefix) { return org.hamcrest.core.StringStartsWith.startsWith(prefix); } /** * Creates a matcher that matches if the examined {@link String} ends with the specified * {@link String}. *

* For example: *

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 endsWith(java.lang.String suffix) { return org.hamcrest.core.StringEndsWith.endsWith(suffix); } /** * Creates a matcher that matches arrays whose elements are satisfied by the specified matchers. Matches * positively only if the number of matchers specified is equal to the length of the examined array and * each matcher[i] is satisfied by array[i]. *

* For example: *

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 org.hamcrest.collection.IsArray array(org.hamcrest.Matcher... elementMatchers) { return org.hamcrest.collection.IsArray.array(elementMatchers); } /** * A shortcut to the frequently used 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 org.hamcrest.Matcher hasItemInArray(T element) { return org.hamcrest.collection.IsArrayContaining.hasItemInArray(element); } /** * Creates a matcher for arrays that matches when the examined array contains at least one item * that is matched by the specified 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 org.hamcrest.Matcher hasItemInArray(org.hamcrest.Matcher elementMatcher) { return org.hamcrest.collection.IsArrayContaining.hasItemInArray(elementMatcher); } /** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified list of matchers. For a positive match, the examined array * must be of the same length as the specified list of matchers. *

* For example: *

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 org.hamcrest.Matcher arrayContaining(java.util.List> itemMatchers) { return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(itemMatchers); } /** * Creates a matcher for arrays that matcheswhen each item in the examined array is * logically equal to the corresponding item in the specified items. For a positive match, * the examined array must be of the same length as the number of specified items. *

* For example: *

assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
* * @param items * the items that must equal the items within an examined array */ public static org.hamcrest.Matcher arrayContaining(E... items) { return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(items); } /** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified matchers. For a positive match, the examined array * must be of the same length as the number of specified matchers. *

* For example: *

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 org.hamcrest.Matcher arrayContaining(org.hamcrest.Matcher... itemMatchers) { return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(itemMatchers); } /** * 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 org.hamcrest.Matcher arrayContainingInAnyOrder(E... items) { return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(items); } /** * 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 org.hamcrest.Matcher arrayContainingInAnyOrder(org.hamcrest.Matcher... itemMatchers) { return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(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. * 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 org.hamcrest.Matcher arrayContainingInAnyOrder(java.util.Collection> itemMatchers) { return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers); } /** * Creates a matcher for arrays that matches when the 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 org.hamcrest.Matcher arrayWithSize(org.hamcrest.Matcher sizeMatcher) { return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(sizeMatcher); } /** * Creates a matcher for arrays that matches when the 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 org.hamcrest.Matcher arrayWithSize(int size) { return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(size); } /** * Creates a matcher for arrays that matches when the length of the array * is zero. *

* For example: *

assertThat(new String[0], emptyArray())
*/ public static org.hamcrest.Matcher emptyArray() { return org.hamcrest.collection.IsArrayWithSize.emptyArray(); } /** * Creates a matcher for {@link java.util.Collection}s that matches when the 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 org.hamcrest.Matcher> hasSize(org.hamcrest.Matcher sizeMatcher) { return org.hamcrest.collection.IsCollectionWithSize.hasSize(sizeMatcher); } /** * Creates a matcher for {@link java.util.Collection}s that matches when the 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 org.hamcrest.Matcher> hasSize(int size) { return org.hamcrest.collection.IsCollectionWithSize.hasSize(size); } /** * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty * method returns true. *

* For example: *

assertThat(new ArrayList<String>(), is(empty()))
*/ public static org.hamcrest.Matcher> empty() { return org.hamcrest.collection.IsEmptyCollection.empty(); } /** * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty * method returns true. *

* For example: *

assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
* * @param type * the type of the collection's content */ public static org.hamcrest.Matcher> emptyCollectionOf(java.lang.Class type) { return org.hamcrest.collection.IsEmptyCollection.emptyCollectionOf(type); } /** * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. *

* For example: *

assertThat(new ArrayList<String>(), is(emptyIterable()))
*/ public static org.hamcrest.Matcher> emptyIterable() { return org.hamcrest.collection.IsEmptyIterable.emptyIterable(); } /** * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. *

* For example: *

assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
* * @param type * the type of the iterable's content */ public static org.hamcrest.Matcher> emptyIterableOf(java.lang.Class type) { return org.hamcrest.collection.IsEmptyIterable.emptyIterableOf(type); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields a series of items, each satisfying the corresponding * matcher in the specified matchers. For a positive match, the examined iterable * must be of the same length as the number of specified matchers. *

* For example: *

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 org.hamcrest.Matcher> contains(org.hamcrest.Matcher... itemMatchers) { return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); } /** * Creates a 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 the * corresponding item in the specified items. For a positive match, the examined iterable * must be of the same length as the number of specified items. *

* For example: *

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 org.hamcrest.Matcher> contains(E... items) { return org.hamcrest.collection.IsIterableContainingInOrder.contains(items); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields a single item that satisfies the specified matcher. * For a positive match, the examined iterable must only yield one item. *

* For example: *

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 org.hamcrest.Matcher> contains(org.hamcrest.Matcher itemMatcher) { return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatcher); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields a series of items, each satisfying the corresponding * matcher in the specified list of matchers. For a positive match, the examined iterable * must be of the same length as the specified list of matchers. *

* For example: *

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 org.hamcrest.Matcher> contains(java.util.List> itemMatchers) { return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); } /** * 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 org.hamcrest.Matcher> containsInAnyOrder(T... items) { return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(items); } /** * 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 org.hamcrest.Matcher> containsInAnyOrder(java.util.Collection> itemMatchers) { return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); } /** * 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 org.hamcrest.Matcher> containsInAnyOrder(org.hamcrest.Matcher... itemMatchers) { return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields a single item that satisfies the specified matcher. * For a positive match, the examined iterable must only yield one item. *

* For example: *

assertThat(Arrays.asList("foo"), containsInAnyOrder(equalTo("foo")))
* * @deprecated use contains(Matcher itemMatcher) instead * @param itemMatcher * the matcher that must be satisfied by the single item provided by an * examined {@link Iterable} */ public static org.hamcrest.Matcher> containsInAnyOrder(org.hamcrest.Matcher itemMatcher) { return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatcher); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields an item count that satisfies the specified * matcher. *

* For example: *

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 org.hamcrest.Matcher> iterableWithSize(org.hamcrest.Matcher sizeMatcher) { return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(sizeMatcher); } /** * Creates a matcher for {@link Iterable}s that matches when a single pass over the * examined {@link Iterable} yields an item count that is equal to the specified * 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 org.hamcrest.Matcher> iterableWithSize(int size) { return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(size); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one entry whose key equals the specified 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 org.hamcrest.Matcher> hasEntry(K key, V value) { return org.hamcrest.collection.IsMapContaining.hasEntry(key, value); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one entry whose key satisfies the specified 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 org.hamcrest.Matcher> hasEntry(org.hamcrest.Matcher keyMatcher, org.hamcrest.Matcher valueMatcher) { return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that satisfies the specified matcher. *

* For example: *

assertThat(myMap, hasKey(equalTo("bar")))
* * @param keyMatcher * the matcher that must be satisfied by at least one key */ public static org.hamcrest.Matcher> hasKey(org.hamcrest.Matcher keyMatcher) { return org.hamcrest.collection.IsMapContaining.hasKey(keyMatcher); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that is equal to the specified key. *

* For example: *

assertThat(myMap, hasKey("bar"))
* * @param key * the key that satisfying maps must contain */ public static org.hamcrest.Matcher> hasKey(K key) { return org.hamcrest.collection.IsMapContaining.hasKey(key); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one value that is equal to the specified value. *

* For example: *

assertThat(myMap, hasValue("foo"))
* * @param value * the value that satisfying maps must contain */ public static org.hamcrest.Matcher> hasValue(V value) { return org.hamcrest.collection.IsMapContaining.hasValue(value); } /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one value that satisfies the specified valueMatcher. *

* For example: *

assertThat(myMap, hasValue(equalTo("foo")))
* * @param valueMatcher * the matcher that must be satisfied by at least one value */ public static org.hamcrest.Matcher> hasValue(org.hamcrest.Matcher valueMatcher) { return org.hamcrest.collection.IsMapContaining.hasValue(valueMatcher); } /** * Creates a matcher that matches when the examined object is found within the * specified collection. *

* For example: *

assertThat("foo", isIn(Arrays.asList("bar", "foo")))
* * @param collection * the collection in which matching items must be found */ public static org.hamcrest.Matcher isIn(java.util.Collection collection) { return org.hamcrest.collection.IsIn.isIn(collection); } public static org.hamcrest.Matcher isIn(T[] param1) { return org.hamcrest.collection.IsIn.isIn(param1); } /** * Creates a matcher that matches when the examined object is equal to one of the * specified elements. *

* For example: *

assertThat("foo", isIn("bar", "foo"))
* * @param elements * the elements amongst which matching items will be found */ public static org.hamcrest.Matcher isOneOf(T... elements) { return org.hamcrest.collection.IsIn.isOneOf(elements); } /** * Creates a matcher of {@link Double}s that matches when an examined double is equal * to the specified operand, within a range of +/- error. *

* For example: *

assertThat(1.03, is(closeTo(1.0, 0.03)))
* * @param operand * the expected value of matching doubles * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher closeTo(double operand, double error) { return org.hamcrest.number.IsCloseTo.closeTo(operand, error); } /** * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal * to the specified operand, within a range of +/- error. The comparison for equality * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. *

* For example: *

assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
* * @param operand * the expected value of matching BigDecimals * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); } /** * Creates a matcher of {@link Comparable} object that matches when the examined object is * equal to the specified value, as reported by the compareTo method of the * examined object. *

* For example: *

assertThat(1, comparesEqualTo(1))
* * @param value * the value which, when passed to the compareTo method of the examined object, should return zero */ public static > org.hamcrest.Matcher comparesEqualTo(T value) { return org.hamcrest.number.OrderingComparison.comparesEqualTo(value); } /** * Creates a matcher of {@link Comparable} object that matches when the examined object is * greater than the specified value, as reported by the compareTo method of the * examined object. *

* For example: *

assertThat(2, greaterThan(1))
* * @param value * the value which, when passed to the compareTo method of the examined object, should return greater * than zero */ public static > org.hamcrest.Matcher greaterThan(T value) { return org.hamcrest.number.OrderingComparison.greaterThan(value); } /** * Creates a matcher of {@link 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. *

* For example: *

assertThat(1, greaterThanOrEqualTo(1))
* * @param value * the value which, when passed to the compareTo method of the examined object, should return greater * than or equal to zero */ public static > org.hamcrest.Matcher greaterThanOrEqualTo(T value) { return org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo(value); } /** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than the specified value, as reported by the compareTo method of the * examined object. *

* For example: *

assertThat(1, lessThan(2))
* * @param value * the value which, when passed to the compareTo method of the examined object, should return less * than zero */ public static > org.hamcrest.Matcher lessThan(T value) { return org.hamcrest.number.OrderingComparison.lessThan(value); } /** * Creates a matcher of {@link 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. *

* For example: *

assertThat(1, lessThanOrEqualTo(1))
* * @param value * the value which, when passed to the compareTo method of the examined object, should return less * than or equal to zero */ public static > org.hamcrest.Matcher lessThanOrEqualTo(T value) { return org.hamcrest.number.OrderingComparison.lessThanOrEqualTo(value); } /** * Creates a matcher of {@link String} that matches when the examined string is equal to * the specified expectedString, ignoring case. *

* For example: *

assertThat("Foo", equalToIgnoringCase("FOO"))
* * @param expectedString * the expected value of matched strings */ public static org.hamcrest.Matcher equalToIgnoringCase(java.lang.String expectedString) { return org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase(expectedString); } /** * Creates a matcher of {@link String} that matches when the examined string is equal to * the specified expectedString, when whitespace differences are (mostly) ignored. To be * exact, the following whitespace rules are applied: *
    *
  • all leading and trailing whitespace of both the expectedString and the examined string are ignored
  • *
  • any remaining whitespace, appearing within either string, is collapsed to a single space before comparison
  • *
*

* For example: *

assertThat("   my\tfoo  bar ", equalToIgnoringWhiteSpace(" my  foo bar"))
* * @param expectedString * the expected value of matched strings */ public static org.hamcrest.Matcher equalToIgnoringWhiteSpace(java.lang.String expectedString) { return org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace(expectedString); } /** * Creates a matcher of {@link String} that matches when the examined string has zero length. *

* For example: *

assertThat("", isEmptyString())
*/ public static org.hamcrest.Matcher isEmptyString() { return org.hamcrest.text.IsEmptyString.isEmptyString(); } /** * Creates a matcher of {@link String} that matches when the examined string is null, or * has zero length. *

* For example: *

assertThat(((String)null), isEmptyString())
*/ public static org.hamcrest.Matcher isEmptyOrNullString() { return org.hamcrest.text.IsEmptyString.isEmptyOrNullString(); } /** * Creates a matcher of {@link String} that matches when the examined string contains all of * the specified substrings, regardless of the order of their appearance. *

* For example: *

assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))
* * @param substrings * the substrings that must be contained within matching strings */ public static org.hamcrest.Matcher stringContainsInOrder(java.lang.Iterable substrings) { return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); } /** * Creates a matcher that matches any examined object whose toString method * returns a value that satisfies the specified matcher. *

* For example: *

assertThat(true, hasToString(equalTo("TRUE")))
* * @param toStringMatcher * the matcher used to verify the toString result */ public static org.hamcrest.Matcher hasToString(org.hamcrest.Matcher toStringMatcher) { return org.hamcrest.object.HasToString.hasToString(toStringMatcher); } /** * Creates a matcher that matches any examined object whose toString method * returns a value equalTo the specified string. *

* For example: *

assertThat(true, hasToString("TRUE"))
* * @param expectedToString * the expected toString result */ public static org.hamcrest.Matcher hasToString(java.lang.String expectedToString) { return org.hamcrest.object.HasToString.hasToString(expectedToString); } /** * Creates a matcher of {@link Class} that matches when the specified baseType is * assignable from the examined class. *

* For example: *

assertThat(Integer.class, typeCompatibleWith(Number.class))
* * @param baseType * the base class to examine classes against */ public static org.hamcrest.Matcher> typeCompatibleWith(java.lang.Class baseType) { return org.hamcrest.object.IsCompatibleType.typeCompatibleWith(baseType); } /** * Creates a matcher of {@link java.util.EventObject} that matches any object * derived from eventClass announced by source. *

* For example: *
assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
* * @param eventClass * the class of the event to match on * @param source * the source of the event */ public static org.hamcrest.Matcher eventFrom(java.lang.Class eventClass, java.lang.Object source) { return org.hamcrest.object.IsEventFrom.eventFrom(eventClass, source); } /** * Creates a matcher of {@link java.util.EventObject} that matches any EventObject * announced by source. *

* For example: *
assertThat(myEvent, is(eventFrom(myBean)))
* * @param source * the source of the event */ public static org.hamcrest.Matcher eventFrom(java.lang.Object source) { return org.hamcrest.object.IsEventFrom.eventFrom(source); } /** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name. *

* For example: *

assertThat(myBean, hasProperty("foo"))
* * @param propertyName * the name of the JavaBean property that examined beans should possess */ public static org.hamcrest.Matcher hasProperty(java.lang.String propertyName) { return org.hamcrest.beans.HasProperty.hasProperty(propertyName); } /** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name whose value satisfies the specified matcher. *

* For example: *

assertThat(myBean, hasProperty("foo", equalTo("bar"))
* * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean */ public static org.hamcrest.Matcher hasProperty(java.lang.String propertyName, org.hamcrest.Matcher valueMatcher) { return org.hamcrest.beans.HasPropertyWithValue.hasProperty(propertyName, valueMatcher); } /** * 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. *

* For example: *

assertThat(myBean, samePropertyValuesAs(myExpectedBean))
* * @param expectedBean * the bean against which examined beans are compared */ public static org.hamcrest.Matcher samePropertyValuesAs(T expectedBean) { return org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs(expectedBean); } /** * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node * at the specified xPath within the specified namespace context, with any content. *

* For example: *

assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
* * @param xPath * the target xpath * @param namespaceContext * the namespace for matching nodes */ public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext) { return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext); } /** * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node * at the specified xPath, with any content. *

* For example: *

assertThat(xml, hasXPath("/root/something[2]/cheese"))
* * @param xPath * the target xpath */ public static org.hamcrest.Matcher hasXPath(java.lang.String xPath) { return org.hamcrest.xml.HasXPath.hasXPath(xPath); } /** * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the * specified xPath, within the specified namespaceContext, that satisfies * the specified valueMatcher. *

* For example: *

assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
* * @param xPath * the target xpath * @param namespaceContext * the namespace for matching nodes * @param valueMatcher * matcher for the value at the specified xpath */ public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext, org.hamcrest.Matcher valueMatcher) { return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext, valueMatcher); } /** * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the * specified xPath that satisfies the specified valueMatcher. *

* For example: *

assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
* * @param xPath * the target xpath * @param valueMatcher * matcher for the value at the specified xpath */ public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, org.hamcrest.Matcher valueMatcher) { return org.hamcrest.xml.HasXPath.hasXPath(xPath, valueMatcher); } }