Class Matchers
 Matchers provides syntactic sugar for building matchers, or
 chains of matchers. By using static imports on these methods, concise and
 readable code calling the matchers can be maintained.
 
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> Matcher<T> Creates a matcher that matches if the examined object matches ALL of the specified matchers.static <T> Matcher<T> Creates a matcher that matches if the examined object matches ALL of the specified matchers.static <T> Matcher<T> Creates a matcher that matches if the examined object matches ALL of the specified matchers.static <T> Matcher<T> Creates a matcher that matches if the examined object matches ALL of the specified matchers.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.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.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.aMapWithSize(int size) Creates a matcher forMaps that matches when thesize()method returns a value equal to the specifiedsize.aMapWithSize(Matcher<? super Integer> sizeMatcher) Creates a matcher forMaps that matches when thesize()method returns a value that satisfies the specified matcher.Creates a matcher forMaps that matches when thesize()method returns zero.static <T> Matcher<T> Creates a matcher that matches when the examined object is an instance of the specifiedtype, as determined by calling theClass.isInstance(Object)method on that type, passing the examined object.static <T> AnyOf<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.static <T> AnyOf<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.static <T> AnyOf<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.static <T> AnyOf<T> Creates a matcher that matches if the examined object matches ANY of the specified matchers.static <T> AnyOf<T> anyOf(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 ANY of the specified matchers.static <T> AnyOf<T> anyOf(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 ANY of the specified matchers.static <T> AnyOf<T> anyOf(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 ANY of the specified matchers.anything()Creates a matcher that always matches, regardless of the examined object.Creates a matcher that always matches, regardless of the examined object, but describes itself with the specifiedString.static <T> IsArray<T> Creates a matcher that matches arrays whose elements are satisfied by the specified matchers.static <E> Matcher<E[]> arrayContaining(E... items) Creates a matcher for arrays that matches when each item in the examined array is logically equal to the corresponding item in the specified items.static <E> Matcher<E[]> arrayContaining(List<Matcher<? super E>> 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.static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers) Creates a matcher for arrays that matches when each item in the examined array satisfies the corresponding matcher in the specified matchers.static <E> Matcher<E[]> arrayContainingInAnyOrder(E... 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.static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> 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.static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... 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.static <E> Matcher<E[]> arrayWithSize(int size) Creates a matcher for arrays that matches when thelengthof the array equals the specifiedsize.static <E> Matcher<E[]> arrayWithSize(Matcher<? super Integer> sizeMatcher) Creates a matcher for arrays that matches when thelengthof the array satisfies the specified matcher.Creates a matcher ofStringthat matches when the examined string isnull, or contains zero or more whitespace characters and nothing else.Creates a matcher ofStringthat matches when the examined string contains zero or more whitespace characters and nothing else.static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> Creates a matcher that matches when both of the specified matchers match the examined object.closeTo(double operand, double error) Creates a matcher ofDoubles that matches when an examined double is equal to the specifiedoperand, within a range of +/-error.static Matcher<BigDecimal> closeTo(BigDecimal operand, BigDecimal error) Creates a matcher ofBigDecimals that matches when an examined BigDecimal is equal to the specifiedoperand, within a range of +/-error.static <T extends Comparable<T>>
 Matcher<T> comparesEqualTo(T value) Creates a matcher ofComparableobject that matches when the examined object is equal to the specified value, as reported by thecompareTomethod of the examined object.contains(E... items) containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers) containsInAnyOrder(Matcher<? super T>... itemMatchers) containsInAnyOrder(T... items) containsInRelativeOrder(E... items) containsInRelativeOrder(List<Matcher<? super E>> itemMatchers) containsInRelativeOrder(Matcher<? super E>... itemMatchers) containsString(String substring) containsStringIgnoringCase(String substring) static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) Wraps an existing matcher, overriding its description with that specified.static <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> Creates a matcher that matches when either of the specified matchers match the examined object.static <E> Matcher<Collection<? extends E>> empty()static <E> Matcher<E[]> Creates a matcher for arrays that matches when thelengthof the array is zero.static <E> Matcher<Collection<E>> emptyCollectionOf(Class<E> unusedToForceReturnType) Creates a matcher forIterables matching examined iterables that yield no items.emptyIterableOf(Class<E> unusedToForceReturnType) Creates a matcher forIterables matching examined iterables that yield no items.Creates a matcher ofStringthat matches when the examined string isnull, or has zero length.Creates a matcher ofStringthat matches when the examined string has zero length.endsWithIgnoringCase(String suffix) static <T> Matcher<T> equalTo(T operand) Creates a matcher that matches when the examined object is logically equal to the specifiedoperand, as determined by calling theObject.equals(java.lang.Object)method on the examined object.equalToCompressingWhiteSpace(String expectedString) Creates a matcher ofStringthat matches when the examined string is equal to the specified expectedString, when whitespace differences are (mostly) ignored.equalToIgnoringCase(String expectedString) Creates a matcher ofStringthat matches when the examined string is equal to the specified expectedString, ignoring case.equalToIgnoringWhiteSpace(String expectedString) Deprecated.equalToObject(Object operand) Creates anIsEqualmatcher that does not enforce the values being compared to be of the same static type.static Matcher<EventObject> eventFrom(Class<? extends EventObject> eventClass, Object source) Creates a matcher ofEventObjectthat matches any object derived from eventClass announced by source.static Matcher<EventObject> Creates a matcher ofEventObjectthat matches any EventObject announced by source.static <T extends Comparable<T>>
 Matcher<T> greaterThan(T value) Creates a matcher ofComparableobject that matches when the examined object is greater than the specified value, as reported by thecompareTomethod of the examined object.static <T extends Comparable<T>>
 Matcher<T> greaterThanOrEqualTo(T value) Creates a matcher ofComparableobject that matches when the examined object is greater than or equal to the specified value, as reported by thecompareTomethod of the examined object.hasEntry(K key, V value) hasItem(T item) static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher) Creates a matcher for arrays that matches when the examined array contains at least one item that is matched by the specifiedelementMatcher.static <T> Matcher<T[]> hasItemInArray(T element) A shortcut to the frequently usedhasItemInArray(equalTo(x)).hasItems(T... items) hasKey(K key) static Matcher<CharSequence> hasLength(int length) Creates a matcher ofCharSequencethat matches when a char sequence has the length of the specifiedargument.static Matcher<CharSequence> Creates a matcher ofCharSequencethat matches when a char sequence has the length that satisfies the specified matcher.static <T> Matcher<T> hasProperty(String propertyName) Creates a matcher that matches when the examined object has a JavaBean property with the specified name.static <T> Matcher<T> hasProperty(String propertyName, Matcher<?> valueMatcher) Creates a matcher that matches when the examined object has a JavaBean property with the specified name whose value satisfies the specified matcher.static <E> Matcher<Collection<? extends E>> hasSize(int size) Creates a matcher forCollections that matches when thesize()method returns a value equal to the specifiedsize.static <E> Matcher<Collection<? extends E>> Creates a matcher forCollections that matches when thesize()method returns a value that satisfies the specified matcher.static <T> Matcher<T> hasToString(String expectedToString) Creates a matcher that matches any examined object whosetoStringmethod returns a value equalTo the specified string.static <T> Matcher<T> hasToString(Matcher<? super String> toStringMatcher) Creates a matcher that matches any examined object whosetoStringmethod returns a value that satisfies the specified matcher.hasValue(V value) Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPath, with any content.hasXPath(String xPath, NamespaceContext namespaceContext) Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPathwithin the specified namespace context, with any content.hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<String> valueMatcher) Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPath, within the specifiednamespaceContext, that satisfies the specifiedvalueMatcher.Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPaththat satisfies the specifiedvalueMatcher.static <T> Matcher<T> in(Collection<T> collection) Creates a matcher that matches when the examined object is found within the specified collection.static <T> Matcher<T> in(T[] elements) Creates a matcher that matches when the examined object is found within the specified array.static <T> Matcher<T> instanceOf(Class<?> type) Creates a matcher that matches when the examined object is an instance of the specifiedtype, as determined by calling theClass.isInstance(Object)method on that type, passing the the examined object.static <T> Matcher<T> Decorates another Matcher, retaining its behaviour, but allowing tests to be slightly more expressive.static <T> Matcher<T> is(T value) A shortcut to the frequently usedis(equalTo(x)).static <T> Matcher<T> A shortcut to the frequently usedis(instanceOf(SomeClass.class)).Deprecated.use is(emptyOrNullString()) insteadDeprecated.use is(emptyString()) insteadstatic <T> Matcher<T> isIn(Collection<T> collection) Deprecated.use is(in(...)) insteadstatic <T> Matcher<T> isIn(T[] elements) Deprecated.use is(in(...)) insteadstatic <T> Matcher<T> isOneOf(T... elements) Deprecated.use is(oneOf(...)) insteaditerableWithSize(int size) iterableWithSize(Matcher<? super Integer> sizeMatcher) static <T extends Comparable<T>>
 Matcher<T> lessThan(T value) Creates a matcher ofComparableobject that matches when the examined object is less than the specified value, as reported by thecompareTomethod of the examined object.static <T extends Comparable<T>>
 Matcher<T> lessThanOrEqualTo(T value) Creates a matcher ofComparableobject that matches when the examined object is less than or equal to the specified value, as reported by thecompareTomethod of the examined object.matchesPattern(String regex) matchesPattern(Pattern pattern) matchesRegex(String regex) Validate a string with a regex.matchesRegex(Pattern pattern) Validate a string with aPattern.static <T> Matcher<T> Creates a matcher that wraps an existing matcher, but inverts the logic by which it will match.static <T> Matcher<T> not(T value) A shortcut to the frequently usednot(equalTo(x)).Creates a matcher ofDoubles that matches when an examined double is not a number.A shortcut to the frequently usednot(nullValue()).static <T> Matcher<T> notNullValue(Class<T> type) A shortcut to the frequently usednot(nullValue(X.class)).Creates a matcher that matches if examined object isnull.static <T> Matcher<T> Creates a matcher that matches if examined object isnull.static <T> Matcher<T> oneOf(T... elements) Creates a matcher that matches when the examined object is equal to one of the specified elements.static <T> Matcher<T> sameInstance(T target) Creates a matcher that matches only when the examined object is the same instance as the specified target object.static <B> Matcher<B> samePropertyValuesAs(B expectedBean, String... ignoredProperties) 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.startsWith(String prefix) startsWithIgnoringCase(String prefix) stringContainsInOrder(Iterable<String> substrings) Creates a matcher ofStringthat matches when the examined string contains all of the specified substrings, considering the order of their appearance.stringContainsInOrder(String... substrings) Creates a matcher ofStringthat matches when the examined string contains all of the specified substrings, considering the order of their appearance.static <T> Matcher<T> theInstance(T target) Creates a matcher that matches only when the examined object is the same instance as the specified target object.typeCompatibleWith(Class<T> baseType) Creates a matcher ofClassthat matches when the specified baseType is assignable from the examined class.
- 
Method Details- 
allOfCreates a matcher that matches if the examined object matches ALL of the specified matchers. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- matchers- all the matchers must pass.
- Returns:
- The matcher.
 
- 
allOfCreates a matcher that matches if the examined object matches ALL of the specified matchers. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- matchers- all the matchers must pass.
- Returns:
- The matcher.
 
- 
allOfCreates a matcher that matches if the examined object matches ALL of the specified matchers. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher that must pass.
- second- second matcher that must pass.
- Returns:
- The matcher.
 
- 
allOfpublic 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. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher that must pass.
- second- second matcher that must pass.
- third- third matcher that must pass.
- Returns:
- The matcher.
 
- 
allOfpublic 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. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher that must pass.
- second- second matcher that must pass.
- third- third matcher that must pass.
- fourth- fourth matcher that must pass.
- Returns:
- The matcher.
 
- 
allOfpublic 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. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher that must pass.
- second- second matcher that must pass.
- third- third matcher that must pass.
- fourth- fourth matcher that must pass.
- fifth- fifth matcher that must pass.
- Returns:
- The matcher.
 
- 
allOfpublic 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. For example:assertThat("myValue", allOf(startsWith("my"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher that must pass.
- second- second matcher that must pass.
- third- third matcher that must pass.
- fourth- fourth matcher that must pass.
- fifth- fifth matcher that must pass.
- sixth- sixth matcher that must pass.
- Returns:
- The matcher.
 
- 
anyOfCreates a matcher that matches if the examined object matches ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- matchers- any the matchers must pass.
- Returns:
- The matcher.
 
- 
anyOfCreates a matcher that matches if the examined object matches ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- matchers- any the matchers must pass.
- Returns:
- The matcher.
 
- 
anyOfCreates a matcher that matches if the examined object matches ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher to check.
- second- second matcher to check.
- Returns:
- The matcher.
 
- 
anyOfpublic static <T> AnyOf<T> anyOf(Matcher<? super 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. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher to check.
- second- second matcher to check.
- third- third matcher to check.
- Returns:
- The matcher.
 
- 
anyOfpublic static <T> AnyOf<T> anyOf(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 ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher to check.
- second- second matcher to check.
- third- third matcher to check.
- fourth- fourth matcher to check.
- Returns:
- The matcher.
 
- 
anyOfpublic static <T> AnyOf<T> anyOf(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 ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher to check.
- second- second matcher to check.
- third- third matcher to check.
- fourth- fourth matcher to check.
- fifth- fifth matcher to check.
- Returns:
- The matcher.
 
- 
anyOfpublic static <T> AnyOf<T> anyOf(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 ANY of the specified matchers. For example:assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))- Type Parameters:
- T- the matcher type.
- Parameters:
- first- first matcher to check.
- second- second matcher to check.
- third- third matcher to check.
- fourth- fourth matcher to check.
- fifth- fifth matcher to check.
- sixth- sixth matcher to check.
- Returns:
- The matcher.
 
- 
bothCreates a matcher that matches when both of the specified matchers match the examined object. For example:assertThat("fab", both(containsString("a")).and(containsString("b")))- Type Parameters:
- LHS- the matcher type.
- Parameters:
- matcher- the matcher to combine, and both must pass.
- Returns:
- The matcher.
 
- 
eitherpublic 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. For example:assertThat("fan", either(containsString("a")).or(containsString("b")))- Type Parameters:
- LHS- the matcher type.
- Parameters:
- matcher- the matcher to combine, and either must pass.
- Returns:
- The matcher.
 
- 
describedAsWraps 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())- Type Parameters:
- T- the matcher type.
- Parameters:
- description- the new description for the wrapped matcher
- matcher- the matcher to wrap
- values- optional values to insert into the tokenized description
- Returns:
- The matcher.
 
- 
everyItemCreates a matcher forIterables that only matches when a single pass over the examinedIterableyields items that are all matched by the specifieditemMatcher. For example:assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))- Type Parameters:
- U- the matcher type.
- Parameters:
- itemMatcher- the matcher to apply to every item provided by the examined- Iterable
- Returns:
- The matcher.
 
- 
isDecorates 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)) - Type Parameters:
- T- the matcher type.
- Parameters:
- matcher- the matcher to wrap.
- Returns:
- The matcher.
 
- 
isA shortcut to the frequently usedis(equalTo(x)). For example:assertThat(cheese, is(smelly)) instead of:assertThat(cheese, is(equalTo(smelly))) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value to check.
- Returns:
- The matcher.
 
- 
isAA shortcut to the frequently usedis(instanceOf(SomeClass.class)). For example:assertThat(cheese, isA(Cheddar.class)) instead of:assertThat(cheese, is(instanceOf(Cheddar.class))) - Type Parameters:
- T- the matcher type.
- Parameters:
- type- the type to check.
- Returns:
- The matcher.
 
- 
anythingCreates a matcher that always matches, regardless of the examined object.- Returns:
- The matcher.
 
- 
anythingCreates a matcher that always matches, regardless of the examined object, but describes itself with the specifiedString.- Parameters:
- description- a meaningful- Stringused when describing itself
- Returns:
- The matcher.
 
- 
hasItemCreates a matcher forIterables that only matches when a single pass over the examinedIterableyields at least one item that is matched by the specifieditemMatcher. Whilst matching, the traversal of the examinedIterablewill stop as soon as a matching item is found. For example:assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))- Type Parameters:
- T- the matcher type.
- Parameters:
- itemMatcher- the matcher to apply to items provided by the examined- Iterable
- Returns:
- The matcher.
 
- 
hasItemCreates a matcher forIterables that only matches when a single pass over the examinedIterableyields at least one item that is equal to the specifieditem. Whilst matching, the traversal of the examinedIterablewill stop as soon as a matching item is found. For example:assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))- Type Parameters:
- T- the matcher type.
- Parameters:
- item- the item to compare against the items provided by the examined- Iterable
- Returns:
- The matcher.
 
- 
hasItemsCreates a matcher forIterables that matches when consecutive passes over the examinedIterableyield at least one item that is matched by the corresponding matcher from the specifieditemMatchers. Whilst matching, each traversal of the examinedIterablewill stop as soon as a matching item is found. For example:assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))- Type Parameters:
- T- the matcher type.
- Parameters:
- itemMatchers- the matchers to apply to items provided by the examined- Iterable
- Returns:
- The matcher.
 
- 
hasItemsCreates a matcher forIterables that matches when consecutive passes over the examinedIterableyield at least one item that is equal to the corresponding item from the specifieditems. Whilst matching, each traversal of the examinedIterablewill stop as soon as a matching item is found. For example:assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))- Type Parameters:
- T- the matcher type.
- Parameters:
- items- the items to compare against the items provided by the examined- Iterable
- Returns:
- The matcher.
 
- 
equalToCreates a matcher that matches when the examined object is logically equal to the specifiedoperand, as determined by calling theObject.equals(java.lang.Object)method on the examined object.If the specified operand is nullthen the created matcher will only match if the examined object'sequalsmethod returnstruewhen passed anull(which would be a violation of theequalscontract), unless the examined object itself isnull, in which case the matcher will return a positive match.The created matcher provides a special behaviour when examining For example: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.assertThat("foo", equalTo("foo")); assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));- Type Parameters:
- T- the matcher type.
- Parameters:
- operand- the value to check.
- Returns:
- The matcher.
 
- 
equalToObjectCreates anIsEqualmatcher that does not enforce the values being compared to be of the same static type.- Parameters:
- operand- the value to check.
- Returns:
- The matcher.
 
- 
anyCreates a matcher that matches when the examined object is an instance of the specifiedtype, as determined by calling theClass.isInstance(Object)method on that type, passing 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 For example:with(any(Thing.class))assertThat(new Canoe(), instanceOf(Canoe.class)); - Type Parameters:
- T- the matcher type.
- Parameters:
- type- the type to check.
- Returns:
- The matcher.
 
- 
instanceOfCreates a matcher that matches when the examined object is an instance of the specifiedtype, as determined by calling theClass.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)); - Type Parameters:
- T- the matcher type.
- Parameters:
- type- the type to check.
- Returns:
- The matcher.
 
- 
notCreates a matcher that wraps an existing matcher, but inverts the logic by which it will match. For example:assertThat(cheese, is(not(equalTo(smelly)))) - Type Parameters:
- T- the matcher type.
- Parameters:
- matcher- the matcher whose sense should be inverted
- Returns:
- The matcher.
 
- 
notA shortcut to the frequently usednot(equalTo(x)). For example:assertThat(cheese, is(not(smelly))) instead of:assertThat(cheese, is(not(equalTo(smelly)))) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value that any examined object should not equal
- Returns:
- The matcher.
 
- 
notNullValueA shortcut to the frequently usednot(nullValue()). For example:assertThat(cheese, is(notNullValue())) instead of:assertThat(cheese, is(not(nullValue()))) - Returns:
- The matcher.
 
- 
notNullValueA shortcut to the frequently usednot(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)))) - Type Parameters:
- T- the matcher type.
- Parameters:
- type- dummy parameter used to infer the generic type of the returned matcher
- Returns:
- The matcher.
 
- 
nullValueCreates a matcher that matches if examined object isnull. For example:assertThat(cheese, is(nullValue()) - Returns:
- The matcher.
 
- 
nullValueCreates a matcher that matches if examined object isnull. Accepts a single dummy argument to facilitate type inference. For example:assertThat(cheese, is(nullValue(Cheese.class)) - Type Parameters:
- T- the matcher type.
- Parameters:
- type- dummy parameter used to infer the generic type of the returned matcher
- Returns:
- The matcher.
 
- 
sameInstanceCreates a matcher that matches only when the examined object is the same instance as the specified target object.- Type Parameters:
- T- the matcher type.
- Parameters:
- target- the target instance against which others should be assessed
- Returns:
- The matcher.
 
- 
theInstanceCreates a matcher that matches only when the examined object is the same instance as the specified target object.- Type Parameters:
- T- the matcher type.
- Parameters:
- target- the target instance against which others should be assessed
- Returns:
- The matcher.
 
- 
containsStringCreates a matcher that matches if the examinedStringcontains the specifiedStringanywhere. For example:assertThat("myStringOfNote", containsString("ring"))- Parameters:
- substring- the substring that the returned matcher will expect to find within any examined string
- Returns:
- The matcher.
 
- 
containsStringIgnoringCaseCreates a matcher that matches if the examinedStringcontains the specifiedStringanywhere, ignoring case. For example:assertThat("myStringOfNote", containsStringIgnoringCase("Ring"))- Parameters:
- substring- the substring that the returned matcher will expect to find within any examined string
- Returns:
- The matcher.
 
- 
startsWithCreates a matcher that matches if the examined For example:Stringstarts with the specifiedString.assertThat("myStringOfNote", startsWith("my"))- Parameters:
- prefix- the substring that the returned matcher will expect at the start of any examined string
- Returns:
- The matcher.
 
- 
startsWithIgnoringCaseCreates a matcher that matches if the examined For example:Stringstarts with the specifiedString, ignoring caseassertThat("myStringOfNote", startsWithIgnoringCase("My"))- Parameters:
- prefix- the substring that the returned matcher will expect at the start of any examined string
- Returns:
- The matcher.
 
- 
endsWithCreates a matcher that matches if the examinedStringends with the specifiedString. For example:assertThat("myStringOfNote", endsWith("Note"))- Parameters:
- suffix- the substring that the returned matcher will expect at the end of any examined string
- Returns:
- The matcher.
 
- 
endsWithIgnoringCaseCreates a matcher that matches if the examinedStringends with the specifiedString, ignoring case. For example:assertThat("myStringOfNote", endsWithIgnoringCase("note"))- Parameters:
- suffix- the substring that the returned matcher will expect at the end of any examined string
- Returns:
- The matcher.
 
- 
matchesRegexValidate a string with aPattern.assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));- Parameters:
- pattern- the pattern to be used.
- Returns:
- The matcher.
 
- 
matchesRegexValidate a string with a regex.assertThat("abc", matchesRegex("ˆ[a-z]+$"));- Parameters:
- regex- The regex to be used for the validation.
- Returns:
- The matcher.
 
- 
arrayCreates 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))))- Type Parameters:
- T- the matcher type.
- Parameters:
- elementMatchers- the matchers that the elements of examined arrays should satisfy
- Returns:
- The matcher.
 
- 
hasItemInArrayCreates a matcher for arrays that matches when the examined array contains at least one item that is matched by the specifiedelementMatcher. 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")))- Type Parameters:
- T- the matcher type.
- Parameters:
- elementMatcher- the matcher to apply to elements in examined arrays
- Returns:
- The matcher.
 
- 
hasItemInArrayA shortcut to the frequently usedhasItemInArray(equalTo(x)). For example:assertThat(hasItemInArray(x)) instead of:assertThat(hasItemInArray(equalTo(x))) - Type Parameters:
- T- the matcher type.
- Parameters:
- element- the element that should be present in examined arrays
- Returns:
- The matcher.
 
- 
arrayContainingCreates a matcher for arrays that matches when 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"}, arrayContaining("foo", "bar"))- Type Parameters:
- E- the matcher type.
- Parameters:
- items- the items that must equal the items within an examined array
- Returns:
- The matcher.
 
- 
arrayContainingCreates 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"}, arrayContaining(equalTo("foo"), equalTo("bar")))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- the matchers that must be satisfied by the items in the examined array
- Returns:
- The matcher.
 
- 
arrayContainingCreates 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"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by the corresponding item in an examined array
- Returns:
- The matcher.
 
- 
arrayContainingInAnyOrder@SafeVarargs public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... 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. 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")))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by an entry in an examined array
- Returns:
- The matcher.
 
- 
arrayContainingInAnyOrderpublic static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> 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"))))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by an item provided by an examined array
- Returns:
- The matcher.
 
- 
arrayContainingInAnyOrderCreates 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"}, arrayContainingInAnyOrder("bar", "foo"))- Type Parameters:
- E- the matcher type.
- Parameters:
- items- the items that must equal the entries of an examined array, in any order
- Returns:
- The matcher.
 
- 
arrayWithSizeCreates a matcher for arrays that matches when thelengthof the array satisfies the specified matcher. For example:assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))- Type Parameters:
- E- the matcher type.
- Parameters:
- sizeMatcher- a matcher for the length of an examined array
- Returns:
- The matcher.
 
- 
arrayWithSizeCreates a matcher for arrays that matches when thelengthof the array equals the specifiedsize. For example:assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))- Type Parameters:
- E- the matcher type.
- Parameters:
- size- the length that an examined array must have for a positive match
- Returns:
- The matcher.
 
- 
emptyArrayCreates a matcher for arrays that matches when thelengthof the array is zero. For example:assertThat(new String[0], emptyArray()) - Type Parameters:
- E- the matcher type.
- Returns:
- The matcher.
 
- 
aMapWithSizepublic static <K,V> Matcher<Map<? extends K,? extends V>> aMapWithSize(Matcher<? super Integer> sizeMatcher) Creates a matcher forMaps that matches when thesize()method returns a value that satisfies the specified matcher. For example:assertThat(myMap, is(aMapWithSize(equalTo(2)))) - Type Parameters:
- K- the map key type.
- V- the map value type.
- Parameters:
- sizeMatcher- a matcher for the size of an examined- Map
- Returns:
- The matcher.
 
- 
aMapWithSizeCreates a matcher forMaps that matches when thesize()method returns a value equal to the specifiedsize. For example:assertThat(myMap, is(aMapWithSize(2))) - Type Parameters:
- K- the map key type.
- V- the map value type.
- Parameters:
- size- the expected size of an examined- Map
- Returns:
- The matcher.
 
- 
anEmptyMapCreates a matcher forMaps that matches when thesize()method returns zero. For example:assertThat(myMap, is(anEmptyMap())) - Type Parameters:
- K- the map key type.
- V- the map value type.
- Returns:
- The matcher.
 
- 
hasSizeCreates a matcher forCollections that matches when thesize()method returns a value that satisfies the specified matcher. For example:assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))- Type Parameters:
- E- the matcher type.
- Parameters:
- sizeMatcher- a matcher for the size of an examined- Collection
- Returns:
- The matcher.
 
- 
hasSizeCreates a matcher forCollections that matches when thesize()method returns a value equal to the specifiedsize. For example:assertThat(Arrays.asList("foo", "bar"), hasSize(2))- Type Parameters:
- E- the matcher type.
- Parameters:
- size- the expected size of an examined- Collection
- Returns:
- The matcher.
 
- 
emptyCreates a matcher forCollections matching examined collections whoseisEmptymethod returnstrue. For example:assertThat(new ArrayList<String>(), is(empty())) - Type Parameters:
- E- the matcher type.
- Returns:
- The matcher.
 
- 
emptyCollectionOfCreates a matcher forCollections matching examined collections whoseisEmptymethod returnstrue. For example:assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class))) - Type Parameters:
- E- the matcher type.
- Parameters:
- unusedToForceReturnType- the type of the collection's content
- Returns:
- The matcher.
 
- 
emptyIterableCreates a matcher forIterables matching examined iterables that yield no items. For example:assertThat(new ArrayList<String>(), is(emptyIterable())) - Type Parameters:
- E- the matcher type.
- Returns:
- The matcher.
 
- 
emptyIterableOfCreates a matcher forIterables matching examined iterables that yield no items. For example:assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class))) - Type Parameters:
- E- the matcher type.
- Parameters:
- unusedToForceReturnType- the type of the iterable's content
- Returns:
- The matcher.
 
- 
containsCreates a matcher forIterables that matches when a single pass over the examinedIterableyields 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"))- Type Parameters:
- E- the matcher type.
- Parameters:
- items- the items that must equal the items provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
containsCreates a matcher forIterables that matches when a single pass over the examinedIterableyields 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")))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatcher- the matcher that must be satisfied by the single item provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
contains@SafeVarargs public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers) Creates a matcher forIterables that matches when a single pass over the examinedIterableyields 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")))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- the matchers that must be satisfied by the items provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
containsCreates a matcher forIterables that matches when a single pass over the examinedIterableyields 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"))))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by the corresponding item provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
containsInAnyOrder@SafeVarargs public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers) Creates an order agnostic matcher for Iterables that matches when a single pass over the examinedIterableyields 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")))- Type Parameters:
- T- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by an item provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
containsInAnyOrderCreates an order agnostic matcher for Iterables that matches when a single pass over the examinedIterableyields 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"))- Type Parameters:
- T- the matcher type.
- Parameters:
- items- the items that must equal the items provided by an examined- Iterablein any order
- Returns:
- The matcher.
 
- 
containsInAnyOrderpublic static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers) Creates an order agnostic matcher for Iterables that matches when a single pass over the examinedIterableyields 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"))))- Type Parameters:
- T- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by an item provided by an examined- Iterable
- Returns:
- The matcher.
 
- 
containsInRelativeOrderCreates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that contains items logically equal to the corresponding item in the specified items, in the same relative order For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))- Type Parameters:
- E- the matcher type.
- Parameters:
- items- the items that must be contained within items provided by an examined- Iterablein the same relative order
- Returns:
- The matcher.
 
- 
containsInRelativeOrder@SafeVarargs public static <E> Matcher<Iterable<? extends E>> containsInRelativeOrder(Matcher<? super E>... itemMatchers) Creates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that each satisfying the corresponding matcher in the specified matchers, in the same relative order. For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- the matchers that must be satisfied by the items provided by an examined- Iterablein the same relative order
- Returns:
- The matcher.
 
- 
containsInRelativeOrderpublic static <E> Matcher<Iterable<? extends E>> containsInRelativeOrder(List<Matcher<? super E>> itemMatchers) Creates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that contains items satisfying the corresponding matcher in the specified list of matchers, in the same relative order. For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))- Type Parameters:
- E- the matcher type.
- Parameters:
- itemMatchers- a list of matchers, each of which must be satisfied by the items provided by an examined- Iterablein the same relative order
- Returns:
- The matcher.
 
- 
iterableWithSizeCreates a matcher forIterables that matches when a single pass over the examinedIterableyields an item count that satisfies the specified matcher. For example:assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))- Type Parameters:
- E- the matcher type.
- Parameters:
- sizeMatcher- a matcher for the number of items that should be yielded by an examined- Iterable
- Returns:
- The matcher.
 
- 
iterableWithSizeCreates a matcher forIterables that matches when a single pass over the examinedIterableyields an item count that is equal to the specifiedsizeargument. For example:assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))- Type Parameters:
- E- the matcher type.
- Parameters:
- size- the number of items that should be yielded by an examined- Iterable
- Returns:
- The matcher.
 
- 
hasEntrypublic static <K,V> Matcher<Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) Creates a matcher forMaps matching when the examinedMapcontains at least one entry whose key satisfies the specifiedkeyMatcherand whose value satisfies the specifiedvalueMatcher. For example:assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))- Type Parameters:
- K- the map key type.
- V- the map value type.
- Parameters:
- keyMatcher- the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
- valueMatcher- the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
- Returns:
- The matcher.
 
- 
hasEntryCreates a matcher forMaps matching when the examinedMapcontains at least one entry whose key equals the specifiedkeyand whose value equals the specifiedvalue. For example:assertThat(myMap, hasEntry("bar", "foo"))- Type Parameters:
- K- the map key type.
- V- the map value type.
- Parameters:
- key- the key that, in combination with the value, must be describe at least one entry
- value- the value that, in combination with the key, must be describe at least one entry
- Returns:
- The matcher.
 
- 
hasKeyCreates a matcher forMaps matching when the examinedMapcontains at least one key that satisfies the specified matcher. For example:assertThat(myMap, hasKey(equalTo("bar")))- Type Parameters:
- K- the map key type.
- Parameters:
- keyMatcher- the matcher that must be satisfied by at least one key
- Returns:
- The matcher.
 
- 
hasKeyCreates a matcher forMaps matching when the examinedMapcontains at least one key that is equal to the specified key. For example:assertThat(myMap, hasKey("bar"))- Type Parameters:
- K- the map key type.
- Parameters:
- key- the key that satisfying maps must contain
- Returns:
- The matcher.
 
- 
hasValueCreates a matcher forMaps matching when the examinedMapcontains at least one value that satisfies the specified valueMatcher. For example:assertThat(myMap, hasValue(equalTo("foo")))- Type Parameters:
- V- the value type.
- Parameters:
- valueMatcher- the matcher that must be satisfied by at least one value
- Returns:
- The matcher.
 
- 
hasValueCreates a matcher forMaps matching when the examinedMapcontains at least one value that is equal to the specified value. For example:assertThat(myMap, hasValue("foo"))- Type Parameters:
- V- the value type.
- Parameters:
- value- the value that satisfying maps must contain
- Returns:
- The matcher.
 
- 
inCreates a matcher that matches when the examined object is found within the specified collection. For example:assertThat("foo", is(in(Arrays.asList("bar", "foo"))))- Type Parameters:
- T- the matcher type.
- Parameters:
- collection- the collection in which matching items must be found
- Returns:
- The matcher.
 
- 
inCreates a matcher that matches when the examined object is found within the specified array. For example:assertThat("foo", is(in(new String[]{"bar", "foo"})))- Type Parameters:
- T- the matcher type.
- Parameters:
- elements- the array in which matching items must be found
- Returns:
- The matcher.
 
- 
isInDeprecated.use is(in(...)) insteadCreates a matcher that matches when the examined object is found within the specified collection. For example:assertThat("foo", isIn(Arrays.asList("bar", "foo")))- Type Parameters:
- T- the matcher type.
- Parameters:
- collection- the collection in which matching items must be found
- Returns:
- The matcher.
 
- 
isInDeprecated.use is(in(...)) insteadCreates a matcher that matches when the examined object is found within the specified array. For example:assertThat("foo", isIn(new String[]{"bar", "foo"}))- Type Parameters:
- T- the matcher type.
- Parameters:
- elements- the array in which matching items must be found
- Returns:
- The matcher.
 
- 
isOneOfDeprecated.use is(oneOf(...)) insteadCreates a matcher that matches when the examined object is equal to one of the specified elements. For example:assertThat("foo", isOneOf("bar", "foo"))- Type Parameters:
- T- the matcher type.
- Parameters:
- elements- the elements amongst which matching items will be found
- Returns:
- The matcher.
 
- 
oneOfCreates a matcher that matches when the examined object is equal to one of the specified elements. For example:assertThat("foo", is(oneOf("bar", "foo")))- Type Parameters:
- T- the matcher type.
- Parameters:
- elements- the elements amongst which matching items will be found
- Returns:
- The matcher.
 
- 
closeToCreates a matcher ofDoubles that matches when an examined double is equal to the specifiedoperand, within a range of +/-error. For example:assertThat(1.03, is(closeTo(1.0, 0.03))) - Parameters:
- operand- the expected value of matching doubles
- error- the delta (+/-) within which matches will be allowed
- Returns:
- The matcher.
 
- 
notANumberCreates a matcher ofDoubles that matches when an examined double is not a number. For example:assertThat(Double.NaN, is(notANumber())) - Returns:
- The matcher.
 
- 
closeToCreates a matcher ofBigDecimals that matches when an examined BigDecimal is equal to the specifiedoperand, within a range of +/-error. The comparison for equality is done by BigDecimalsBigDecimal.compareTo(java.math.BigDecimal)method. For example:assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))- Parameters:
- operand- the expected value of matching BigDecimals
- error- the delta (+/-) within which matches will be allowed
- Returns:
- The matcher.
 
- 
comparesEqualToCreates a matcher ofComparableobject that matches when the examined object is equal to the specified value, as reported by thecompareTomethod of the examined object. For example:assertThat(1, comparesEqualTo(1)) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value which, when passed to the compareTo method of the examined object, should return zero
- Returns:
- The matcher.
 
- 
greaterThanCreates a matcher ofComparableobject that matches when the examined object is greater than the specified value, as reported by thecompareTomethod of the examined object. For example:assertThat(2, greaterThan(1)) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value which, when passed to the compareTo method of the examined object, should return greater than zero
- Returns:
- The matcher.
 
- 
greaterThanOrEqualToCreates a matcher ofComparableobject that matches when the examined object is greater than or equal to the specified value, as reported by thecompareTomethod of the examined object. For example:assertThat(1, greaterThanOrEqualTo(1)) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value which, when passed to the compareTo method of the examined object, should return greater than or equal to zero
- Returns:
- The matcher.
 
- 
lessThanCreates a matcher ofComparableobject that matches when the examined object is less than the specified value, as reported by thecompareTomethod of the examined object. For example:assertThat(1, lessThan(2)) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value which, when passed to the compareTo method of the examined object, should return less than zero
- Returns:
- The matcher.
 
- 
lessThanOrEqualToCreates a matcher ofComparableobject that matches when the examined object is less than or equal to the specified value, as reported by thecompareTomethod of the examined object. For example:assertThat(1, lessThanOrEqualTo(1)) - Type Parameters:
- T- the matcher type.
- Parameters:
- value- the value which, when passed to the compareTo method of the examined object, should return less than or equal to zero
- Returns:
- The matcher.
 
- 
equalToIgnoringCaseCreates a matcher ofStringthat matches when the examined string is equal to the specified expectedString, ignoring case. For example:assertThat("Foo", equalToIgnoringCase("FOO"))- Parameters:
- expectedString- the expected value of matched strings
- Returns:
- The matcher.
 
- 
equalToIgnoringWhiteSpaceDeprecated.- Parameters:
- expectedString- the expected value of matched strings
- Returns:
- The matcher.
 
- 
equalToCompressingWhiteSpaceCreates a matcher ofStringthat 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
 assertThat(" my\tfoo bar ", equalToIgnoringWhiteSpace(" my foo bar"))- Parameters:
- expectedString- the expected value of matched strings
- Returns:
- The matcher.
 
- 
emptyOrNullStringCreates a matcher ofStringthat matches when the examined string isnull, or has zero length. For example:assertThat(((String)null), is(emptyOrNullString())) - Returns:
- The matcher.
 
- 
emptyStringCreates a matcher ofStringthat matches when the examined string has zero length. For example:assertThat("", is(emptyString()))- Returns:
- The matcher.
 
- 
isEmptyOrNullStringDeprecated.use is(emptyOrNullString()) insteadCreates a matcher ofStringthat matches when the examined string isnull, or has zero length. For example:assertThat(((String)null), isEmptyOrNullString()) - Returns:
- The matcher.
 
- 
isEmptyStringDeprecated.use is(emptyString()) insteadCreates a matcher ofStringthat matches when the examined string has zero length. For example:assertThat("", isEmptyString())- Returns:
- The matcher.
 
- 
blankOrNullStringCreates a matcher ofStringthat matches when the examined string isnull, or contains zero or more whitespace characters and nothing else. For example:assertThat(((String)null), is(blankOrNullString())) - Returns:
- The matcher.
 
- 
blankStringCreates a matcher ofStringthat matches when the examined string contains zero or more whitespace characters and nothing else. For example:assertThat(" ", is(blankString()))- Returns:
- The matcher.
 
- 
matchesPatternCreates a matcher ofStringthat matches when the examined string exactly matches the givenPattern.- Parameters:
- pattern- the text pattern to match.
- Returns:
- The matcher.
 
- 
matchesPatternCreates a matcher ofStringthat matches when the examined string exactly matches the given regular expression, treated as aPattern.- Parameters:
- regex- the regex to match.
- Returns:
- The matcher.
 
- 
stringContainsInOrderCreates a matcher ofStringthat matches when the examined string contains all of the specified substrings, considering the order of their appearance. For example:assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))fails as "foo" occurs before "bar" in the string "myfoobarbaz"- Parameters:
- substrings- the substrings that must be contained within matching strings
- Returns:
- The matcher.
 
- 
stringContainsInOrderCreates a matcher ofStringthat matches when the examined string contains all of the specified substrings, considering the order of their appearance. For example:assertThat("myfoobarbaz", stringContainsInOrder("bar", "foo"))fails as "foo" occurs before "bar" in the string "myfoobarbaz"- Parameters:
- substrings- the substrings that must be contained within matching strings
- Returns:
- The matcher.
 
- 
hasLengthCreates a matcher ofCharSequencethat matches when a char sequence has the length that satisfies the specified matcher. For example:assertThat("text", hasLength(lessThan(4)))- Parameters:
- lengthMatcher- a matcher for the expected length of the string
- Returns:
- The matcher.
 
- 
hasLengthCreates a matcher ofCharSequencethat matches when a char sequence has the length of the specifiedargument. For example:assertThat("text", length(4))- Parameters:
- length- the expected length of the string
- Returns:
- The matcher.
 
- 
hasToStringCreates a matcher that matches any examined object whosetoStringmethod returns a value that satisfies the specified matcher. For example:assertThat(true, hasToString(equalTo("TRUE")))- Type Parameters:
- T- the matcher type.
- Parameters:
- toStringMatcher- the matcher used to verify the toString result
- Returns:
- The matcher.
 
- 
hasToStringCreates a matcher that matches any examined object whosetoStringmethod returns a value equalTo the specified string. For example:assertThat(true, hasToString("TRUE"))- Type Parameters:
- T- the matcher type.
- Parameters:
- expectedToString- the expected toString result
- Returns:
- The matcher.
 
- 
typeCompatibleWithCreates a matcher ofClassthat matches when the specified baseType is assignable from the examined class. For example:assertThat(Integer.class, typeCompatibleWith(Number.class)) - Type Parameters:
- T- the matcher type.
- Parameters:
- baseType- the base class to examine classes against
- Returns:
- The matcher.
 
- 
eventFrompublic static Matcher<EventObject> eventFrom(Class<? extends EventObject> eventClass, Object source) Creates a matcher ofEventObjectthat matches any object derived from eventClass announced by source. For example:assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean))) - Parameters:
- eventClass- the class of the event to match on
- source- the source of the event
- Returns:
- The matcher.
 
- 
eventFromCreates a matcher ofEventObjectthat matches any EventObject announced by source. For example:assertThat(myEvent, is(eventFrom(myBean))) - Parameters:
- source- the source of the event
- Returns:
- The matcher.
 
- 
hasPropertyCreates a matcher that matches when the examined object has a JavaBean property with the specified name. For example:assertThat(myBean, hasProperty("foo"))- Type Parameters:
- T- the matcher type.
- Parameters:
- propertyName- the name of the JavaBean property that examined beans should possess
- Returns:
- The matcher.
 
- 
hasPropertyCreates 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"))- Type Parameters:
- T- the matcher type.
- Parameters:
- propertyName- the name of the JavaBean property that examined beans should possess
- valueMatcher- a matcher for the value of the specified property of the examined bean
- Returns:
- The matcher.
 
- 
samePropertyValuesAsCreates 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. If any properties are marked as ignored, they will be dropped from both the expected and actual bean. Note that the ignored properties use JavaBean display names, for exampleage rather than method names such asgetAge . For example:assertThat(myBean, samePropertyValuesAs(myExpectedBean)) assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height") - Type Parameters:
- B- the matcher type.
- Parameters:
- expectedBean- the bean against which examined beans are compared
- ignoredProperties- do not check any of these named properties.
- Returns:
- The matcher.
 
- 
hasXPathCreates a matcher ofNodes that matches when the examined node has a value at the specifiedxPaththat satisfies the specifiedvalueMatcher. For example:assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))- Parameters:
- xPath- the target xpath
- valueMatcher- matcher for the value at the specified xpath
- Returns:
- The matcher.
 
- 
hasXPathpublic static Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<String> valueMatcher) Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPath, within the specifiednamespaceContext, that satisfies the specifiedvalueMatcher. For example:assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))- Parameters:
- xPath- the target xpath
- namespaceContext- the namespace for matching nodes
- valueMatcher- matcher for the value at the specified xpath
- Returns:
- The matcher.
 
- 
hasXPathCreates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPath, with any content. For example:assertThat(xml, hasXPath("/root/something[2]/cheese"))- Parameters:
- xPath- the target xpath
- Returns:
- The matcher.
 
- 
hasXPathCreates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPathwithin the specified namespace context, with any content. For example:assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))- Parameters:
- xPath- the target xpath
- namespaceContext- the namespace for matching nodes
- Returns:
- The matcher.
 
 
- 
equalToCompressingWhiteSpace(String)