diff --git a/docs/javadoc/2.1/allclasses-frame.html b/docs/javadoc/2.1/allclasses-frame.html new file mode 100644 index 00000000..e92aacf7 --- /dev/null +++ b/docs/javadoc/2.1/allclasses-frame.html @@ -0,0 +1,102 @@ + + + +
+ +Class and Description | +
---|
org.hamcrest.collection.IsArrayContainingInAnyOrder
+ As of release 2.1, replaced by
+ArrayMatching . |
+
org.hamcrest.collection.IsArrayContainingInOrder
+ As of release 2.1, replaced by
+ArrayMatching . |
+
org.hamcrest.core.IsCollectionContaining
+ As of release 2.1, replaced by
+IsIterableContaining . |
+
The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+Each annotation type has its own separate page with the following sections:
+Each enum has its own separate page with the following sections:
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object
. The interfaces do not inherit from java.lang.Object
.
The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+These links take you to the next or previous class, interface, package, or related page.
+These links show and hide the HTML frames. All pages are available with or without frames.
+The All Classes link shows all classes and interfaces except non-static nested types.
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+The Constant Field Values page lists the static final fields and their values.
+Map
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.Map
s that matches when the size()
method returns
+ a value equal to the specified size
.Map
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.Map
s that matches when the size()
method returns
+ a value equal to the specified size
.Map
s that matches when the size()
method returns
+ zero.Map
s that matches when the size()
method returns
+ zero.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.String
.String
.String
.SelfDescribing
value to this description.SelfDescribing
objects
+ to the description.ArrayMatching.arrayContaining(Object[])
.ArrayMatching.arrayContaining(Matcher[])
.ArrayMatching.arrayContaining(List)
.ArrayMatching.arrayContainingInAnyOrder(Matcher[])
.ArrayMatching.arrayContainingInAnyOrder(Collection)
.ArrayMatching.arrayContainingInAnyOrder(Object[])
.length
of the array
+ satisfies the specified matcher.length
of the array
+ equals the specified size
.length
of the array
+ satisfies the specified matcher.length
of the array
+ equals the specified size
.StringDescription.toString(SelfDescribing)
.Description
that is stored as a string.String
that matches when the examined string is null
, or
+ contains zero or more whitespace characters and nothing else.String
that matches when the examined string is null
, or
+ contains zero or more whitespace characters and nothing else.String
that matches when the examined string contains
+ zero or more whitespace characters and nothing else.String
that matches when the examined string contains
+ zero or more whitespace characters and nothing else.Double
s that matches when an examined double is equal
+ to the specified operand
, within a range of +/- error
.BigDecimal
s that matches when an examined BigDecimal is equal
+ to the specified operand
, within a range of +/- error
.BigDecimal
s that matches when an examined BigDecimal is equal
+ to the specified operand
, within a range of +/- error
.Double
s that matches when an examined double is equal
+ to the specified operand
, within a range of +/- error
.Comparators
s of T
.T
object that matches when the examined object is
+ equal to the specified value, as reported by the Comparator
used to
+ create this builder.Comparable
object that matches when the examined object is
+ equal to the specified value, as reported by the compareTo
method of the
+ examined object.Comparable
object that matches when the examined object is
+ equal to the specified value, as reported by the compareTo
method of the
+ examined object.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each logically equal to the
+ corresponding item in the specified items.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a single item that satisfies the specified matcher.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified matchers.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each logically equal to the
+ corresponding item in the specified items.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a single item that satisfies the specified matcher.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified matchers.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified matchers.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each logically equal to one item
+ anywhere in the specified items.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified matchers.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each logically equal to one item
+ anywhere in the specified items.Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that contains items logically equal to the
+ corresponding item in the specified items, in the same relative order
+ For example:Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that each satisfying the corresponding
+ matcher in the specified matchers, in the same relative order.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that contains items satisfying the corresponding
+ matcher in the specified list of matchers, in the same relative order.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that contains items logically equal to the
+ corresponding item in the specified items, in the same relative order
+ For example:Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that each satisfying the corresponding
+ matcher in the specified matchers, in the same relative order.Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, that contains items satisfying the corresponding
+ matcher in the specified list of matchers, in the same relative order.String
contains the specified
+ String
anywhere.String
contains the specified
+ String
anywhere.String
contains the specified
+ String
anywhere.String
contains the specified
+ String
anywhere, ignoring case.String
contains the specified
+ String
anywhere, ignoring case.String
contains the specified
+ String
anywhere, ignoring case.Collection
s matching examined collections whose isEmpty
+ method returns true
.Collection
s matching examined collections whose isEmpty
+ method returns true
.length
of the array
+ is zero.length
of the array
+ is zero.Collection
s matching examined collections whose isEmpty
+ method returns true
.Collection
s matching examined collections whose isEmpty
+ method returns true
.Iterable
s matching examined iterables that yield no items.Iterable
s matching examined iterables that yield no items.Iterable
s matching examined iterables that yield no items.Iterable
s matching examined iterables that yield no items.String
that matches when the examined string is null
, or
+ has zero length.String
that matches when the examined string is null
, or
+ has zero length.String
that matches when the examined string has zero length.String
that matches when the examined string has zero length.String
ends with the specified
+ String
.String
ends with the specified
+ String
.String
ends with the specified
+ String
.String
ends with the specified
+ String
, ignoring case.String
ends with the specified
+ String
, ignoring case.String
ends with the specified
+ String
, ignoring case.operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.String
that matches when the examined string is equal to
+ the specified expectedString, when whitespace differences are (mostly) ignored.String
that matches when the examined string is equal to
+ the specified expectedString, when whitespace differences are (mostly) ignored.String
that matches when the examined string is equal to
+ the specified expectedString, ignoring case.String
that matches when the examined string is equal to
+ the specified expectedString, ignoring case.IsEqual
matcher that does not enforce the values being
+ compared to be of the same static type.IsEqual
matcher that does not enforce the values being
+ compared to be of the same static type.IsEqual
matcher that does not enforce the values being
+ compared to be of the same static type.EventObject
that matches any object
+ derived from eventClass announced by source.EventObject
that matches any EventObject
+ announced by source.EventObject
that matches any object
+ derived from eventClass announced by source.EventObject
that matches any EventObject
+ announced by source.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.T
object that matches when the examined object is
+ greater than the specified value, as reported by the Comparator
used to
+ create this builder.Comparable
object that matches when the examined object is
+ greater than the specified value, as reported by the compareTo
method of the
+ examined object.Comparable
object that matches when the examined object is
+ greater than the specified value, as reported by the compareTo
method of the
+ examined object.T
object that matches when the examined object is
+ greater than or equal to the specified value, as reported by the Comparator
used to
+ create this builder.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.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.Map
s matching when the examined Map
contains
+ at least one entry whose key satisfies the specified keyMatcher
and whose
+ value satisfies the specified valueMatcher
.Map
s matching when the examined Map
contains
+ at least one entry whose key equals the specified key
and whose value equals the
+ specified value
.Map
s matching when the examined Map
contains
+ at least one entry whose key satisfies the specified keyMatcher
and whose
+ value satisfies the specified valueMatcher
.Map
s matching when the examined Map
contains
+ at least one entry whose key equals the specified key
and whose value equals the
+ specified value
.IsIterableContaining.hasItem(Matcher)
.IsIterableContaining.hasItem(Object)
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
.elementMatcher
.hasItemInArray(equalTo(x))
.elementMatcher
.hasItemInArray(equalTo(x))
.IsIterableContaining.hasItems(Matcher[])
}.IsIterableContaining.hasItems(Object[])
}.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
.Map
s matching when the examined Map
contains
+ at least one key that satisfies the specified matcher.Map
s matching when the examined Map
contains
+ at least one key that is equal to the specified key.Map
s matching when the examined Map
contains
+ at least one key that satisfies the specified matcher.Map
s matching when the examined Map
contains
+ at least one key that is equal to the specified key.CharSequence
that matches when a char sequence has the length
+ of the specified argument
.CharSequence
that matches when a char sequence has the given length
+ For example:CharSequence
that matches when a char sequence has the given length
+ For example:Collection
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.Collection
s that matches when the size()
method returns
+ a value equal to the specified size
.Collection
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.Collection
s that matches when the size()
method returns
+ a value equal to the specified size
.toString
method
+ returns a value that satisfies the specified matcher.toString
method
+ returns a value equalTo the specified string.toString
method
+ returns a value that satisfies the specified matcher.toString
method
+ returns a value equalTo the specified string.Map
s matching when the examined Map
contains
+ at least one value that satisfies the specified valueMatcher.Map
s matching when the examined Map
contains
+ at least one value that is equal to the specified value.Map
s matching when the examined Map
contains
+ at least one value that satisfies the specified valueMatcher.Map
s matching when the examined Map
contains
+ at least one value that is equal to the specified value.Node
s that matches when the examined node has a value at the
+ specified xPath
that satisfies the specified valueMatcher
.Node
s that matches when the examined node has a value at the
+ specified xPath
, within the specified namespaceContext
, that satisfies
+ the specified valueMatcher
.Node
s that matches when the examined node contains a node
+ at the specified xPath
, with any content.Node
s that matches when the examined node contains a node
+ at the specified xPath
within the specified namespace context, with any content.Node
s that matches when the examined node has a value at the
+ specified xPath
that satisfies the specified valueMatcher
.Node
s that matches when the examined node has a value at the
+ specified xPath
, within the specified namespaceContext
, that satisfies
+ the specified valueMatcher
.Node
s that matches when the examined node contains a node
+ at the specified xPath
, with any content.Node
s that matches when the examined node contains a node
+ at the specified xPath
within the specified namespace context, with any content.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.is(equalTo(x))
.is(equalTo(x))
.is(equalTo(x))
.is(instanceOf(SomeClass.class))
.is(instanceOf(SomeClass.class))
.is(instanceOf(SomeClass.class))
.true
.ArrayMatching
.ArrayMatching
.IsIterableContaining
.Object.equals(java.lang.Object)
invokedMethod?Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that satisfies the specified
+ matcher.Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that is equal to the specified
+ size
argument.Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that satisfies the specified
+ matcher.Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that is equal to the specified
+ size
argument.T
object that matches when the examined object is
+ less than the specified value, as reported by the Comparator
used to
+ create this builder.Comparable
object that matches when the examined object is
+ less than the specified value, as reported by the compareTo
method of the
+ examined object.Comparable
object that matches when the examined object is
+ less than the specified value, as reported by the compareTo
method of the
+ examined object.T
object that matches when the examined object is
+ less than or equal to the specified value, as reported by the Comparator
used to
+ create this builder.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.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.String
that matches when the examined string
+ exactly matches the given Pattern
.String
that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern
.String
that matches when the examined string
+ exactly matches the given Pattern
.String
that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern
.Pattern
.Pattern
.not(equalTo(x))
.not(equalTo(x))
.not(equalTo(x))
.Double
s that matches when an examined double is not a number.Double
s that matches when an examined double is not a number.not(nullValue())
.not(nullValue(X.class)).
not(nullValue())
.not(nullValue(X.class)).
not(nullValue())
.not(nullValue(X.class)).
null
.null
.null
.null
.null
.null
.String
starts with the specified
+ String
.String
starts with the specified
+ String
.String
starts with the specified
+ String
.String
starts with the specified
+ String
, ignoring caseString
starts with the specified
+ String
, ignoring caseString
starts with the specified
+ String
, ignoring caseString
that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance.String
that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance.String
that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance.String
that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance.Description
that is stored as a string.SelfDescribing
object as a String.Class
that matches when the specified baseType is
+ assignable from the examined class.Class
that matches when the specified baseType is
+ assignable from the examined class.matchesSafely
+ is not the class that binds <T> to a type.matchesSafely
+ is not the class that binds <T> to a type.matchesSafely
+ is not the class that binds <T> to a type.matchesSafely
+ is not the class that binds <T> to a type.Comparable
s.public abstract class BaseDescription +extends java.lang.Object +implements Description+
Description
that is stored as a string.Description.NullDescription
NONE
Constructor and Description | +
---|
BaseDescription() |
+
Modifier and Type | +Method and Description | +
---|---|
protected abstract void |
+append(char c)
+Append the char c to the description.
+ |
+
protected void |
+append(java.lang.String str)
+Append the String str to the description.
+ |
+
Description |
+appendDescriptionOf(SelfDescribing value)
+Appends the description of a
+SelfDescribing value to this description. |
+
Description |
+appendList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<? extends SelfDescribing> values)
+Appends a list of
+SelfDescribing objects
+ to the description. |
+
Description |
+appendText(java.lang.String text)
+Appends some plain text to the description.
+ |
+
Description |
+appendValue(java.lang.Object value)
+Appends an arbitrary value to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<T> values)
+Appends a list of values to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ T... values)
+Appends a list of values to the description.
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public Description appendText(java.lang.String text)+
Description
appendText
in interface Description
public Description appendDescriptionOf(SelfDescribing value)+
Description
SelfDescribing
value to this description.appendDescriptionOf
in interface Description
public Description appendValue(java.lang.Object value)+
Description
appendValue
in interface Description
@SafeVarargs +public final <T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + T... values)+
Description
appendValueList
in interface Description
public <T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<T> values)+
Description
appendValueList
in interface Description
public Description appendList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<? extends SelfDescribing> values)+
Description
SelfDescribing
objects
+ to the description.appendList
in interface Description
protected void append(java.lang.String str)+
append(char)
.
+ Override in subclasses to provide an efficient implementation.protected abstract void append(char c)+
public abstract class BaseMatcher<T> +extends java.lang.Object +implements Matcher<T>+
Matcher
Constructor and Description | +
---|
BaseMatcher() |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+_dont_implement_Matcher___instead_extend_BaseMatcher_()
+Deprecated.
+ |
+
void |
+describeMismatch(java.lang.Object item,
+ Description description)
+Generate a description of why the matcher has not accepted the item.
+ |
+
protected static boolean |
+isNotNull(java.lang.Object actual,
+ Description mismatch)
+Useful null-check method.
+ |
+
java.lang.String |
+toString() |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
describeTo
@Deprecated +public final void _dont_implement_Matcher___instead_extend_BaseMatcher_()+
Matcher
_dont_implement_Matcher___instead_extend_BaseMatcher_
in interface Matcher<T>
Matcher._dont_implement_Matcher___instead_extend_BaseMatcher_()
public void describeMismatch(java.lang.Object item, + Description description)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
item
- The item that the Matcher has rejected.description
- The description to be built or appended to.public java.lang.String toString()+
toString
in class java.lang.Object
protected static boolean isNotNull(java.lang.Object actual, + Description mismatch)+
actual
- the object to checkmismatch
- where to write the mismatch description, if anyModifier and Type | +Method and Description | +
---|---|
Condition<O> |
+apply(I value,
+ Description mismatch) |
+
public abstract class Condition<T>
+extends java.lang.Object
+Modifier and Type | +Class and Description | +
---|---|
static interface |
+Condition.Step<I,O> |
+
Modifier and Type | +Field and Description | +
---|---|
static org.hamcrest.Condition.NotMatched<java.lang.Object> |
+NOT_MATCHED |
+
Modifier and Type | +Method and Description | +
---|---|
abstract <U> Condition<U> |
+and(Condition.Step<? super T,U> mapping) |
+
static <T> Condition<T> |
+matched(T theValue,
+ Description mismatch) |
+
boolean |
+matching(Matcher<T> match) |
+
abstract boolean |
+matching(Matcher<T> match,
+ java.lang.String message) |
+
static <T> Condition<T> |
+notMatched() |
+
<U> Condition<U> |
+then(Condition.Step<? super T,U> mapping) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final org.hamcrest.Condition.NotMatched<java.lang.Object> NOT_MATCHED+
public abstract <U> Condition<U> and(Condition.Step<? super T,U> mapping)+
public final <U> Condition<U> then(Condition.Step<? super T,U> mapping)+
public static <T> Condition<T> notMatched()+
public static <T> Condition<T> matched(T theValue, + Description mismatch)+
public class CoreMatchers
+extends java.lang.Object
+Constructor and Description | +
---|
CoreMatchers() |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<T> |
+allOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ALL of the specified matchers.
+ |
+
static <T> Matcher<T> |
+allOf(Matcher<? super T>... matchers)
+Creates a matcher that matches if the examined object matches ALL of the specified matchers.
+ |
+
static <T> Matcher<T> |
+any(java.lang.Class<T> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
static <T> AnyOf<T> |
+anyOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<? super T>... matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static Matcher<java.lang.Object> |
+anything()
+Creates a matcher that always matches, regardless of the examined object.
+ |
+
static Matcher<java.lang.Object> |
+anything(java.lang.String description)
+Creates a matcher that always matches, regardless of the examined object, but describes
+ itself with the specified
+String . |
+
static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> |
+both(Matcher<? super LHS> matcher)
+Creates a matcher that matches when both of the specified matchers match the examined object.
+ |
+
static Matcher<java.lang.String> |
+containsString(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere. |
+
static Matcher<java.lang.String> |
+containsStringIgnoringCase(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere, ignoring case. |
+
static <T> Matcher<T> |
+describedAs(java.lang.String description,
+ Matcher<T> matcher,
+ java.lang.Object... values)
+Wraps an existing matcher, overriding its description with that specified.
+ |
+
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.
+ |
+
static Matcher<java.lang.String> |
+endsWith(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String . |
+
static Matcher<java.lang.String> |
+endsWithIgnoringCase(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String , ignoring case. |
+
static <T> Matcher<T> |
+equalTo(T operand)
+Creates a matcher that matches when the examined object is logically equal to the specified
+
+operand , as determined by calling the Object.equals(java.lang.Object) method on
+ the examined object. |
+
static Matcher<java.lang.Object> |
+equalToObject(java.lang.Object operand)
+Creates an
+IsEqual matcher that does not enforce the values being
+ compared to be of the same static type. |
+
static <U> Matcher<java.lang.Iterable<? extends U>> |
+everyItem(Matcher<U> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields items that are all matched by the specified
+ itemMatcher . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(Matcher<? super T> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is matched by the specified
+ itemMatcher . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(T item)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is equal to the specified
+ item . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(Matcher<? super T>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(T... items)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is equal to the corresponding
+ item from the specified items . |
+
static <T> Matcher<T> |
+instanceOf(java.lang.Class<?> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
static <T> Matcher<T> |
+is(Matcher<T> matcher)
+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 used
+is(equalTo(x)) . |
+
static <T> Matcher<T> |
+isA(java.lang.Class<T> type)
+A shortcut to the frequently used
+is(instanceOf(SomeClass.class)) . |
+
static <T> Matcher<T> |
+not(Matcher<T> matcher)
+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 used
+not(equalTo(x)) . |
+
static Matcher<java.lang.Object> |
+notNullValue()
+A shortcut to the frequently used
+not(nullValue()) . |
+
static <T> Matcher<T> |
+notNullValue(java.lang.Class<T> type)
+A shortcut to the frequently used
+not(nullValue(X.class)). |
+
static Matcher<java.lang.Object> |
+nullValue()
+Creates a matcher that matches if examined object is
+null . |
+
static <T> Matcher<T> |
+nullValue(java.lang.Class<T> type)
+Creates a matcher that matches if examined object is
+null . |
+
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 Matcher<java.lang.String> |
+startsWith(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String . |
+
static Matcher<java.lang.String> |
+startsWithIgnoringCase(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String , ignoring case |
+
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.
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T> Matcher<T> allOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
@SafeVarargs +public static <T> Matcher<T> allOf(Matcher<? super T>... matchers)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> AnyOf<T> anyOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
@SafeVarargs +public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher)+
assertThat("fab", both(containsString("a")).and(containsString("b")))
public static <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher)+
assertThat("fan", either(containsString("a")).or(containsString("b")))
public static <T> Matcher<T> describedAs(java.lang.String description, + Matcher<T> matcher, + java.lang.Object... values)+
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
description
- the new description for the wrapped matchermatcher
- the matcher to wrapvalues
- optional values to insert into the tokenised descriptionpublic static <U> Matcher<java.lang.Iterable<? extends U>> everyItem(Matcher<U> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.
+ For example:
+ assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
itemMatcher
- the matcher to apply to every item provided by the examined Iterable
public static <T> Matcher<T> is(Matcher<T> matcher)+
assertThat(cheese, is(equalTo(smelly)))+ instead of: +
assertThat(cheese, equalTo(smelly))
public static <T> Matcher<T> is(T value)+
is(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(smelly))+ instead of: +
assertThat(cheese, is(equalTo(smelly)))
public static <T> Matcher<T> isA(java.lang.Class<T> type)+
is(instanceOf(SomeClass.class))
.
+ For example:
+ assertThat(cheese, isA(Cheddar.class))+ instead of: +
assertThat(cheese, is(instanceOf(Cheddar.class)))
public static Matcher<java.lang.Object> anything()+
public static Matcher<java.lang.Object> anything(java.lang.String description)+
String
.description
- a meaningful String
used when describing itselfpublic static <T> Matcher<java.lang.Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
itemMatcher
- the matcher to apply to items provided by the examined Iterable
public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(T item)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
item
- the item to compare against the items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(Matcher<? super T>... itemMatchers)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
. Whilst matching, each traversal of
+ the examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
itemMatchers
- the matchers to apply to items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(T... items)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
. Whilst matching, each traversal of the
+ examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
items
- the items to compare against the items provided by the examined Iterable
public static <T> Matcher<T> equalTo(T operand)+
operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.
+
+ If the specified operand is null
then the created matcher will only match if
+ the examined object's equals
method returns true
when passed a
+ null
(which would be a violation of the equals
contract), unless the
+ examined object itself is null
, in which case the matcher will return a positive
+ match.
The created matcher provides a special behaviour when examining Array
s, whereby
+ it will match if both the operand and the examined object are arrays of the same length and
+ contain items that are equal to each other (according to the above rules) in the same
+ indexes.
+ assertThat("foo", equalTo("foo")); + assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"})); +
public static Matcher<java.lang.Object> equalToObject(java.lang.Object operand)+
IsEqual
matcher that does not enforce the values being
+ compared to be of the same static type.public static <T> Matcher<T> any(java.lang.Class<T> type)+
type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.
+
+ The created matcher forces a relationship between specified type and the examined object, and should be
+ used when it is necessary to make generics conform, for example in the JMock clause
+ with(any(Thing.class))
assertThat(new Canoe(), instanceOf(Canoe.class));
public static <T> Matcher<T> instanceOf(java.lang.Class<?> type)+
type
,
+ as determined by calling the 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 <T> Matcher<T> not(Matcher<T> matcher)+
assertThat(cheese, is(not(equalTo(smelly))))
matcher
- the matcher whose sense should be invertedpublic static <T> Matcher<T> not(T value)+
not(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(not(smelly)))+ instead of: +
assertThat(cheese, is(not(equalTo(smelly))))
value
- the value that any examined object should not equalpublic static Matcher<java.lang.Object> notNullValue()+
not(nullValue())
.
+ For example:
+ assertThat(cheese, is(notNullValue()))+ instead of: +
assertThat(cheese, is(not(nullValue())))
public static <T> Matcher<T> notNullValue(java.lang.Class<T> type)+
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))))
type
- dummy parameter used to infer the generic type of the returned matcherpublic static Matcher<java.lang.Object> nullValue()+
null
.
+ For example:
+ assertThat(cheese, is(nullValue())
public static <T> Matcher<T> nullValue(java.lang.Class<T> type)+
null
. Accepts a
+ single dummy argument to facilitate type inference.
+ For example:
+ assertThat(cheese, is(nullValue(Cheese.class))
type
- dummy parameter used to infer the generic type of the returned matcherpublic static <T> Matcher<T> sameInstance(T target)+
target
- the target instance against which others should be assessedpublic static <T> Matcher<T> theInstance(T target)+
target
- the target instance against which others should be assessedpublic static Matcher<java.lang.String> containsString(java.lang.String substring)+
String
contains the specified
+ String
anywhere.
+ For example:
+ assertThat("myStringOfNote", containsString("ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic static Matcher<java.lang.String> containsStringIgnoringCase(java.lang.String substring)+
String
contains the specified
+ String
anywhere, ignoring case.
+ For example:
+ assertThat("myStringOfNote", containsString("ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic static Matcher<java.lang.String> startsWith(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
.
+
assertThat("myStringOfNote", startsWith("my"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic static Matcher<java.lang.String> startsWithIgnoringCase(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
, ignoring case
+
assertThat("myStringOfNote", startsWith("my"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic static Matcher<java.lang.String> endsWith(java.lang.String suffix)+
String
ends with the specified
+ String
.
+ For example:
+ assertThat("myStringOfNote", endsWith("Note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringpublic static Matcher<java.lang.String> endsWithIgnoringCase(java.lang.String suffix)+
String
ends with the specified
+ String
, ignoring case.
+ For example:
+ assertThat("myStringOfNote", endsWith("Note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringT
- The type of object being matched.public abstract class CustomMatcher<T> +extends BaseMatcher<T>+
+ Matcher<String> aNonEmptyString = new CustomMatcher<String>("a non empty string") { + public boolean matches(Object object) { + return ((object instanceof String) && !((String) object).isEmpty(); + } + }; ++
+ This class is designed for scenarios where an anonymous inner class + matcher makes sense. It should not be used by API designers implementing + matchers.
Constructor and Description | +
---|
CustomMatcher(java.lang.String description) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public CustomMatcher(java.lang.String description)+
public final void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.T
- The type of object being matchedpublic abstract class CustomTypeSafeMatcher<T> +extends TypeSafeMatcher<T>+
+ Matcher<String> aNonEmptyString = new CustomTypeSafeMatcher<String>("a non empty string") { + public boolean matchesSafely(String string) { + return !string.isEmpty(); + } + public void describeMismatchSafely(String string, Description mismatchDescription) { + mismatchDescription.appendText("was empty"); + } + }; ++ This is a variant of
CustomMatcher
that first type checks
+ the argument being matched. By the time TypeSafeMatcher.matchesSafely(T)
is
+ is called the argument is guaranteed to be non-null and of the correct
+ type.Constructor and Description | +
---|
CustomTypeSafeMatcher(java.lang.String description) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
describeMismatch, describeMismatchSafely, matches, matchesSafely
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public CustomTypeSafeMatcher(java.lang.String description)+
public final void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static final class Description.NullDescription +extends java.lang.Object +implements Description+
Description.NullDescription
NONE
Constructor and Description | +
---|
NullDescription() |
+
Modifier and Type | +Method and Description | +
---|---|
Description |
+appendDescriptionOf(SelfDescribing value)
+Appends the description of a
+SelfDescribing value to this description. |
+
Description |
+appendList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<? extends SelfDescribing> values)
+Appends a list of
+SelfDescribing objects
+ to the description. |
+
Description |
+appendText(java.lang.String text)
+Appends some plain text to the description.
+ |
+
Description |
+appendValue(java.lang.Object value)
+Appends an arbitrary value to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<T> values)
+Appends a list of values to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ T... values)
+Appends a list of values to the description.
+ |
+
java.lang.String |
+toString() |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public Description appendDescriptionOf(SelfDescribing value)+
Description
SelfDescribing
value to this description.appendDescriptionOf
in interface Description
public Description appendList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<? extends SelfDescribing> values)+
Description
SelfDescribing
objects
+ to the description.appendList
in interface Description
public Description appendText(java.lang.String text)+
Description
appendText
in interface Description
public Description appendValue(java.lang.Object value)+
Description
appendValue
in interface Description
public <T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + T... values)+
Description
appendValueList
in interface Description
public <T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<T> values)+
Description
appendValueList
in interface Description
public java.lang.String toString()+
toString
in class java.lang.Object
public interface Description
+SelfDescribing.describeTo(Description)
Modifier and Type | +Interface and Description | +
---|---|
static class |
+Description.NullDescription |
+
Modifier and Type | +Field and Description | +
---|---|
static Description |
+NONE
+A description that consumes input but does nothing.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
Description |
+appendDescriptionOf(SelfDescribing value)
+Appends the description of a
+SelfDescribing value to this description. |
+
Description |
+appendList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<? extends SelfDescribing> values)
+Appends a list of
+SelfDescribing objects
+ to the description. |
+
Description |
+appendText(java.lang.String text)
+Appends some plain text to the description.
+ |
+
Description |
+appendValue(java.lang.Object value)
+Appends an arbitrary value to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ java.lang.Iterable<T> values)
+Appends a list of values to the description.
+ |
+
<T> Description |
+appendValueList(java.lang.String start,
+ java.lang.String separator,
+ java.lang.String end,
+ T... values)
+Appends a list of values to the description.
+ |
+
static final Description NONE+
Description appendText(java.lang.String text)+
Description appendDescriptionOf(SelfDescribing value)+
SelfDescribing
value to this description.Description appendValue(java.lang.Object value)+
<T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + T... values)+
<T> Description appendValueList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<T> values)+
Description appendList(java.lang.String start, + java.lang.String separator, + java.lang.String end, + java.lang.Iterable<? extends SelfDescribing> values)+
SelfDescribing
objects
+ to the description.T
- public abstract class DiagnosingMatcher<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
DiagnosingMatcher() |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatch(java.lang.Object item,
+ Description mismatchDescription)
+Generate a description of why the matcher has not accepted the item.
+ |
+
boolean |
+matches(java.lang.Object item)
+Evaluates the matcher for argument item.
+ |
+
protected abstract boolean |
+matches(java.lang.Object item,
+ Description mismatchDescription) |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
describeTo
public final boolean matches(java.lang.Object item)+
Matcher
item
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public final void describeMismatch(java.lang.Object item, + Description mismatchDescription)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
describeMismatch
in class BaseMatcher<T>
item
- The item that the Matcher has rejected.mismatchDescription
- The description to be built or appended to.protected abstract boolean matches(java.lang.Object item, + Description mismatchDescription)+
T
- The type of the object to be matchedU
- The type of the feature to be matchedpublic abstract class FeatureMatcher<T,U> +extends TypeSafeDiagnosingMatcher<T>+
featureValueOf()
+ in a subclass to pull out the feature to be matched against.Constructor and Description | +
---|
FeatureMatcher(Matcher<? super U> subMatcher,
+ java.lang.String featureDescription,
+ java.lang.String featureName)
+Constructor
+ |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected abstract U |
+featureValueOf(T actual)
+Implement this to extract the interesting feature.
+ |
+
protected boolean |
+matchesSafely(T actual,
+ Description mismatch)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public FeatureMatcher(Matcher<? super U> subMatcher, + java.lang.String featureDescription, + java.lang.String featureName)+
subMatcher
- The matcher to apply to the featurefeatureDescription
- Descriptive text to use in describeTofeatureName
- Identifying text for mismatch messageprotected abstract U featureValueOf(T actual)+
actual
- the target objectprotected boolean matchesSafely(T actual, + Description mismatch)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<T>
public final void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public interface Matcher<T> +extends SelfDescribing+
+ A matcher over acceptable values. + A matcher is able to describe itself to give feedback when it fails. +
+
+ Matcher implementations should NOT directly implement this interface.
+ Instead, extend the BaseMatcher
abstract class,
+ which will ensure that the Matcher API can grow to support
+ new features and remain compatible with all Matcher implementations.
+
+ When using Hamcrest, there is no guarantee as to how often matches()
or
+ describeMismatch()
will be called, so the objects passed as
+ actual
arguments should not change when referenced. If you're testing a
+ stream, a good practice is to collect the contents of the stream before matching.
+
+ N.B. Well designed matchers should be immutable. +
BaseMatcher
Modifier and Type | +Method and Description | +
---|---|
void |
+_dont_implement_Matcher___instead_extend_BaseMatcher_()
+Deprecated.
+
+to make
+ |
+
void |
+describeMismatch(java.lang.Object actual,
+ Description mismatchDescription)
+Generate a description of why the matcher has not accepted the item.
+ |
+
boolean |
+matches(java.lang.Object actual)
+Evaluates the matcher for argument item.
+ |
+
describeTo
boolean matches(java.lang.Object actual)+
actual
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
void describeMismatch(java.lang.Object actual, + Description mismatchDescription)+
matches(item)
is false, but
+ will not check this.actual
- The item that the Matcher has rejected.mismatchDescription
- The description to be built or appended to.@Deprecated +void _dont_implement_Matcher___instead_extend_BaseMatcher_()+
for reasons why.
,
+BaseMatcher
public class MatcherAssert
+extends java.lang.Object
+Constructor and Description | +
---|
MatcherAssert() |
+
Modifier and Type | +Method and Description | +
---|---|
static void |
+assertThat(java.lang.String reason,
+ boolean assertion) |
+
static <T> void |
+assertThat(java.lang.String reason,
+ T actual,
+ Matcher<? super T> matcher) |
+
static <T> void |
+assertThat(T actual,
+ Matcher<? super T> matcher) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T> void assertThat(T actual, + Matcher<? super T> matcher)+
public static <T> void assertThat(java.lang.String reason, + T actual, + Matcher<? super T> matcher)+
public static void assertThat(java.lang.String reason, + boolean assertion)+
public class Matchers
+extends java.lang.Object
+Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<T> |
+allOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ALL of the specified matchers.
+ |
+
static <T> Matcher<T> |
+allOf(Matcher<? super T>... matchers)
+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)
+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)
+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.
+ |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+aMapWithSize(int size)
+Creates a matcher for
+Map s that matches when the size() method returns
+ a value equal to the specified size . |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+aMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Map s that matches when the size() method returns
+ a value that satisfies the specified matcher. |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+anEmptyMap()
+Creates a matcher for
+Map s that matches when the size() method returns
+ zero. |
+
static <T> Matcher<T> |
+any(java.lang.Class<T> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
static <T> AnyOf<T> |
+anyOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<? super T>... matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<T> first,
+ Matcher<? super T> second)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<T> first,
+ Matcher<? super T> second,
+ Matcher<? super T> third)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<T> first,
+ Matcher<? super T> second,
+ Matcher<? super T> third,
+ Matcher<? super T> fourth)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<T> first,
+ Matcher<? super T> second,
+ Matcher<? super T> third,
+ Matcher<? super T> fourth,
+ Matcher<? super T> fifth)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<T> first,
+ Matcher<? super T> second,
+ Matcher<? super T> third,
+ Matcher<? super T> fourth,
+ Matcher<? super T> fifth,
+ Matcher<? super T> sixth)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static Matcher<java.lang.Object> |
+anything()
+Creates a matcher that always matches, regardless of the examined object.
+ |
+
static Matcher<java.lang.Object> |
+anything(java.lang.String description)
+Creates a matcher that always matches, regardless of the examined object, but describes
+ itself with the specified
+String . |
+
static <T> IsArray<T> |
+array(Matcher<? super T>... elementMatchers)
+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(java.util.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(java.util.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(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(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 the
+length of the array
+ equals the specified size . |
+
static <E> Matcher<E[]> |
+arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for arrays that matches when the
+length of the array
+ satisfies the specified matcher. |
+
static Matcher<java.lang.String> |
+blankOrNullString()
+Creates a matcher of
+String that matches when the examined string is null , or
+ contains zero or more whitespace characters and nothing else. |
+
static Matcher<java.lang.String> |
+blankString()
+Creates a matcher of
+String that matches when the examined string contains
+ zero or more whitespace characters and nothing else. |
+
static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> |
+both(Matcher<? super LHS> matcher)
+Creates a matcher that matches when both of the specified matchers match the examined object.
+ |
+
static Matcher<java.math.BigDecimal> |
+closeTo(java.math.BigDecimal operand,
+ java.math.BigDecimal error)
+Creates a matcher of
+BigDecimal s that matches when an examined BigDecimal is equal
+ to the specified operand , within a range of +/- error . |
+
static Matcher<java.lang.Double> |
+closeTo(double operand,
+ double error)
+Creates a matcher of
+Double s that matches when an examined double is equal
+ to the specified operand , within a range of +/- error . |
+
static <T extends java.lang.Comparable<T>> |
+comparesEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ equal to the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(E... items)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each logically equal to the
+ corresponding item in the specified items. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(java.util.List<Matcher<? super E>> itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(Matcher<? super E>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each satisfying the corresponding
+ matcher in the specified matchers. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(Matcher<? super E> itemMatcher)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a single item that satisfies the specified matcher. |
+
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(java.util.Collection<Matcher<? super T>> itemMatchers)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers. |
+
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(Matcher<? super T>... itemMatchers)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each satisfying one matcher anywhere
+ in the specified matchers. |
+
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(T... items)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each logically equal to one item
+ anywhere in the specified items. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(E... items)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that contains items logically equal to the
+ corresponding item in the specified items, in the same relative order
+ For example: |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(java.util.List<Matcher<? super E>> itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that contains items satisfying the corresponding
+ matcher in the specified list of matchers, in the same relative order. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(Matcher<? super E>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that each satisfying the corresponding
+ matcher in the specified matchers, in the same relative order. |
+
static Matcher<java.lang.String> |
+containsString(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere. |
+
static Matcher<java.lang.String> |
+containsStringIgnoringCase(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere, ignoring case. |
+
static <T> Matcher<T> |
+describedAs(java.lang.String description,
+ Matcher<T> matcher,
+ java.lang.Object... values)
+Wraps an existing matcher, overriding its description with that specified.
+ |
+
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.
+ |
+
static <E> Matcher<java.util.Collection<? extends E>> |
+empty()
+Creates a matcher for
+Collection s matching examined collections whose isEmpty
+ method returns true . |
+
static <E> Matcher<E[]> |
+emptyArray()
+Creates a matcher for arrays that matches when the
+length of the array
+ is zero. |
+
static <E> Matcher<java.util.Collection<E>> |
+emptyCollectionOf(java.lang.Class<E> unusedToForceReturnType)
+Creates a matcher for
+Collection s matching examined collections whose isEmpty
+ method returns true . |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+emptyIterable()
+Creates a matcher for
+Iterable s matching examined iterables that yield no items. |
+
static <E> Matcher<java.lang.Iterable<E>> |
+emptyIterableOf(java.lang.Class<E> unusedToForceReturnType)
+Creates a matcher for
+Iterable s matching examined iterables that yield no items. |
+
static Matcher<java.lang.String> |
+emptyOrNullString()
+Creates a matcher of
+String that matches when the examined string is null , or
+ has zero length. |
+
static Matcher<java.lang.String> |
+emptyString()
+Creates a matcher of
+String that matches when the examined string has zero length. |
+
static Matcher<java.lang.String> |
+endsWith(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String . |
+
static Matcher<java.lang.String> |
+endsWithIgnoringCase(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String , ignoring case. |
+
static <T> Matcher<T> |
+equalTo(T operand)
+Creates a matcher that matches when the examined object is logically equal to the specified
+
+operand , as determined by calling the Object.equals(java.lang.Object) method on
+ the examined object. |
+
static Matcher<java.lang.String> |
+equalToCompressingWhiteSpace(java.lang.String expectedString)
+Creates a matcher of
+String that matches when the examined string is equal to
+ the specified expectedString, when whitespace differences are (mostly) ignored. |
+
static Matcher<java.lang.String> |
+equalToIgnoringCase(java.lang.String expectedString)
+Creates a matcher of
+String that matches when the examined string is equal to
+ the specified expectedString, ignoring case. |
+
static Matcher<java.lang.String> |
+equalToIgnoringWhiteSpace(java.lang.String expectedString)
+Deprecated.
+
+
+ |
+
static Matcher<java.lang.Object> |
+equalToObject(java.lang.Object operand)
+Creates an
+IsEqual matcher that does not enforce the values being
+ compared to be of the same static type. |
+
static Matcher<java.util.EventObject> |
+eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass,
+ java.lang.Object source)
+Creates a matcher of
+EventObject that matches any object
+ derived from eventClass announced by source. |
+
static Matcher<java.util.EventObject> |
+eventFrom(java.lang.Object source)
+Creates a matcher of
+EventObject that matches any EventObject
+ announced by source. |
+
static <U> Matcher<java.lang.Iterable<? extends U>> |
+everyItem(Matcher<U> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields items that are all matched by the specified
+ itemMatcher . |
+
static <T extends java.lang.Comparable<T>> |
+greaterThan(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ greater than the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <T extends java.lang.Comparable<T>> |
+greaterThanOrEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ greater than or equal to the specified value, as reported by the compareTo method
+ of the examined object. |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+hasEntry(K key,
+ V value)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one entry whose key equals the specified key and whose value equals the
+ specified value . |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+hasEntry(Matcher<? super K> keyMatcher,
+ Matcher<? super V> valueMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one entry whose key satisfies the specified keyMatcher and whose
+ value satisfies the specified valueMatcher . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(Matcher<? super T> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is matched by the specified
+ itemMatcher . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(T item)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is equal to the specified
+ 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 specified
+elementMatcher . |
+
static <T> Matcher<T[]> |
+hasItemInArray(T element)
+A shortcut to the frequently used
+hasItemInArray(equalTo(x)) . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(Matcher<? super T>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(T... items)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is equal to the corresponding
+ item from the specified items . |
+
static <K> Matcher<java.util.Map<? extends K,?>> |
+hasKey(K key)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one key that is equal to the specified key. |
+
static <K> Matcher<java.util.Map<? extends K,?>> |
+hasKey(Matcher<? super K> keyMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one key that satisfies the specified matcher. |
+
static Matcher<java.lang.CharSequence> |
+hasLength(int length)
+Creates a matcher of
+CharSequence that matches when a char sequence has the length
+ of the specified argument . |
+
static <T> Matcher<T> |
+hasProperty(java.lang.String propertyName)
+Creates a matcher that matches when the examined object has a JavaBean property
+ with the specified name.
+ |
+
static <T> Matcher<T> |
+hasProperty(java.lang.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<java.util.Collection<? extends E>> |
+hasSize(int size)
+Creates a matcher for
+Collection s that matches when the size() method returns
+ a value equal to the specified size . |
+
static <E> Matcher<java.util.Collection<? extends E>> |
+hasSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Collection s that matches when the size() method returns
+ a value that satisfies the specified matcher. |
+
static <T> Matcher<T> |
+hasToString(Matcher<? super java.lang.String> toStringMatcher)
+Creates a matcher that matches any examined object whose
+toString method
+ returns a value that satisfies the specified matcher. |
+
static <T> Matcher<T> |
+hasToString(java.lang.String expectedToString)
+Creates a matcher that matches any examined object whose
+toString method
+ returns a value equalTo the specified string. |
+
static <V> Matcher<java.util.Map<?,? extends V>> |
+hasValue(Matcher<? super V> valueMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one value that satisfies the specified valueMatcher. |
+
static <V> Matcher<java.util.Map<?,? extends V>> |
+hasValue(V value)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one value that is equal to the specified value. |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath)
+Creates a matcher of
+Node s that matches when the examined node contains a node
+ at the specified xPath , with any content. |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ Matcher<java.lang.String> valueMatcher)
+Creates a matcher of
+Node s that matches when the examined node has a value at the
+ specified xPath that satisfies the specified valueMatcher . |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ javax.xml.namespace.NamespaceContext namespaceContext)
+Creates a matcher of
+Node s that matches when the examined node contains a node
+ at the specified xPath within the specified namespace context, with any content. |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ javax.xml.namespace.NamespaceContext namespaceContext,
+ Matcher<java.lang.String> valueMatcher)
+Creates a matcher of
+Node s that matches when the examined node has a value at the
+ specified xPath , within the specified namespaceContext , that satisfies
+ the specified valueMatcher . |
+
static <T> Matcher<T> |
+in(java.util.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(java.lang.Class<?> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
static <T> Matcher<T> |
+is(Matcher<T> matcher)
+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 used
+is(equalTo(x)) . |
+
static <T> Matcher<T> |
+isA(java.lang.Class<?> type)
+A shortcut to the frequently used
+is(instanceOf(SomeClass.class)) . |
+
static Matcher<java.lang.String> |
+isEmptyOrNullString()
+Deprecated.
+
+use is(emptyOrNullString()) instead
+ |
+
static Matcher<java.lang.String> |
+isEmptyString()
+Deprecated.
+
+use is(emptyString()) instead
+ |
+
static <T> Matcher<T> |
+isIn(java.util.Collection<T> collection)
+Deprecated.
+
+use is(in(...)) instead
+ |
+
static <T> Matcher<T> |
+isIn(T[] elements)
+Deprecated.
+
+use is(in(...)) instead
+ |
+
static <T> Matcher<T> |
+isOneOf(T... elements)
+Deprecated.
+
+use is(oneOf(...)) instead
+ |
+
static <E> Matcher<java.lang.Iterable<E>> |
+iterableWithSize(int size)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields an item count that is equal to the specified
+ size argument. |
+
static <E> Matcher<java.lang.Iterable<E>> |
+iterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields an item count that satisfies the specified
+ matcher. |
+
static <T extends java.lang.Comparable<T>> |
+lessThan(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ less than the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <T extends java.lang.Comparable<T>> |
+lessThanOrEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ less than or equal to the specified value, as reported by the compareTo method
+ of the examined object. |
+
static Matcher<java.lang.String> |
+matchesPattern(java.util.regex.Pattern pattern)
+Creates a matcher of
+String that matches when the examined string
+ exactly matches the given Pattern . |
+
static Matcher<java.lang.String> |
+matchesPattern(java.lang.String regex)
+Creates a matcher of
+String that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern . |
+
static Matcher<java.lang.String> |
+matchesRegex(java.util.regex.Pattern pattern)
+Validate a string with a
+Pattern . |
+
static Matcher<java.lang.String> |
+matchesRegex(java.lang.String regex)
+Validate a string with a regex.
+ |
+
static <T> Matcher<T> |
+not(Matcher<T> matcher)
+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 used
+not(equalTo(x)) . |
+
static Matcher<java.lang.Double> |
+notANumber()
+Creates a matcher of
+Double s that matches when an examined double is not a number. |
+
static Matcher<java.lang.Object> |
+notNullValue()
+A shortcut to the frequently used
+not(nullValue()) . |
+
static <T> Matcher<T> |
+notNullValue(java.lang.Class<T> type)
+A shortcut to the frequently used
+not(nullValue(X.class)). |
+
static Matcher<java.lang.Object> |
+nullValue()
+Creates a matcher that matches if examined object is
+null . |
+
static <T> Matcher<T> |
+nullValue(java.lang.Class<T> type)
+Creates a matcher that matches if examined object is
+null . |
+
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,
+ java.lang.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.
+ |
+
static Matcher<java.lang.String> |
+startsWith(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String . |
+
static Matcher<java.lang.String> |
+startsWithIgnoringCase(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String , ignoring case |
+
static Matcher<java.lang.String> |
+stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings)
+Creates a matcher of
+String that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance. |
+
static Matcher<java.lang.String> |
+stringContainsInOrder(java.lang.String... substrings)
+Creates a matcher of
+String that 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.
+ |
+
static <T> Matcher<java.lang.Class<?>> |
+typeCompatibleWith(java.lang.Class<T> baseType)
+Creates a matcher of
+Class that matches when the specified baseType is
+ assignable from the examined class. |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T> Matcher<T> allOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
@SafeVarargs +public static <T> Matcher<T> allOf(Matcher<? super T>... matchers)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> Matcher<T> allOf(Matcher<? super T> first, + Matcher<? super T> second)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> Matcher<T> allOf(Matcher<? super T> first, + Matcher<? super T> second, + Matcher<? super T> third)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> Matcher<T> allOf(Matcher<? super T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> Matcher<T> allOf(Matcher<? super T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth, + Matcher<? super T> fifth)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> Matcher<T> allOf(Matcher<? super T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth, + Matcher<? super T> fifth, + Matcher<? super T> sixth)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public static <T> AnyOf<T> anyOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
@SafeVarargs +public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <T> AnyOf<T> anyOf(Matcher<T> first, + Matcher<? super T> second)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <T> AnyOf<T> anyOf(Matcher<T> first, + Matcher<? super T> second, + Matcher<? super T> third)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <T> AnyOf<T> anyOf(Matcher<T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <T> AnyOf<T> anyOf(Matcher<T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth, + Matcher<? super T> fifth)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <T> AnyOf<T> anyOf(Matcher<T> first, + Matcher<? super T> second, + Matcher<? super T> third, + Matcher<? super T> fourth, + Matcher<? super T> fifth, + Matcher<? super T> sixth)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
public static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher)+
assertThat("fab", both(containsString("a")).and(containsString("b")))
public static <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher)+
assertThat("fan", either(containsString("a")).or(containsString("b")))
public static <T> Matcher<T> describedAs(java.lang.String description, + Matcher<T> matcher, + java.lang.Object... values)+
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
description
- the new description for the wrapped matchermatcher
- the matcher to wrapvalues
- optional values to insert into the tokenized descriptionpublic static <U> Matcher<java.lang.Iterable<? extends U>> everyItem(Matcher<U> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.
+ For example:
+ assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
itemMatcher
- the matcher to apply to every item provided by the examined Iterable
public static <T> Matcher<T> is(Matcher<T> matcher)+
assertThat(cheese, is(equalTo(smelly)))+ instead of: +
assertThat(cheese, equalTo(smelly))
public static <T> Matcher<T> is(T value)+
is(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(smelly))+ instead of: +
assertThat(cheese, is(equalTo(smelly)))
public static <T> Matcher<T> isA(java.lang.Class<?> type)+
is(instanceOf(SomeClass.class))
.
+ For example:
+ assertThat(cheese, isA(Cheddar.class))+ instead of: +
assertThat(cheese, is(instanceOf(Cheddar.class)))
public static Matcher<java.lang.Object> anything()+
public static Matcher<java.lang.Object> anything(java.lang.String description)+
String
.description
- a meaningful String
used when describing itselfpublic static <T> Matcher<java.lang.Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
itemMatcher
- the matcher to apply to items provided by the examined Iterable
public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(T item)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
item
- the item to compare against the items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(Matcher<? super T>... itemMatchers)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
. Whilst matching, each traversal of
+ the examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
itemMatchers
- the matchers to apply to items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(T... items)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
. Whilst matching, each traversal of the
+ examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
items
- the items to compare against the items provided by the examined Iterable
public static <T> Matcher<T> equalTo(T operand)+
operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.
+
+ If the specified operand is null
then the created matcher will only match if
+ the examined object's equals
method returns true
when passed a
+ null
(which would be a violation of the equals
contract), unless the
+ examined object itself is null
, in which case the matcher will return a positive
+ match.
The created matcher provides a special behaviour when examining Array
s, whereby
+ it will match if both the operand and the examined object are arrays of the same length and
+ contain items that are equal to each other (according to the above rules) in the same
+ indexes.
+ assertThat("foo", equalTo("foo")); + assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"})); +
public static Matcher<java.lang.Object> equalToObject(java.lang.Object operand)+
IsEqual
matcher that does not enforce the values being
+ compared to be of the same static type.public static <T> Matcher<T> any(java.lang.Class<T> type)+
type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.
+
+ The created matcher forces a relationship between specified type and the examined object, and should be
+ used when it is necessary to make generics conform, for example in the JMock clause
+ with(any(Thing.class))
assertThat(new Canoe(), instanceOf(Canoe.class));
public static <T> Matcher<T> instanceOf(java.lang.Class<?> type)+
type
,
+ as determined by calling the 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 <T> Matcher<T> not(Matcher<T> matcher)+
assertThat(cheese, is(not(equalTo(smelly))))
matcher
- the matcher whose sense should be invertedpublic static <T> Matcher<T> not(T value)+
not(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(not(smelly)))+ instead of: +
assertThat(cheese, is(not(equalTo(smelly))))
value
- the value that any examined object should not equalpublic static Matcher<java.lang.Object> notNullValue()+
not(nullValue())
.
+ For example:
+ assertThat(cheese, is(notNullValue()))+ instead of: +
assertThat(cheese, is(not(nullValue())))
public static <T> Matcher<T> notNullValue(java.lang.Class<T> type)+
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))))
type
- dummy parameter used to infer the generic type of the returned matcherpublic static Matcher<java.lang.Object> nullValue()+
null
.
+ For example:
+ assertThat(cheese, is(nullValue())
public static <T> Matcher<T> nullValue(java.lang.Class<T> type)+
null
. Accepts a
+ single dummy argument to facilitate type inference.
+ For example:
+ assertThat(cheese, is(nullValue(Cheese.class))
type
- dummy parameter used to infer the generic type of the returned matcherpublic static <T> Matcher<T> sameInstance(T target)+
target
- the target instance against which others should be assessedpublic static <T> Matcher<T> theInstance(T target)+
target
- the target instance against which others should be assessedpublic static Matcher<java.lang.String> containsString(java.lang.String substring)+
String
contains the specified
+ String
anywhere.
+ For example:
+ assertThat("myStringOfNote", containsString("ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic static Matcher<java.lang.String> containsStringIgnoringCase(java.lang.String substring)+
String
contains the specified
+ String
anywhere, ignoring case.
+ For example:
+ assertThat("myStringOfNote", containsStringIgnoringCase("Ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic static Matcher<java.lang.String> startsWith(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
.
+
assertThat("myStringOfNote", startsWith("my"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic static Matcher<java.lang.String> startsWithIgnoringCase(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
, ignoring case
+
assertThat("myStringOfNote", startsWithIgnoringCase("My"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic static Matcher<java.lang.String> endsWith(java.lang.String suffix)+
String
ends with the specified
+ String
.
+ For example:
+ assertThat("myStringOfNote", endsWith("Note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringpublic static Matcher<java.lang.String> endsWithIgnoringCase(java.lang.String suffix)+
String
ends with the specified
+ String
, ignoring case.
+ For example:
+ assertThat("myStringOfNote", endsWithIgnoringCase("note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringpublic static Matcher<java.lang.String> matchesRegex(java.util.regex.Pattern pattern)+
Pattern
.
+
+ + assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$")); +
pattern
- the pattern to be used.public static Matcher<java.lang.String> matchesRegex(java.lang.String regex)+
+ assertThat("abc", matchesRegex("ˆ[a-z]+$")); +
regex
- The regex to be used for the validation.@SafeVarargs +public static <T> IsArray<T> array(Matcher<? super T>... elementMatchers)+
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))
elementMatchers
- the matchers that the elements of examined arrays should satisfypublic static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)+
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")))
elementMatcher
- the matcher to apply to elements in examined arrayspublic static <T> Matcher<T[]> hasItemInArray(T element)+
hasItemInArray(equalTo(x))
.
+ For example:
+ assertThat(hasItemInArray(x))+ instead of: +
assertThat(hasItemInArray(equalTo(x)))
element
- the element that should be present in examined arrays@SafeVarargs +public static <E> Matcher<E[]> arrayContaining(E... items)+
assertThat(new String[]{"foo", "bar"}, arrayContaining("foo", "bar"))
items
- the items that must equal the items within an examined array@SafeVarargs +public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers)+
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
itemMatchers
- the matchers that must be satisfied by the items in the examined arraypublic static <E> Matcher<E[]> arrayContaining(java.util.List<Matcher<? super E>> itemMatchers)+
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the corresponding item in an examined array@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")))
itemMatchers
- a list of matchers, each of which must be satisfied by an entry in an examined arraypublic static <E> Matcher<E[]> arrayContainingInAnyOrder(java.util.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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined array@SafeVarargs +public 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. + 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"))
items
- the items that must equal the entries of an examined array, in any orderpublic static <E> Matcher<E[]> arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
length
of the array
+ satisfies the specified matcher.
+ For example:
+ assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
sizeMatcher
- a matcher for the length of an examined arraypublic static <E> Matcher<E[]> arrayWithSize(int size)+
length
of the array
+ equals the specified size
.
+ For example:
+ assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
size
- the length that an examined array must have for a positive matchpublic static <E> Matcher<E[]> emptyArray()+
length
of the array
+ is zero.
+ For example:
+ assertThat(new String[0], emptyArray())
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> aMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
Map
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.
+ For example:
+ assertThat(myMap, is(aMapWithSize(equalTo(2))))
sizeMatcher
- a matcher for the size of an examined Map
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> aMapWithSize(int size)+
Map
s that matches when the size()
method returns
+ a value equal to the specified size
.
+ For example:
+ assertThat(myMap, is(aMapWithSize(2)))
size
- the expected size of an examined Map
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> anEmptyMap()+
Map
s that matches when the size()
method returns
+ zero.
+ For example:
+ assertThat(myMap, is(anEmptyMap()))
public static <E> Matcher<java.util.Collection<? extends E>> hasSize(Matcher<? super java.lang.Integer> sizeMatcher)+
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)))
sizeMatcher
- a matcher for the size of an examined Collection
public static <E> Matcher<java.util.Collection<? extends E>> hasSize(int size)+
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))
size
- the expected size of an examined Collection
public static <E> Matcher<java.util.Collection<? extends E>> empty()+
Collection
s matching examined collections whose isEmpty
+ method returns true
.
+ For example:
+ assertThat(new ArrayList<String>(), is(empty()))
public static <E> Matcher<java.util.Collection<E>> emptyCollectionOf(java.lang.Class<E> unusedToForceReturnType)+
Collection
s matching examined collections whose isEmpty
+ method returns true
.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
unusedToForceReturnType
- the type of the collection's contentpublic static <E> Matcher<java.lang.Iterable<? extends E>> emptyIterable()+
Iterable
s matching examined iterables that yield no items.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyIterable()))
public static <E> Matcher<java.lang.Iterable<E>> emptyIterableOf(java.lang.Class<E> unusedToForceReturnType)+
Iterable
s matching examined iterables that yield no items.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
unusedToForceReturnType
- the type of the iterable's content@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> contains(E... items)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each logically equal to the
+ corresponding item in the specified items. 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"))
items
- the items that must equal the items provided by an examined Iterable
public static <E> Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E> itemMatcher)+
Iterable
s that matches when a single pass over the
+ examined 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")))
itemMatcher
- the matcher that must be satisfied by the single item provided by an
+ examined Iterable
@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined 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")))
itemMatchers
- the matchers that must be satisfied by the items provided by an examined Iterable
public static <E> Matcher<java.lang.Iterable<? extends E>> contains(java.util.List<Matcher<? super E>> itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers. 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the corresponding item provided by
+ an examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined 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")))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(T... items)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each logically equal to one item
+ anywhere in the specified items. 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"))
items
- the items that must equal the items provided by an examined Iterable
in any orderpublic static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(java.util.Collection<Matcher<? super T>> itemMatchers)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers. 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(E... items)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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"))
items
- the items that must be contained within items provided by an examined Iterable
in the same relative order@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(Matcher<? super E>... itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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")))
itemMatchers
- the matchers that must be satisfied by the items provided by an examined Iterable
in the same relative orderpublic static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(java.util.List<Matcher<? super E>> itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the items provided by
+ an examined Iterable
in the same relative orderpublic static <E> Matcher<java.lang.Iterable<E>> iterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that satisfies the specified
+ matcher.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
sizeMatcher
- a matcher for the number of items that should be yielded by an examined Iterable
public static <E> Matcher<java.lang.Iterable<E>> iterableWithSize(int size)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that is equal to the specified
+ size
argument.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
size
- the number of items that should be yielded by an examined Iterable
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, + Matcher<? super V> valueMatcher)+
Map
s matching when the examined 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")))
keyMatcher
- the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entryvalueMatcher
- the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entrypublic static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(K key, + V value)+
Map
s matching when the examined 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"))
key
- the key that, in combination with the value, must be describe at least one entryvalue
- the value that, in combination with the key, must be describe at least one entrypublic static <K> Matcher<java.util.Map<? extends K,?>> hasKey(Matcher<? super K> keyMatcher)+
Map
s matching when the examined Map
contains
+ at least one key that satisfies the specified matcher.
+ For example:
+ assertThat(myMap, hasKey(equalTo("bar")))
keyMatcher
- the matcher that must be satisfied by at least one keypublic static <K> Matcher<java.util.Map<? extends K,?>> hasKey(K key)+
Map
s matching when the examined Map
contains
+ at least one key that is equal to the specified key.
+ For example:
+ assertThat(myMap, hasKey("bar"))
key
- the key that satisfying maps must containpublic static <V> Matcher<java.util.Map<?,? extends V>> hasValue(Matcher<? super V> valueMatcher)+
Map
s matching when the examined Map
contains
+ at least one value that satisfies the specified valueMatcher.
+ For example:
+ assertThat(myMap, hasValue(equalTo("foo")))
valueMatcher
- the matcher that must be satisfied by at least one valuepublic static <V> Matcher<java.util.Map<?,? extends V>> hasValue(V value)+
Map
s matching when the examined Map
contains
+ at least one value that is equal to the specified value.
+ For example:
+ assertThat(myMap, hasValue("foo"))
value
- the value that satisfying maps must containpublic static <T> Matcher<T> in(java.util.Collection<T> collection)+
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
collection
- the collection in which matching items must be foundpublic static <T> Matcher<T> in(T[] elements)+
assertThat("foo", is(in(new String[]{"bar", "foo"})))
elements
- the array in which matching items must be foundpublic static <T> Matcher<T> isIn(java.util.Collection<T> collection)+
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
collection
- the collection in which matching items must be foundpublic static <T> Matcher<T> isIn(T[] elements)+
assertThat("foo", isIn(new String[]{"bar", "foo"}))
elements
- the array in which matching items must be found@SafeVarargs +public static <T> Matcher<T> isOneOf(T... elements)+
assertThat("foo", isOneOf("bar", "foo"))
elements
- the elements amongst which matching items will be found@SafeVarargs +public static <T> Matcher<T> oneOf(T... elements)+
assertThat("foo", is(oneOf("bar", "foo")))
elements
- the elements amongst which matching items will be foundpublic static Matcher<java.lang.Double> closeTo(double operand, + double error)+
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)))
operand
- the expected value of matching doubleserror
- the delta (+/-) within which matches will be allowedpublic static Matcher<java.lang.Double> notANumber()+
Double
s that matches when an examined double is not a number.
+ For example:
+ assertThat(Double.NaN, is(notANumber()))
public static Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, + java.math.BigDecimal error)+
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 BigDecimal.compareTo(java.math.BigDecimal)
method.
+ For example:
+ assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
operand
- the expected value of matching BigDecimalserror
- the delta (+/-) within which matches will be allowedpublic static <T extends java.lang.Comparable<T>> Matcher<T> comparesEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> greaterThan(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return greater
+ than zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return greater
+ than or equal to zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> lessThan(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return less
+ than zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> lessThanOrEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return less
+ than or equal to zeropublic static Matcher<java.lang.String> equalToIgnoringCase(java.lang.String expectedString)+
String
that matches when the examined string is equal to
+ the specified expectedString, ignoring case.
+ For example:
+ assertThat("Foo", equalToIgnoringCase("FOO"))
expectedString
- the expected value of matched stringspublic static Matcher<java.lang.String> equalToIgnoringWhiteSpace(java.lang.String expectedString)+
equalToCompressingWhiteSpace(String)
expectedString
- the expected value of matched stringspublic static Matcher<java.lang.String> equalToCompressingWhiteSpace(java.lang.String expectedString)+
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:
+ assertThat(" my\tfoo bar ", equalToIgnoringWhiteSpace(" my foo bar"))
expectedString
- the expected value of matched stringspublic static Matcher<java.lang.String> emptyOrNullString()+
String
that matches when the examined string is null
, or
+ has zero length.
+ For example:
+ assertThat(((String)null), is(emptyOrNullString()))
public static Matcher<java.lang.String> emptyString()+
String
that matches when the examined string has zero length.
+ For example:
+ assertThat("", is(emptyString()))
public static Matcher<java.lang.String> isEmptyOrNullString()+
String
that matches when the examined string is null
, or
+ has zero length.
+ For example:
+ assertThat(((String)null), isEmptyOrNullString())
public static Matcher<java.lang.String> isEmptyString()+
String
that matches when the examined string has zero length.
+ For example:
+ assertThat("", isEmptyString())
public static Matcher<java.lang.String> blankOrNullString()+
String
that matches when the examined string is null
, or
+ contains zero or more whitespace characters and nothing else.
+ For example:
+ assertThat(((String)null), is(blankOrNullString()))
public static Matcher<java.lang.String> blankString()+
String
that matches when the examined string contains
+ zero or more whitespace characters and nothing else.
+ For example:
+ assertThat(" ", is(blankString()))
public static Matcher<java.lang.String> matchesPattern(java.util.regex.Pattern pattern)+
String
that matches when the examined string
+ exactly matches the given Pattern
.public static Matcher<java.lang.String> matchesPattern(java.lang.String regex)+
String
that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern
.public static Matcher<java.lang.String> stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings)+
String
that 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"
substrings
- the substrings that must be contained within matching stringspublic static Matcher<java.lang.String> stringContainsInOrder(java.lang.String... substrings)+
String
that 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"
substrings
- the substrings that must be contained within matching stringspublic static Matcher<java.lang.CharSequence> hasLength(int length)+
CharSequence
that matches when a char sequence has the length
+ of the specified argument
.
+ For example:
+
+ + assertThat("text", length(4)) +
length
- the expected length of the stringpublic static <T> Matcher<T> hasToString(Matcher<? super java.lang.String> toStringMatcher)+
toString
method
+ returns a value that satisfies the specified matcher.
+ For example:
+ assertThat(true, hasToString(equalTo("TRUE")))
toStringMatcher
- the matcher used to verify the toString resultpublic static <T> Matcher<T> hasToString(java.lang.String expectedToString)+
toString
method
+ returns a value equalTo the specified string.
+ For example:
+ assertThat(true, hasToString("TRUE"))
expectedToString
- the expected toString resultpublic static <T> Matcher<java.lang.Class<?>> typeCompatibleWith(java.lang.Class<T> baseType)+
Class
that matches when the specified baseType is
+ assignable from the examined class.
+ For example:
+ assertThat(Integer.class, typeCompatibleWith(Number.class))
baseType
- the base class to examine classes againstpublic static Matcher<java.util.EventObject> eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass, + java.lang.Object source)+
EventObject
that matches any object
+ derived from eventClass announced by source.
+ For example:
+ assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
eventClass
- the class of the event to match onsource
- the source of the eventpublic static Matcher<java.util.EventObject> eventFrom(java.lang.Object source)+
EventObject
that matches any EventObject
+ announced by source.
+ For example:
+ assertThat(myEvent, is(eventFrom(myBean)))
source
- the source of the eventpublic static <T> Matcher<T> hasProperty(java.lang.String propertyName)+
assertThat(myBean, hasProperty("foo"))
propertyName
- the name of the JavaBean property that examined beans should possesspublic static <T> Matcher<T> hasProperty(java.lang.String propertyName, + Matcher<?> valueMatcher)+
assertThat(myBean, hasProperty("foo", equalTo("bar"))
propertyName
- the name of the JavaBean property that examined beans should possessvalueMatcher
- a matcher for the value of the specified property of the examined beanpublic static <B> Matcher<B> samePropertyValuesAs(B expectedBean, + java.lang.String... ignoredProperties)+
agerather than method names such as
getAge. + For example: +
assertThat(myBean, samePropertyValuesAs(myExpectedBean))+
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
expectedBean
- the bean against which examined beans are comparedignoredProperties
- do not check any of these named properties.public static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + Matcher<java.lang.String> valueMatcher)+
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")))
xPath
- the target xpathvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + javax.xml.namespace.NamespaceContext namespaceContext, + Matcher<java.lang.String> valueMatcher)+
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")))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodesvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath)+
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"))
xPath
- the target xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + javax.xml.namespace.NamespaceContext namespaceContext)+
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))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodespublic interface SelfDescribing
+Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
void describeTo(Description description)+
description
- The description to be built or appended to.public class StringDescription +extends BaseDescription+
Description
that is stored as a string.Description.NullDescription
NONE
Constructor and Description | +
---|
StringDescription() |
+
StringDescription(java.lang.Appendable out) |
+
Modifier and Type | +Method and Description | +
---|---|
protected void |
+append(char c)
+Append the char c to the description.
+ |
+
protected void |
+append(java.lang.String str)
+Append the String str to the description.
+ |
+
static java.lang.String |
+asString(SelfDescribing selfDescribing)
+Alias for
+toString(SelfDescribing) . |
+
java.lang.String |
+toString()
+Returns the description as a string.
+ |
+
static java.lang.String |
+toString(SelfDescribing selfDescribing)
+Return the description of a
+SelfDescribing object as a String. |
+
appendDescriptionOf, appendList, appendText, appendValue, appendValueList, appendValueList
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public StringDescription()+
public StringDescription(java.lang.Appendable out)+
public static java.lang.String toString(SelfDescribing selfDescribing)+
SelfDescribing
object as a String.selfDescribing
- The object to be described.public static java.lang.String asString(SelfDescribing selfDescribing)+
toString(SelfDescribing)
.protected void append(java.lang.String str)+
BaseDescription
BaseDescription.append(char)
.
+ Override in subclasses to provide an efficient implementation.append
in class BaseDescription
protected void append(char c)+
BaseDescription
append
in class BaseDescription
public java.lang.String toString()+
toString
in class java.lang.Object
T
- public abstract class TypeSafeDiagnosingMatcher<T> +extends BaseMatcher<T>+
matchesSafely().
Modifier | +Constructor and Description | +
---|---|
protected |
+TypeSafeDiagnosingMatcher()
+The default constructor for simple sub types
+ |
+
protected |
+TypeSafeDiagnosingMatcher(java.lang.Class<?> expectedType)
+Use this constructor if the subclass that implements
+matchesSafely
+ is not the class that binds <T> to a type. |
+
protected |
+TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder)
+Use this constructor if the subclass that implements
+matchesSafely
+ is not the class that binds <T> to a type. |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatch(java.lang.Object item,
+ Description mismatchDescription)
+Generate a description of why the matcher has not accepted the item.
+ |
+
boolean |
+matches(java.lang.Object item)
+Evaluates the matcher for argument item.
+ |
+
protected abstract boolean |
+matchesSafely(T item,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
describeTo
protected TypeSafeDiagnosingMatcher(java.lang.Class<?> expectedType)+
matchesSafely
+ is not the class that binds <T> to a type.expectedType
- The expectedType of the actual value.protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder)+
matchesSafely
+ is not the class that binds <T> to a type.typeFinder
- A type finder to extract the typeprotected TypeSafeDiagnosingMatcher()+
protected abstract boolean matchesSafely(T item, + Description mismatchDescription)+
public final boolean matches(java.lang.Object item)+
Matcher
item
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public final void describeMismatch(java.lang.Object item, + Description mismatchDescription)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
describeMismatch
in class BaseMatcher<T>
item
- The item that the Matcher has rejected.mismatchDescription
- The description to be built or appended to.public abstract class TypeSafeMatcher<T> +extends BaseMatcher<T>+
Modifier | +Constructor and Description | +
---|---|
protected |
+TypeSafeMatcher()
+The default constructor for simple sub types
+ |
+
protected |
+TypeSafeMatcher(java.lang.Class<?> expectedType)
+Use this constructor if the subclass that implements
+matchesSafely
+ is not the class that binds <T> to a type. |
+
protected |
+TypeSafeMatcher(ReflectiveTypeFinder typeFinder)
+Use this constructor if the subclass that implements
+matchesSafely
+ is not the class that binds <T> to a type. |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatch(java.lang.Object item,
+ Description description)
+Generate a description of why the matcher has not accepted the item.
+ |
+
protected void |
+describeMismatchSafely(T item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
boolean |
+matches(java.lang.Object item)
+Methods made final to prevent accidental override.
+ |
+
protected abstract boolean |
+matchesSafely(T item)
+Subclasses should implement this.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
describeTo
protected TypeSafeMatcher()+
protected TypeSafeMatcher(java.lang.Class<?> expectedType)+
matchesSafely
+ is not the class that binds <T> to a type.expectedType
- The expectedType of the actual value.protected TypeSafeMatcher(ReflectiveTypeFinder typeFinder)+
matchesSafely
+ is not the class that binds <T> to a type.typeFinder
- A type finder to extract the typeprotected abstract boolean matchesSafely(T item)+
protected void describeMismatchSafely(T item, + Description mismatchDescription)+
public final boolean matches(java.lang.Object item)+
BaseMatcher
.item
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public final void describeMismatch(java.lang.Object item, + Description description)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
describeMismatch
in class BaseMatcher<T>
item
- The item that the Matcher has rejected.description
- The description to be built or appended to.public class HasProperty<T> +extends TypeSafeMatcher<T>+
Constructor and Description | +
---|
HasProperty(java.lang.String propertyName) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(T item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+hasProperty(java.lang.String propertyName)
+Creates a matcher that matches when the examined object has a JavaBean property
+ with the specified name.
+ |
+
boolean |
+matchesSafely(T obj)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public HasProperty(java.lang.String propertyName)+
public boolean matchesSafely(T obj)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<T>
public void describeMismatchSafely(T item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> hasProperty(java.lang.String propertyName)+
assertThat(myBean, hasProperty("foo"))
propertyName
- the name of the JavaBean property that examined beans should possesspublic class HasPropertyWithValue<T> +extends TypeSafeDiagnosingMatcher<T>+
Matcher that asserts that a JavaBean property on an argument passed to the + mock object meets the provided matcher. This is useful for when objects + are created within code under test and passed to a mock object, and you wish + to assert that the created object has certain properties. +
+ ++ public class Person { + private String name; + public Person(String person) { + this.person = person; + } + public String getName() { + return name; + } + }+ + And that these person objects are generated within a piece of code under test + (a class named PersonGenerator). This object is sent to one of our mock objects + which overrides the PersonGenerationListener interface: +
+ public interface PersonGenerationListener { + public void personGenerated(Person person); + }+ + In order to check that the code under test generates a person with name + "Iain" we would do the following: +
+ Mock personGenListenerMock = mock(PersonGenerationListener.class); + personGenListenerMock.expects(once()).method("personGenerated").with(and(isA(Person.class), hasProperty("Name", eq("Iain"))); + PersonGenerationListener listener = (PersonGenerationListener)personGenListenerMock.proxy();+ +
If an exception is thrown by the getter method for a property, the property + does not exist, is not readable, or a reflection related exception is thrown + when trying to invoke it then this is treated as an evaluation failure and + the matches method will return false. +
+This matcher class will also work with JavaBean objects that have explicit + bean descriptions via an associated BeanInfo description class. See the + JavaBeans specification for more information: + http://java.sun.com/products/javabeans/docs/index.html +
Constructor and Description | +
---|
HasPropertyWithValue(java.lang.String propertyName,
+ Matcher<?> valueMatcher) |
+
HasPropertyWithValue(java.lang.String propertyName,
+ Matcher<?> valueMatcher,
+ java.lang.String messageFormat) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+hasProperty(java.lang.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 <T> Matcher<T> |
+hasPropertyAtPath(java.lang.String path,
+ Matcher<T> valueMatcher)
+Creates a matcher that matches when the examined object is a graph of
+ JavaBean objects that can be navigated along the declared dot-separated path
+ and the final element of that path is a JavaBean property whose value satisfies the
+ specified matcher.
+ |
+
boolean |
+matchesSafely(T bean,
+ Description mismatch)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public HasPropertyWithValue(java.lang.String propertyName, + Matcher<?> valueMatcher)+
public HasPropertyWithValue(java.lang.String propertyName, + Matcher<?> valueMatcher, + java.lang.String messageFormat)+
public boolean matchesSafely(T bean, + Description mismatch)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> hasProperty(java.lang.String propertyName, + Matcher<?> valueMatcher)+
assertThat(myBean, hasProperty("foo", equalTo("bar"))
propertyName
- the name of the JavaBean property that examined beans should possessvalueMatcher
- a matcher for the value of the specified property of the examined beanpublic static <T> Matcher<T> hasPropertyAtPath(java.lang.String path, + Matcher<T> valueMatcher)+
assertThat(myBean, hasProperty("foo.bar.baz", equalTo("a property value"))
path
- the dot-separated path from the examined object to the JavaBean propertyvalueMatcher
- a matcher for the value of the specified property of the examined beanpublic class PropertyUtil
+extends java.lang.Object
+Modifier and Type | +Field and Description | +
---|---|
static java.lang.Object[] |
+NO_ARGUMENTS |
+
Constructor and Description | +
---|
PropertyUtil() |
+
Modifier and Type | +Method and Description | +
---|---|
static java.beans.PropertyDescriptor |
+getPropertyDescriptor(java.lang.String propertyName,
+ java.lang.Object fromObj)
+Returns the description of the property with the provided
+ name on the provided object's interface.
+ |
+
static java.beans.PropertyDescriptor[] |
+propertyDescriptorsFor(java.lang.Object fromObj,
+ java.lang.Class<java.lang.Object> stopClass)
+Returns all the property descriptors for the class associated with the given object
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final java.lang.Object[] NO_ARGUMENTS+
public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String propertyName, + java.lang.Object fromObj) + throws java.lang.IllegalArgumentException+
java.lang.IllegalArgumentException
- if there's a introspection failurepublic static java.beans.PropertyDescriptor[] propertyDescriptorsFor(java.lang.Object fromObj, + java.lang.Class<java.lang.Object> stopClass) + throws java.lang.IllegalArgumentException+
fromObj
- Use the class of this objectstopClass
- Don't include any properties from this ancestor class upwards.java.lang.IllegalArgumentException
- if there's a introspection failurepublic class SamePropertyValuesAs<T> +extends DiagnosingMatcher<T>+
Constructor and Description | +
---|
SamePropertyValuesAs(T expectedBean,
+ java.util.List<java.lang.String> ignoredProperties) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected boolean |
+matches(java.lang.Object actual,
+ Description mismatch) |
+
static <B> Matcher<B> |
+samePropertyValuesAs(B expectedBean,
+ java.lang.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.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public SamePropertyValuesAs(T expectedBean, + java.util.List<java.lang.String> ignoredProperties)+
protected boolean matches(java.lang.Object actual, + Description mismatch)+
matches
in class DiagnosingMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <B> Matcher<B> samePropertyValuesAs(B expectedBean, + java.lang.String... ignoredProperties)+
agerather than method names such as
getAge. + For example: +
assertThat(myBean, samePropertyValuesAs(myExpectedBean))+
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
expectedBean
- the bean against which examined beans are comparedignoredProperties
- do not check any of these named properties.See: Description
+Class | +Description | +
---|---|
HasProperty<T> | +
+ A Matcher that checks that an object has a JavaBean property
+ with the specified name.
+ |
+
HasPropertyWithValue<T> | +
+ Matcher that asserts that a JavaBean property on an argument passed to the
+ mock object meets the provided matcher.
+ |
+
PropertyUtil | +
+ Utility class for accessing properties on JavaBean objects.
+ |
+
SamePropertyValuesAs<T> | ++ |
Matchers of Java Bean properties and their values.
public class ArrayAsIterableMatcher<E> +extends TypeSafeMatcher<E[]>+
Modifier and Type | +Field and Description | +
---|---|
protected TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>> |
+iterableMatcher |
+
protected java.util.Collection<Matcher<? super E>> |
+matchers |
+
Constructor and Description | +
---|
ArrayAsIterableMatcher(TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>> iterableMatcher,
+ java.util.Collection<Matcher<? super E>> matchers,
+ java.lang.String message) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(E[] item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(E[] item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected final TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>> iterableMatcher+
public ArrayAsIterableMatcher(TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>> iterableMatcher, + java.util.Collection<Matcher<? super E>> matchers, + java.lang.String message)+
public boolean matchesSafely(E[] item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<E[]>
public void describeMismatchSafely(E[] item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<E[]>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public class ArrayMatching
+extends java.lang.Object
+Constructor and Description | +
---|
ArrayMatching() |
+
Modifier and Type | +Method and Description | +
---|---|
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(java.util.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(java.util.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(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(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> java.util.List<Matcher<? super E>> |
+asEqualMatchers(E[] items) |
+
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 specified
+elementMatcher . |
+
static <T> Matcher<T[]> |
+hasItemInArray(T element)
+A shortcut to the frequently used
+hasItemInArray(equalTo(x)) . |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)+
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")))
elementMatcher
- the matcher to apply to elements in examined arrayspublic static <T> Matcher<T[]> hasItemInArray(T element)+
hasItemInArray(equalTo(x))
.
+ For example:
+ assertThat(hasItemInArray(x))+ instead of: +
assertThat(hasItemInArray(equalTo(x)))
element
- the element that should be present in examined arrays@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")))
itemMatchers
- a list of matchers, each of which must be satisfied by an entry in an examined arraypublic static <E> Matcher<E[]> arrayContainingInAnyOrder(java.util.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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined array@SafeVarargs +public 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. + 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"))
items
- the items that must equal the entries of an examined array, in any order@SafeVarargs +public static <E> Matcher<E[]> arrayContaining(E... items)+
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
items
- the items that must equal the items within an examined array@SafeVarargs +public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers)+
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
itemMatchers
- the matchers that must be satisfied by the items in the examined arraypublic static <E> Matcher<E[]> arrayContaining(java.util.List<Matcher<? super E>> itemMatchers)+
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the corresponding item in an examined arraypublic static <E> java.util.List<Matcher<? super E>> asEqualMatchers(E[] items)+
public class HasItemInArray<T> +extends TypeSafeMatcher<T[]>+
Constructor and Description | +
---|
HasItemInArray(Matcher<? super T> elementMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(T[] actual,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(T[] actual)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(T[] actual)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<T[]>
public void describeMismatchSafely(T[] actual, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<T[]>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public class IsArray<T> +extends TypeSafeMatcher<T[]>+
Constructor and Description | +
---|
IsArray(Matcher<? super T>[] elementMatchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> IsArray<T> |
+array(Matcher<? super T>... elementMatchers)
+Creates a matcher that matches arrays whose elements are satisfied by the specified matchers.
+ |
+
void |
+describeMismatchSafely(T[] actual,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected java.lang.String |
+descriptionEnd()
+Returns the string that ends the description.
+ |
+
protected java.lang.String |
+descriptionSeparator()
+Returns the string that separates the elements in the description.
+ |
+
protected java.lang.String |
+descriptionStart()
+Returns the string that starts the description.
+ |
+
boolean |
+matchesSafely(T[] array)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(T[] array)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<T[]>
public void describeMismatchSafely(T[] actual, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<T[]>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.protected java.lang.String descriptionStart()+
protected java.lang.String descriptionSeparator()+
protected java.lang.String descriptionEnd()+
public static <T> IsArray<T> array(Matcher<? super T>... elementMatchers)+
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))
elementMatchers
- the matchers that the elements of examined arrays should satisfyArrayMatching
.@Deprecated +public class IsArrayContainingInAnyOrder<E> +extends TypeSafeMatcher<E[]>+
Constructor and Description | +
---|
IsArrayContainingInAnyOrder(java.util.Collection<Matcher<? super E>> matchers)
+Deprecated.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> Matcher<E[]> |
+arrayContainingInAnyOrder(java.util.Collection<Matcher<? super E>> itemMatchers)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContainingInAnyOrder(Collection) . |
+
static <E> Matcher<E[]> |
+arrayContainingInAnyOrder(E... items)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContainingInAnyOrder(Object[]) . |
+
static <E> Matcher<E[]> |
+arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContainingInAnyOrder(Matcher[]) . |
+
void |
+describeMismatchSafely(E[] item,
+ Description mismatchDescription)
+Deprecated.
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Deprecated.
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(E[] item)
+Deprecated.
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(E[] item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<E[]>
public void describeMismatchSafely(E[] item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<E[]>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers)+
ArrayMatching.arrayContainingInAnyOrder(Matcher[])
.+ 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")))
itemMatchers
- a list of matchers, each of which must be satisfied by an entry in an examined arraypublic static <E> Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<Matcher<? super E>> itemMatchers)+
ArrayMatching.arrayContainingInAnyOrder(Collection)
.+ 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined arraypublic static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items)+
ArrayMatching.arrayContainingInAnyOrder(Object[])
.+ 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"))
items
- the items that must equal the entries of an examined array, in any orderArrayMatching
.public class IsArrayContainingInOrder<E> +extends TypeSafeMatcher<E[]>+
Constructor and Description | +
---|
IsArrayContainingInOrder(java.util.List<Matcher<? super E>> matchers)
+Deprecated.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> Matcher<E[]> |
+arrayContaining(E... items)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContaining(Object[]) . |
+
static <E> Matcher<E[]> |
+arrayContaining(java.util.List<Matcher<? super E>> itemMatchers)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContaining(List) . |
+
static <E> Matcher<E[]> |
+arrayContaining(Matcher<? super E>... itemMatchers)
+Deprecated.
+
+As of version 2.1, use
+ArrayMatching.arrayContaining(Matcher[]) . |
+
void |
+describeMismatchSafely(E[] item,
+ Description mismatchDescription)
+Deprecated.
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Deprecated.
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(E[] item)
+Deprecated.
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(E[] item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<E[]>
public void describeMismatchSafely(E[] item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<E[]>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <E> Matcher<E[]> arrayContaining(E... items)+
ArrayMatching.arrayContaining(Object[])
.+ For example: +
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
items
- the items that must equal the items within an examined arraypublic static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers)+
ArrayMatching.arrayContaining(Matcher[])
.+ For example: +
assertThat(new String[]{"foo", "bar"}, contains(equalTo("foo"), equalTo("bar")))
itemMatchers
- the matchers that must be satisfied by the items in the examined arraypublic static <E> Matcher<E[]> arrayContaining(java.util.List<Matcher<? super E>> itemMatchers)+
ArrayMatching.arrayContaining(List)
.+ For example: +
assertThat(new String[]{"foo", "bar"}, contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the corresponding item in an examined arraypublic class IsArrayWithSize<E> +extends FeatureMatcher<E[],java.lang.Integer>+
Constructor and Description | +
---|
IsArrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> Matcher<E[]> |
+arrayWithSize(int size)
+Creates a matcher for arrays that matches when the
+length of the array
+ equals the specified size . |
+
static <E> Matcher<E[]> |
+arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for arrays that matches when the
+length of the array
+ satisfies the specified matcher. |
+
static <E> Matcher<E[]> |
+emptyArray()
+Creates a matcher for arrays that matches when the
+length of the array
+ is zero. |
+
protected java.lang.Integer |
+featureValueOf(E[] actual)
+Implement this to extract the interesting feature.
+ |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsArrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
protected java.lang.Integer featureValueOf(E[] actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<E[],java.lang.Integer>
actual
- the target objectpublic static <E> Matcher<E[]> arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
length
of the array
+ satisfies the specified matcher.
+ For example:
+ assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
sizeMatcher
- a matcher for the length of an examined arraypublic static <E> Matcher<E[]> arrayWithSize(int size)+
length
of the array
+ equals the specified size
.
+ For example:
+ assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
size
- the length that an examined array must have for a positive matchpublic static <E> Matcher<E[]> emptyArray()+
length
of the array
+ is zero.
+ For example:
+ assertThat(new String[0], emptyArray())
public class IsCollectionWithSize<E> +extends FeatureMatcher<java.util.Collection<? extends E>,java.lang.Integer>+
Constructor and Description | +
---|
IsCollectionWithSize(Matcher<? super java.lang.Integer> sizeMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
protected java.lang.Integer |
+featureValueOf(java.util.Collection<? extends E> actual)
+Implement this to extract the interesting feature.
+ |
+
static <E> Matcher<java.util.Collection<? extends E>> |
+hasSize(int size)
+Creates a matcher for
+Collection s that matches when the size() method returns
+ a value equal to the specified size . |
+
static <E> Matcher<java.util.Collection<? extends E>> |
+hasSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Collection s that matches when the size() method returns
+ a value that satisfies the specified matcher. |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsCollectionWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
protected java.lang.Integer featureValueOf(java.util.Collection<? extends E> actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<java.util.Collection<? extends E>,java.lang.Integer>
actual
- the target objectpublic static <E> Matcher<java.util.Collection<? extends E>> hasSize(Matcher<? super java.lang.Integer> sizeMatcher)+
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)))
sizeMatcher
- a matcher for the size of an examined Collection
public static <E> Matcher<java.util.Collection<? extends E>> hasSize(int size)+
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))
size
- the expected size of an examined Collection
public class IsEmptyCollection<E> +extends TypeSafeMatcher<java.util.Collection<? extends E>>+
Constructor and Description | +
---|
IsEmptyCollection() |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.util.Collection<? extends E> item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <E> Matcher<java.util.Collection<? extends E>> |
+empty()
+Creates a matcher for
+Collection s matching examined collections whose isEmpty
+ method returns true . |
+
static <E> Matcher<java.util.Collection<E>> |
+emptyCollectionOf(java.lang.Class<E> unusedToForceReturnType)
+Creates a matcher for
+Collection s matching examined collections whose isEmpty
+ method returns true . |
+
boolean |
+matchesSafely(java.util.Collection<? extends E> item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.util.Collection<? extends E> item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.util.Collection<? extends E>>
public void describeMismatchSafely(java.util.Collection<? extends E> item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.util.Collection<? extends E>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <E> Matcher<java.util.Collection<? extends E>> empty()+
Collection
s matching examined collections whose isEmpty
+ method returns true
.
+ For example:
+ assertThat(new ArrayList<String>(), is(empty()))
public static <E> Matcher<java.util.Collection<E>> emptyCollectionOf(java.lang.Class<E> unusedToForceReturnType)+
Collection
s matching examined collections whose isEmpty
+ method returns true
.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
unusedToForceReturnType
- the type of the collection's contentpublic class IsEmptyIterable<E> +extends TypeSafeMatcher<java.lang.Iterable<? extends E>>+
Constructor and Description | +
---|
IsEmptyIterable() |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.Iterable<? extends E> iter,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+emptyIterable()
+Creates a matcher for
+Iterable s matching examined iterables that yield no items. |
+
static <E> Matcher<java.lang.Iterable<E>> |
+emptyIterableOf(java.lang.Class<E> unusedToForceReturnType)
+Creates a matcher for
+Iterable s matching examined iterables that yield no items. |
+
boolean |
+matchesSafely(java.lang.Iterable<? extends E> iterable)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.lang.Iterable<? extends E> iterable)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.Iterable<? extends E>>
public void describeMismatchSafely(java.lang.Iterable<? extends E> iter, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.Iterable<? extends E>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <E> Matcher<java.lang.Iterable<? extends E>> emptyIterable()+
Iterable
s matching examined iterables that yield no items.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyIterable()))
public static <E> Matcher<java.lang.Iterable<E>> emptyIterableOf(java.lang.Class<E> unusedToForceReturnType)+
Iterable
s matching examined iterables that yield no items.
+ For example:
+ assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
unusedToForceReturnType
- the type of the iterable's contentpublic class IsIn<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
IsIn(java.util.Collection<T> collection) |
+
IsIn(T[] elements) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description buffer)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+in(java.util.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> |
+isIn(java.util.Collection<T> collection)
+Deprecated.
+
+use is(in(...)) instead
+ |
+
static <T> Matcher<T> |
+isIn(T[] elements)
+Deprecated.
+
+use is(in(...)) instead
+ |
+
static <T> Matcher<T> |
+isOneOf(T... elements)
+Deprecated.
+
+use is(oneOf(...)) instead
+ |
+
boolean |
+matches(java.lang.Object o)
+Evaluates the matcher for argument item.
+ |
+
static <T> Matcher<T> |
+oneOf(T... elements)
+Creates a matcher that matches when the examined object is equal to one of the
+ specified elements.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsIn(java.util.Collection<T> collection)+
public IsIn(T[] elements)+
public boolean matches(java.lang.Object o)+
Matcher
o
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description buffer)+
SelfDescribing
buffer
- The description to be built or appended to.@Deprecated +public static <T> Matcher<T> isIn(java.util.Collection<T> collection)+
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
collection
- the collection in which matching items must be foundpublic static <T> Matcher<T> in(java.util.Collection<T> collection)+
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
collection
- the collection in which matching items must be found@Deprecated +public static <T> Matcher<T> isIn(T[] elements)+
assertThat("foo", isIn(new String[]{"bar", "foo"}))
elements
- the array in which matching items must be foundpublic static <T> Matcher<T> in(T[] elements)+
assertThat("foo", is(in(new String[]{"bar", "foo"})))
elements
- the array in which matching items must be found@SafeVarargs + @Deprecated +public static <T> Matcher<T> isOneOf(T... elements)+
assertThat("foo", isOneOf("bar", "foo"))
elements
- the elements amongst which matching items will be found@SafeVarargs +public static <T> Matcher<T> oneOf(T... elements)+
assertThat("foo", is(oneOf("bar", "foo")))
elements
- the elements amongst which matching items will be foundpublic class IsIterableContainingInAnyOrder<T> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends T>>+
Constructor and Description | +
---|
IsIterableContainingInAnyOrder(java.util.Collection<Matcher<? super T>> matchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(java.util.Collection<Matcher<? super T>> itemMatchers)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers. |
+
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(Matcher<? super T>... itemMatchers)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each satisfying one matcher anywhere
+ in the specified matchers. |
+
static <T> Matcher<java.lang.Iterable<? extends T>> |
+containsInAnyOrder(T... items)
+
+ Creates an order agnostic matcher for
+Iterable s that matches when a single pass over
+ the examined Iterable yields a series of items, each logically equal to one item
+ anywhere in the specified items. |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected boolean |
+matchesSafely(java.lang.Iterable<? extends T> items,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(java.lang.Iterable<? extends T> items, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends T>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.@SafeVarargs +public static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined 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")))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(T... items)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each logically equal to one item
+ anywhere in the specified items. 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"))
items
- the items that must equal the items provided by an examined Iterable
in any orderpublic static <T> Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(java.util.Collection<Matcher<? super T>> itemMatchers)+
+ Creates an order agnostic matcher for Iterable
s that matches when a single pass over
+ the examined Iterable
yields a series of items, each satisfying one matcher anywhere
+ in the specified collection of matchers. 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by an item provided by an examined Iterable
public class IsIterableContainingInOrder<E> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>>+
Constructor and Description | +
---|
IsIterableContainingInOrder(java.util.List<Matcher<? super E>> matchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(E... items)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each logically equal to the
+ corresponding item in the specified items. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(java.util.List<Matcher<? super E>> itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(Matcher<? super E>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, each satisfying the corresponding
+ matcher in the specified matchers. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+contains(Matcher<? super E> itemMatcher)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a single item that satisfies the specified matcher. |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected boolean |
+matchesSafely(java.lang.Iterable<? extends E> iterable,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(java.lang.Iterable<? extends E> iterable, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> contains(E... items)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each logically equal to the
+ corresponding item in the specified items. 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"))
items
- the items that must equal the items provided by an examined Iterable
public static <E> Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E> itemMatcher)+
Iterable
s that matches when a single pass over the
+ examined 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")))
itemMatcher
- the matcher that must be satisfied by the single item provided by an
+ examined Iterable
@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined 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")))
itemMatchers
- the matchers that must be satisfied by the items provided by an examined Iterable
public static <E> Matcher<java.lang.Iterable<? extends E>> contains(java.util.List<Matcher<? super E>> itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields a series of items, each satisfying the corresponding
+ matcher in the specified list of matchers. 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the corresponding item provided by
+ an examined Iterable
public class IsIterableContainingInRelativeOrder<E> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>>+
Constructor and Description | +
---|
IsIterableContainingInRelativeOrder(java.util.List<Matcher<? super E>> matchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(E... items)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that contains items logically equal to the
+ corresponding item in the specified items, in the same relative order
+ For example: |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(java.util.List<Matcher<? super E>> itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that contains items satisfying the corresponding
+ matcher in the specified list of matchers, in the same relative order. |
+
static <E> Matcher<java.lang.Iterable<? extends E>> |
+containsInRelativeOrder(Matcher<? super E>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields a series of items, that each satisfying the corresponding
+ matcher in the specified matchers, in the same relative order. |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected boolean |
+matchesSafely(java.lang.Iterable<? extends E> iterable,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(java.lang.Iterable<? extends E> iterable, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends E>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(E... items)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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"))
items
- the items that must be contained within items provided by an examined Iterable
in the same relative order@SafeVarargs +public static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(Matcher<? super E>... itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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")))
itemMatchers
- the matchers that must be satisfied by the items provided by an examined Iterable
in the same relative orderpublic static <E> Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(java.util.List<Matcher<? super E>> itemMatchers)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields 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"))))
itemMatchers
- a list of matchers, each of which must be satisfied by the items provided by
+ an examined Iterable
in the same relative orderpublic class IsIterableWithSize<E> +extends FeatureMatcher<java.lang.Iterable<E>,java.lang.Integer>+
Constructor and Description | +
---|
IsIterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
protected java.lang.Integer |
+featureValueOf(java.lang.Iterable<E> actual)
+Implement this to extract the interesting feature.
+ |
+
static <E> Matcher<java.lang.Iterable<E>> |
+iterableWithSize(int size)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields an item count that is equal to the specified
+ size argument. |
+
static <E> Matcher<java.lang.Iterable<E>> |
+iterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Iterable s that matches when a single pass over the
+ examined Iterable yields an item count that satisfies the specified
+ matcher. |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsIterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
protected java.lang.Integer featureValueOf(java.lang.Iterable<E> actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<java.lang.Iterable<E>,java.lang.Integer>
actual
- the target objectpublic static <E> Matcher<java.lang.Iterable<E>> iterableWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that satisfies the specified
+ matcher.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
sizeMatcher
- a matcher for the number of items that should be yielded by an examined Iterable
public static <E> Matcher<java.lang.Iterable<E>> iterableWithSize(int size)+
Iterable
s that matches when a single pass over the
+ examined Iterable
yields an item count that is equal to the specified
+ size
argument.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
size
- the number of items that should be yielded by an examined Iterable
public class IsMapContaining<K,V> +extends TypeSafeMatcher<java.util.Map<? extends K,? extends V>>+
Constructor and Description | +
---|
IsMapContaining(Matcher<? super K> keyMatcher,
+ Matcher<? super V> valueMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.util.Map<? extends K,? extends V> map,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+hasEntry(K key,
+ V value)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one entry whose key equals the specified key and whose value equals the
+ specified value . |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+hasEntry(Matcher<? super K> keyMatcher,
+ Matcher<? super V> valueMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one entry whose key satisfies the specified keyMatcher and whose
+ value satisfies the specified valueMatcher . |
+
static <K> Matcher<java.util.Map<? extends K,?>> |
+hasKey(K key)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one key that is equal to the specified key. |
+
static <K> Matcher<java.util.Map<? extends K,?>> |
+hasKey(Matcher<? super K> keyMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one key that satisfies the specified matcher. |
+
static <V> Matcher<java.util.Map<?,? extends V>> |
+hasValue(Matcher<? super V> valueMatcher)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one value that satisfies the specified valueMatcher. |
+
static <V> Matcher<java.util.Map<?,? extends V>> |
+hasValue(V value)
+Creates a matcher for
+Map s matching when the examined Map contains
+ at least one value that is equal to the specified value. |
+
boolean |
+matchesSafely(java.util.Map<? extends K,? extends V> map)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.util.Map<? extends K,? extends V> map)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.util.Map<? extends K,? extends V>>
public void describeMismatchSafely(java.util.Map<? extends K,? extends V> map, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.util.Map<? extends K,? extends V>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, + Matcher<? super V> valueMatcher)+
Map
s matching when the examined 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")))
keyMatcher
- the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entryvalueMatcher
- the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entrypublic static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(K key, + V value)+
Map
s matching when the examined 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"))
key
- the key that, in combination with the value, must be describe at least one entryvalue
- the value that, in combination with the key, must be describe at least one entrypublic static <K> Matcher<java.util.Map<? extends K,?>> hasKey(Matcher<? super K> keyMatcher)+
Map
s matching when the examined Map
contains
+ at least one key that satisfies the specified matcher.
+ For example:
+ assertThat(myMap, hasKey(equalTo("bar")))
keyMatcher
- the matcher that must be satisfied by at least one keypublic static <K> Matcher<java.util.Map<? extends K,?>> hasKey(K key)+
Map
s matching when the examined Map
contains
+ at least one key that is equal to the specified key.
+ For example:
+ assertThat(myMap, hasKey("bar"))
key
- the key that satisfying maps must containpublic static <V> Matcher<java.util.Map<?,? extends V>> hasValue(Matcher<? super V> valueMatcher)+
Map
s matching when the examined Map
contains
+ at least one value that satisfies the specified valueMatcher.
+ For example:
+ assertThat(myMap, hasValue(equalTo("foo")))
valueMatcher
- the matcher that must be satisfied by at least one valuepublic static <V> Matcher<java.util.Map<?,? extends V>> hasValue(V value)+
Map
s matching when the examined Map
contains
+ at least one value that is equal to the specified value.
+ For example:
+ assertThat(myMap, hasValue("foo"))
value
- the value that satisfying maps must containpublic final class IsMapWithSize<K,V> +extends FeatureMatcher<java.util.Map<? extends K,? extends V>,java.lang.Integer>+
Constructor and Description | +
---|
IsMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+aMapWithSize(int size)
+Creates a matcher for
+Map s that matches when the size() method returns
+ a value equal to the specified size . |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+aMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
+Creates a matcher for
+Map s that matches when the size() method returns
+ a value that satisfies the specified matcher. |
+
static <K,V> Matcher<java.util.Map<? extends K,? extends V>> |
+anEmptyMap()
+Creates a matcher for
+Map s that matches when the size() method returns
+ zero. |
+
protected java.lang.Integer |
+featureValueOf(java.util.Map<? extends K,? extends V> actual)
+Implement this to extract the interesting feature.
+ |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
protected java.lang.Integer featureValueOf(java.util.Map<? extends K,? extends V> actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<java.util.Map<? extends K,? extends V>,java.lang.Integer>
actual
- the target objectpublic static <K,V> Matcher<java.util.Map<? extends K,? extends V>> aMapWithSize(Matcher<? super java.lang.Integer> sizeMatcher)+
Map
s that matches when the size()
method returns
+ a value that satisfies the specified matcher.
+ For example:
+ assertThat(myMap, is(aMapWithSize(equalTo(2))))
sizeMatcher
- a matcher for the size of an examined Map
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> aMapWithSize(int size)+
Map
s that matches when the size()
method returns
+ a value equal to the specified size
.
+ For example:
+ assertThat(myMap, is(aMapWithSize(2)))
size
- the expected size of an examined Map
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> anEmptyMap()+
Map
s that matches when the size()
method returns
+ zero.
+ For example:
+ assertThat(myMap, is(anEmptyMap()))
Class | +Description | +
---|---|
ArrayAsIterableMatcher<E> | ++ |
ArrayMatching | ++ |
HasItemInArray<T> | +
+ Matches if an array contains an item satisfying a nested matcher.
+ |
+
IsArray<T> | +
+ Matcher for array whose elements satisfy a sequence of matchers.
+ |
+
IsArrayContainingInAnyOrder<E> | +Deprecated
+ As of release 2.1, replaced by
+ArrayMatching . |
+
IsArrayContainingInOrder<E> | +Deprecated
+ As of release 2.1, replaced by
+ArrayMatching . |
+
IsArrayWithSize<E> | +
+ Matches if array size satisfies a nested matcher.
+ |
+
IsCollectionWithSize<E> | +
+ Matches if collection size satisfies a nested matcher.
+ |
+
IsEmptyCollection<E> | +
+ Tests if collection is empty.
+ |
+
IsEmptyIterable<E> | +
+ Tests if collection is empty.
+ |
+
IsIn<T> | ++ |
IsIterableContainingInAnyOrder<T> | ++ |
IsIterableContainingInOrder<E> | ++ |
IsIterableContainingInRelativeOrder<E> | ++ |
IsIterableWithSize<E> | ++ |
IsMapContaining<K,V> | ++ |
IsMapWithSize<K,V> | +
+ Matches if map size satisfies a nested matcher.
+ |
+
Matchers of arrays and collections.
public final class ComparatorMatcherBuilder<T>
+extends java.lang.Object
+Modifier and Type | +Method and Description | +
---|---|
static <T> ComparatorMatcherBuilder<T> |
+comparedBy(java.util.Comparator<T> comparator)
+Creates a matcher factory for matchers of
+Comparators s of T . |
+
Matcher<T> |
+comparesEqualTo(T value)
+Creates a matcher of
+T object that matches when the examined object is
+ equal to the specified value, as reported by the Comparator used to
+ create this builder. |
+
Matcher<T> |
+greaterThan(T value)
+Creates a matcher of
+T object that matches when the examined object is
+ greater than the specified value, as reported by the Comparator used to
+ create this builder. |
+
Matcher<T> |
+greaterThanOrEqualTo(T value)
+Creates a matcher of
+T object that matches when the examined object is
+ greater than or equal to the specified value, as reported by the Comparator used to
+ create this builder. |
+
Matcher<T> |
+lessThan(T value)
+Creates a matcher of
+T object that matches when the examined object is
+ less than the specified value, as reported by the Comparator used to
+ create this builder. |
+
Matcher<T> |
+lessThanOrEqualTo(T value)
+Creates a matcher of
+T object that matches when the examined object is
+ less than or equal to the specified value, as reported by the Comparator used to
+ create this builder. |
+
static <T extends java.lang.Comparable<T>> |
+usingNaturalOrdering()
+Creates a matcher factory for matchers of
+Comparable s. |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T extends java.lang.Comparable<T>> ComparatorMatcherBuilder<T> usingNaturalOrdering()+
Comparable
s.
+ For example:
+ assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
public static <T> ComparatorMatcherBuilder<T> comparedBy(java.util.Comparator<T> comparator)+
Comparators
s of T
.
+ For example:
+ assertThat(5, comparedBy(new Comparator<Integer>() { + public int compare(Integer o1, Integer o2) { + return -o1.compareTo(o2); + } + }).lessThan(4))
public Matcher<T> comparesEqualTo(T value)+
T
object that matches when the examined object is
+ equal to the specified value, as reported by the Comparator
used to
+ create this builder.
+ For example:
+ assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().comparesEqualTo(1))
value
- the value which, when passed to the Comparator supplied to this builder, should return zeropublic Matcher<T> greaterThan(T value)+
T
object that matches when the examined object is
+ greater than the specified value, as reported by the Comparator
used to
+ create this builder.
+ For example:
+ assertThat(2, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().greaterThan(1))
value
- the value which, when passed to the Comparator supplied to this builder, should return greater
+ than zeropublic Matcher<T> greaterThanOrEqualTo(T value)+
T
object that matches when the examined object is
+ greater than or equal to the specified value, as reported by the Comparator
used to
+ create this builder.
+ For example:
+ assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().greaterThanOrEqualTo(1))
value
- the value which, when passed to the Comparator supplied to this builder, should return greater
+ than or equal to zeropublic Matcher<T> lessThan(T value)+
T
object that matches when the examined object is
+ less than the specified value, as reported by the Comparator
used to
+ create this builder.
+ For example:
+ assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThan(2))
value
- the value which, when passed to the Comparator supplied to this builder, should return less
+ than zeropublic Matcher<T> lessThanOrEqualTo(T value)+
T
object that matches when the examined object is
+ less than or equal to the specified value, as reported by the Comparator
used to
+ create this builder.
+ For example:
+ assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
value
- the value which, when passed to the Comparator supplied to this builder, should return less
+ than or equal to zeroClass | +Description | +
---|---|
ComparatorMatcherBuilder<T> | ++ |
public class AllOf<T> +extends DiagnosingMatcher<T>+
false
.Constructor and Description | +
---|
AllOf(java.lang.Iterable<Matcher<? super T>> matchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<T> |
+allOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ALL of the specified matchers.
+ |
+
static <T> Matcher<T> |
+allOf(Matcher<? super T>... matchers)
+Creates a matcher that matches if the examined object matches ALL of the specified matchers.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object o,
+ Description mismatch) |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object o, + Description mismatch)+
matches
in class DiagnosingMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> allOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
public class AnyOf<T> +extends BaseMatcher<T>+
true
.Constructor and Description | +
---|
AnyOf(java.lang.Iterable<Matcher<? super T>> matchers) |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> AnyOf<T> |
+anyOf(java.lang.Iterable<Matcher<? super T>> matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
static <T> AnyOf<T> |
+anyOf(Matcher<? super T>... matchers)
+Creates a matcher that matches if the examined object matches ANY of the specified matchers.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
void |
+describeTo(Description description,
+ java.lang.String operator) |
+
boolean |
+matches(java.lang.Object o)
+Evaluates the matcher for argument item.
+ |
+
protected boolean |
+matches(java.lang.Object o,
+ boolean shortcut) |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object o)+
Matcher
matches
in interface Matcher<T>
o
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
describeTo
in interface SelfDescribing
description
- The description to be built or appended to.public static <T> AnyOf<T> anyOf(java.lang.Iterable<Matcher<? super T>> matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
@SafeVarargs +public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers)+
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
protected boolean matches(java.lang.Object o, + boolean shortcut)+
public void describeTo(Description description, + java.lang.String operator)+
public static final class CombinableMatcher.CombinableBothMatcher<X>
+extends java.lang.Object
+Constructor and Description | +
---|
CombinableBothMatcher(Matcher<? super X> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
CombinableMatcher<X> |
+and(Matcher<? super X> other) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final class CombinableMatcher.CombinableEitherMatcher<X>
+extends java.lang.Object
+Constructor and Description | +
---|
CombinableEitherMatcher(Matcher<? super X> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
CombinableMatcher<X> |
+or(Matcher<? super X> other) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public class CombinableMatcher<T> +extends TypeSafeDiagnosingMatcher<T>+
Modifier and Type | +Class and Description | +
---|---|
static class |
+CombinableMatcher.CombinableBothMatcher<X> |
+
static class |
+CombinableMatcher.CombinableEitherMatcher<X> |
+
Constructor and Description | +
---|
CombinableMatcher(Matcher<? super T> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
CombinableMatcher<T> |
+and(Matcher<? super T> other) |
+
static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> |
+both(Matcher<? super LHS> matcher)
+Creates a matcher that matches when both of the specified matchers match the examined object.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
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.
+ |
+
protected boolean |
+matchesSafely(T item,
+ Description mismatch)
+Subclasses should implement this.
+ |
+
CombinableMatcher<T> |
+or(Matcher<? super T> other) |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(T item, + Description mismatch)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public CombinableMatcher<T> and(Matcher<? super T> other)+
public CombinableMatcher<T> or(Matcher<? super T> other)+
public static <LHS> CombinableMatcher.CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher)+
assertThat("fab", both(containsString("a")).and(containsString("b")))
public static <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher)+
assertThat("fan", either(containsString("a")).or(containsString("b")))
public class DescribedAs<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
DescribedAs(java.lang.String descriptionTemplate,
+ Matcher<T> matcher,
+ java.lang.Object[] values) |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<T> |
+describedAs(java.lang.String description,
+ Matcher<T> matcher,
+ java.lang.Object... values)
+Wraps an existing matcher, overriding its description with that specified.
+ |
+
void |
+describeMismatch(java.lang.Object item,
+ Description description)
+Generate a description of why the matcher has not accepted the item.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object o)
+Evaluates the matcher for argument item.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object o)+
Matcher
o
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public void describeMismatch(java.lang.Object item, + Description description)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
describeMismatch
in class BaseMatcher<T>
item
- The item that the Matcher has rejected.description
- The description to be built or appended to.public static <T> Matcher<T> describedAs(java.lang.String description, + Matcher<T> matcher, + java.lang.Object... values)+
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
description
- the new description for the wrapped matchermatcher
- the matcher to wrapvalues
- optional values to insert into the tokenised descriptionpublic class Every<T> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends T>>+
Constructor and Description | +
---|
Every(Matcher<? super T> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <U> Matcher<java.lang.Iterable<? extends U>> |
+everyItem(Matcher<U> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields items that are all matched by the specified
+ itemMatcher . |
+
boolean |
+matchesSafely(java.lang.Iterable<? extends T> collection,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.lang.Iterable<? extends T> collection, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? extends T>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <U> Matcher<java.lang.Iterable<? extends U>> everyItem(Matcher<U> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields items that are all matched by the specified
+ itemMatcher
.
+ For example:
+ assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
itemMatcher
- the matcher to apply to every item provided by the examined Iterable
public class Is<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
Is(Matcher<T> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatch(java.lang.Object item,
+ Description mismatchDescription)
+Generate a description of why the matcher has not accepted the item.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+is(Matcher<T> matcher)
+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 used
+is(equalTo(x)) . |
+
static <T> Matcher<T> |
+isA(java.lang.Class<?> type)
+A shortcut to the frequently used
+is(instanceOf(SomeClass.class)) . |
+
boolean |
+matches(java.lang.Object arg)
+Evaluates the matcher for argument item.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object arg)+
Matcher
arg
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public void describeMismatch(java.lang.Object item, + Description mismatchDescription)+
Matcher
matches(item)
is false, but
+ will not check this.describeMismatch
in interface Matcher<T>
describeMismatch
in class BaseMatcher<T>
item
- The item that the Matcher has rejected.mismatchDescription
- The description to be built or appended to.public static <T> Matcher<T> is(Matcher<T> matcher)+
assertThat(cheese, is(equalTo(smelly)))+ instead of: +
assertThat(cheese, equalTo(smelly))
public static <T> Matcher<T> is(T value)+
is(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(smelly))+ instead of: +
assertThat(cheese, is(equalTo(smelly)))
public static <T> Matcher<T> isA(java.lang.Class<?> type)+
is(instanceOf(SomeClass.class))
.
+ For example:
+ assertThat(cheese, isA(Cheddar.class))+ instead of: +
assertThat(cheese, is(instanceOf(Cheddar.class)))
public class IsAnything<T> +extends BaseMatcher<T>+
true
.Constructor and Description | +
---|
IsAnything() |
+
IsAnything(java.lang.String message) |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.lang.Object> |
+anything()
+Creates a matcher that always matches, regardless of the examined object.
+ |
+
static Matcher<java.lang.Object> |
+anything(java.lang.String description)
+Creates a matcher that always matches, regardless of the examined object, but describes
+ itself with the specified
+String . |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object o)
+Evaluates the matcher for argument item.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsAnything()+
public IsAnything(java.lang.String message)+
public boolean matches(java.lang.Object o)+
Matcher
o
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.Object> anything()+
public static Matcher<java.lang.Object> anything(java.lang.String description)+
String
.description
- a meaningful String
used when describing itselfIsIterableContaining
.@Deprecated +public class IsCollectionContaining<T> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? super T>>+
Constructor and Description | +
---|
IsCollectionContaining(Matcher<? super T> elementMatcher)
+Deprecated.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Deprecated.
+Generates a description of the object.
+ |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(Matcher<? super T> itemMatcher)
+Deprecated.
+
+As of version 2.1, use
+IsIterableContaining.hasItem(Matcher) . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(T item)
+Deprecated.
+
+As of version 2.1, use
+IsIterableContaining.hasItem(Object) . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(Matcher<? super T>... itemMatchers)
+Deprecated.
+
+As of version 2.1, use
+IsIterableContaining.hasItems(Matcher[]) }. |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(T... items)
+Deprecated.
+
+As of version 2.1, use
+IsIterableContaining.hasItems(Object[]) }. |
+
protected boolean |
+matchesSafely(java.lang.Iterable<? super T> collection,
+ Description mismatchDescription)
+Deprecated.
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(java.lang.Iterable<? super T> collection, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? super T>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)+
IsIterableContaining.hasItem(Matcher)
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
itemMatcher
- the matcher to apply to items provided by the examined Iterable
public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(T item)+
IsIterableContaining.hasItem(Object)
.Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
item
- the item to compare against the items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(Matcher<? super T>... itemMatchers)+
IsIterableContaining.hasItems(Matcher[])
}.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
. Whilst matching, each traversal of
+ the examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
itemMatchers
- the matchers to apply to items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(T... items)+
IsIterableContaining.hasItems(Object[])
}.Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
. Whilst matching, each traversal of the
+ examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
items
- the items to compare against the items provided by the examined Iterable
public class IsEqual<T> +extends BaseMatcher<T>+
Object.equals(java.lang.Object)
invokedMethod?Constructor and Description | +
---|
IsEqual(T equalArg) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+equalTo(T operand)
+Creates a matcher that matches when the examined object is logically equal to the specified
+
+operand , as determined by calling the Object.equals(java.lang.Object) method on
+ the examined object. |
+
static Matcher<java.lang.Object> |
+equalToObject(java.lang.Object operand)
+Creates an
+IsEqual matcher that does not enforce the values being
+ compared to be of the same static type. |
+
boolean |
+matches(java.lang.Object actualValue)
+Evaluates the matcher for argument item.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object actualValue)+
Matcher
actualValue
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> equalTo(T operand)+
operand
, as determined by calling the Object.equals(java.lang.Object)
method on
+ the examined object.
+
+ If the specified operand is null
then the created matcher will only match if
+ the examined object's equals
method returns true
when passed a
+ null
(which would be a violation of the equals
contract), unless the
+ examined object itself is null
, in which case the matcher will return a positive
+ match.
The created matcher provides a special behaviour when examining Array
s, whereby
+ it will match if both the operand and the examined object are arrays of the same length and
+ contain items that are equal to each other (according to the above rules) in the same
+ indexes.
+ assertThat("foo", equalTo("foo")); + assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"})); +
public class IsInstanceOf +extends DiagnosingMatcher<java.lang.Object>+
Constructor and Description | +
---|
IsInstanceOf(java.lang.Class<?> expectedClass)
+Creates a new instance of IsInstanceOf
+ |
+
Modifier and Type | +Method and Description | +
---|---|
static <T> Matcher<T> |
+any(java.lang.Class<T> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<T> |
+instanceOf(java.lang.Class<?> type)
+Creates a matcher that matches when the examined object is an instance of the specified
+type ,
+ as determined by calling the Class.isInstance(Object) method on that type, passing the
+ the examined object. |
+
protected boolean |
+matches(java.lang.Object item,
+ Description mismatch) |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsInstanceOf(java.lang.Class<?> expectedClass)+
expectedClass
- The predicate evaluates to true for instances of this class
+ or one of its subclasses.protected boolean matches(java.lang.Object item, + Description mismatch)+
matches
in class DiagnosingMatcher<java.lang.Object>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> instanceOf(java.lang.Class<?> type)+
type
,
+ as determined by calling the 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 <T> Matcher<T> any(java.lang.Class<T> type)+
type
,
+ as determined by calling the Class.isInstance(Object)
method on that type, passing the
+ the examined object.
+
+ The created matcher forces a relationship between specified type and the examined object, and should be
+ used when it is necessary to make generics conform, for example in the JMock clause
+ with(any(Thing.class))
assertThat(new Canoe(), instanceOf(Canoe.class));
public class IsIterableContaining<T> +extends TypeSafeDiagnosingMatcher<java.lang.Iterable<? super T>>+
Constructor and Description | +
---|
IsIterableContaining(Matcher<? super T> elementMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(Matcher<? super T> itemMatcher)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is matched by the specified
+ itemMatcher . |
+
static <T> Matcher<java.lang.Iterable<? super T>> |
+hasItem(T item)
+Creates a matcher for
+Iterable s that only matches when a single pass over the
+ examined Iterable yields at least one item that is equal to the specified
+ item . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(Matcher<? super T>... itemMatchers)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers . |
+
static <T> Matcher<java.lang.Iterable<T>> |
+hasItems(T... items)
+Creates a matcher for
+Iterable s that matches when consecutive passes over the
+ examined Iterable yield at least one item that is equal to the corresponding
+ item from the specified items . |
+
protected boolean |
+matchesSafely(java.lang.Iterable<? super T> collection,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected boolean matchesSafely(java.lang.Iterable<? super T> collection, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.Iterable<? super T>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is matched by the specified
+ itemMatcher
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
itemMatcher
- the matcher to apply to items provided by the examined Iterable
public static <T> Matcher<java.lang.Iterable<? super T>> hasItem(T item)+
Iterable
s that only matches when a single pass over the
+ examined Iterable
yields at least one item that is equal to the specified
+ item
. Whilst matching, the traversal of the examined Iterable
+ will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
item
- the item to compare against the items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(Matcher<? super T>... itemMatchers)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is matched by the corresponding
+ matcher from the specified itemMatchers
. Whilst matching, each traversal of
+ the examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
itemMatchers
- the matchers to apply to items provided by the examined Iterable
@SafeVarargs +public static <T> Matcher<java.lang.Iterable<T>> hasItems(T... items)+
Iterable
s that matches when consecutive passes over the
+ examined Iterable
yield at least one item that is equal to the corresponding
+ item from the specified items
. Whilst matching, each traversal of the
+ examined Iterable
will stop as soon as a matching item is found.
+ For example:
+ assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
items
- the items to compare against the items provided by the examined Iterable
public class IsNot<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
IsNot(Matcher<T> matcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object arg)
+Evaluates the matcher for argument item.
+ |
+
static <T> Matcher<T> |
+not(Matcher<T> matcher)
+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 used
+not(equalTo(x)) . |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object arg)+
Matcher
arg
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> not(Matcher<T> matcher)+
assertThat(cheese, is(not(equalTo(smelly))))
matcher
- the matcher whose sense should be invertedpublic static <T> Matcher<T> not(T value)+
not(equalTo(x))
.
+ For example:
+ assertThat(cheese, is(not(smelly)))+ instead of: +
assertThat(cheese, is(not(equalTo(smelly))))
value
- the value that any examined object should not equalpublic class IsNull<T> +extends BaseMatcher<T>+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object o)
+Evaluates the matcher for argument item.
+ |
+
static Matcher<java.lang.Object> |
+notNullValue()
+A shortcut to the frequently used
+not(nullValue()) . |
+
static <T> Matcher<T> |
+notNullValue(java.lang.Class<T> type)
+A shortcut to the frequently used
+not(nullValue(X.class)). |
+
static Matcher<java.lang.Object> |
+nullValue()
+Creates a matcher that matches if examined object is
+null . |
+
static <T> Matcher<T> |
+nullValue(java.lang.Class<T> type)
+Creates a matcher that matches if examined object is
+null . |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object o)+
Matcher
o
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.Object> nullValue()+
null
.
+ For example:
+ assertThat(cheese, is(nullValue())
public static Matcher<java.lang.Object> notNullValue()+
not(nullValue())
.
+ For example:
+ assertThat(cheese, is(notNullValue()))+ instead of: +
assertThat(cheese, is(not(nullValue())))
public static <T> Matcher<T> nullValue(java.lang.Class<T> type)+
null
. Accepts a
+ single dummy argument to facilitate type inference.
+ For example:
+ assertThat(cheese, is(nullValue(Cheese.class))
type
- dummy parameter used to infer the generic type of the returned matcherpublic static <T> Matcher<T> notNullValue(java.lang.Class<T> type)+
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))))
type
- dummy parameter used to infer the generic type of the returned matcherpublic class IsSame<T> +extends BaseMatcher<T>+
Constructor and Description | +
---|
IsSame(T object) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matches(java.lang.Object arg)
+Evaluates the matcher for argument item.
+ |
+
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 <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.
+ |
+
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matches(java.lang.Object arg)+
Matcher
arg
- the object against which the matcher is evaluated.true
if item matches, otherwise false
.BaseMatcher
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<T> sameInstance(T target)+
target
- the target instance against which others should be assessedpublic static <T> Matcher<T> theInstance(T target)+
target
- the target instance against which others should be assessedpublic class StringContains +extends SubstringMatcher+
substring
Constructor and Description | +
---|
StringContains(boolean ignoringCase,
+ java.lang.String substring) |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.lang.String> |
+containsString(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere. |
+
static Matcher<java.lang.String> |
+containsStringIgnoringCase(java.lang.String substring)
+Creates a matcher that matches if the examined
+String contains the specified
+ String anywhere, ignoring case. |
+
protected boolean |
+evalSubstringOf(java.lang.String s) |
+
converted, describeMismatchSafely, describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public StringContains(boolean ignoringCase, + java.lang.String substring)+
protected boolean evalSubstringOf(java.lang.String s)+
evalSubstringOf
in class SubstringMatcher
public static Matcher<java.lang.String> containsString(java.lang.String substring)+
String
contains the specified
+ String
anywhere.
+ For example:
+ assertThat("myStringOfNote", containsString("ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic static Matcher<java.lang.String> containsStringIgnoringCase(java.lang.String substring)+
String
contains the specified
+ String
anywhere, ignoring case.
+ For example:
+ assertThat("myStringOfNote", containsStringIgnoringCase("Ring"))
substring
- the substring that the returned matcher will expect to find within any examined stringpublic class StringEndsWith +extends SubstringMatcher+
substring
Constructor and Description | +
---|
StringEndsWith(boolean ignoringCase,
+ java.lang.String substring) |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.lang.String> |
+endsWith(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String . |
+
static Matcher<java.lang.String> |
+endsWithIgnoringCase(java.lang.String suffix)
+Creates a matcher that matches if the examined
+String ends with the specified
+ String , ignoring case. |
+
protected boolean |
+evalSubstringOf(java.lang.String s) |
+
converted, describeMismatchSafely, describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public StringEndsWith(boolean ignoringCase, + java.lang.String substring)+
protected boolean evalSubstringOf(java.lang.String s)+
evalSubstringOf
in class SubstringMatcher
public static Matcher<java.lang.String> endsWith(java.lang.String suffix)+
String
ends with the specified
+ String
.
+ For example:
+ assertThat("myStringOfNote", endsWith("Note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringpublic static Matcher<java.lang.String> endsWithIgnoringCase(java.lang.String suffix)+
String
ends with the specified
+ String
, ignoring case.
+ For example:
+ assertThat("myStringOfNote", endsWithIgnoringCase("note"))
suffix
- the substring that the returned matcher will expect at the end of any examined stringpublic class StringRegularExpression +extends TypeSafeDiagnosingMatcher<java.lang.String>+
Modifier | +Constructor and Description | +
---|---|
protected |
+StringRegularExpression(java.util.regex.Pattern pattern) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.lang.String> |
+matchesRegex(java.util.regex.Pattern pattern)
+Creates a matcher that checks if the examined string matches a specified
+Pattern . |
+
static Matcher<java.lang.String> |
+matchesRegex(java.lang.String regex)
+Creates a matcher that checks if the examined string matches a specified regex.
+ |
+
protected boolean |
+matchesSafely(java.lang.String actual,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected StringRegularExpression(java.util.regex.Pattern pattern)+
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.protected boolean matchesSafely(java.lang.String actual, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.lang.String>
public static Matcher<java.lang.String> matchesRegex(java.util.regex.Pattern pattern)+
Pattern
.
+
+ + assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$")); +
pattern
- the pattern to be used.public static Matcher<java.lang.String> matchesRegex(java.lang.String regex)+
+ assertThat("abc", matchesRegex("ˆ[a-z]+$")); +
regex
- The regex to be used for the validation.public class StringStartsWith +extends SubstringMatcher+
substring
Constructor and Description | +
---|
StringStartsWith(boolean ignoringCase,
+ java.lang.String substring) |
+
Modifier and Type | +Method and Description | +
---|---|
protected boolean |
+evalSubstringOf(java.lang.String s) |
+
static Matcher<java.lang.String> |
+startsWith(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String . |
+
static Matcher<java.lang.String> |
+startsWithIgnoringCase(java.lang.String prefix)
+
+ Creates a matcher that matches if the examined
+String starts with the specified
+ String , ignoring case |
+
converted, describeMismatchSafely, describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public StringStartsWith(boolean ignoringCase, + java.lang.String substring)+
protected boolean evalSubstringOf(java.lang.String s)+
evalSubstringOf
in class SubstringMatcher
public static Matcher<java.lang.String> startsWith(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
.
+
assertThat("myStringOfNote", startsWith("my"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic static Matcher<java.lang.String> startsWithIgnoringCase(java.lang.String prefix)+
+ Creates a matcher that matches if the examined String
starts with the specified
+ String
, ignoring case
+
assertThat("myStringOfNote", startsWithIgnoringCase("My"))
prefix
- the substring that the returned matcher will expect at the start of any examined stringpublic abstract class SubstringMatcher +extends TypeSafeMatcher<java.lang.String>+
Modifier and Type | +Field and Description | +
---|---|
protected java.lang.String |
+substring |
+
Modifier | +Constructor and Description | +
---|---|
protected |
+SubstringMatcher(java.lang.String relationship,
+ boolean ignoringCase,
+ java.lang.String substring) |
+
Modifier and Type | +Method and Description | +
---|---|
protected java.lang.String |
+converted(java.lang.String arg) |
+
void |
+describeMismatchSafely(java.lang.String item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected abstract boolean |
+evalSubstringOf(java.lang.String string) |
+
boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected SubstringMatcher(java.lang.String relationship, + boolean ignoringCase, + java.lang.String substring)+
public boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeMismatchSafely(java.lang.String item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.protected java.lang.String converted(java.lang.String arg)+
protected abstract boolean evalSubstringOf(java.lang.String string)+
See: Description
+Class | +Description | +
---|---|
AllOf<T> | +
+ Calculates the logical conjunction of multiple matchers.
+ |
+
AnyOf<T> | +
+ Calculates the logical disjunction of multiple matchers.
+ |
+
CombinableMatcher<T> | ++ |
CombinableMatcher.CombinableBothMatcher<X> | ++ |
CombinableMatcher.CombinableEitherMatcher<X> | ++ |
DescribedAs<T> | +
+ Provides a custom description to another matcher.
+ |
+
Every<T> | ++ |
Is<T> | +
+ Decorates another Matcher, retaining the behaviour but allowing tests
+ to be slightly more expressive.
+ |
+
IsAnything<T> | +
+ A matcher that always returns
+true . |
+
IsCollectionContaining<T> | +Deprecated
+ As of release 2.1, replaced by
+IsIterableContaining . |
+
IsEqual<T> | +
+ Is the value equal to another value, as tested by the
+
+Object.equals(java.lang.Object) invokedMethod? |
+
IsInstanceOf | +
+ Tests whether the value is an instance of a class.
+ |
+
IsIterableContaining<T> | ++ |
IsNot<T> | +
+ Calculates the logical negation of a matcher.
+ |
+
IsNull<T> | +
+ Is the value null?
+ |
+
IsSame<T> | +
+ Is the value the same object as another value?
+ |
+
StringContains | +
+ Tests if the argument is a string that contains a specific substring.
+ |
+
StringEndsWith | +
+ Tests if the argument is a string that ends with a specific substring.
+ |
+
StringRegularExpression | ++ |
StringStartsWith | +
+ Tests if the argument is a string that starts with a specific substring.
+ |
+
SubstringMatcher | ++ |
Fundamental matchers of objects and values, and composite matchers.
public class ArrayIterator
+extends java.lang.Object
+implements java.util.Iterator<java.lang.Object>
+Constructor and Description | +
---|
ArrayIterator(java.lang.Object array) |
+
Modifier and Type | +Method and Description | +
---|---|
boolean |
+hasNext() |
+
java.lang.Object |
+next() |
+
void |
+remove() |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public ArrayIterator(java.lang.Object array)+
public boolean hasNext()+
hasNext
in interface java.util.Iterator<java.lang.Object>
public java.lang.Object next()+
next
in interface java.util.Iterator<java.lang.Object>
public void remove()+
remove
in interface java.util.Iterator<java.lang.Object>
public class NullSafety
+extends java.lang.Object
+Constructor and Description | +
---|
NullSafety() |
+
Modifier and Type | +Method and Description | +
---|---|
static <E> java.util.List<Matcher<? super E>> |
+nullSafe(Matcher<? super E>[] itemMatchers) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public class ReflectiveTypeFinder
+extends java.lang.Object
+Constructor and Description | +
---|
ReflectiveTypeFinder(java.lang.String methodName,
+ int expectedNumberOfParameters,
+ int typedParameter) |
+
Modifier and Type | +Method and Description | +
---|---|
java.lang.Class<?> |
+findExpectedType(java.lang.Class<?> fromClass) |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public class SelfDescribingValue<T> +extends java.lang.Object +implements SelfDescribing+
Constructor and Description | +
---|
SelfDescribingValue(T value) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public SelfDescribingValue(T value)+
public void describeTo(Description description)+
SelfDescribing
describeTo
in interface SelfDescribing
description
- The description to be built or appended to.public class SelfDescribingValueIterator<T> +extends java.lang.Object +implements java.util.Iterator<SelfDescribing>+
Constructor and Description | +
---|
SelfDescribingValueIterator(java.util.Iterator<T> values) |
+
Modifier and Type | +Method and Description | +
---|---|
boolean |
+hasNext() |
+
SelfDescribing |
+next() |
+
void |
+remove() |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public SelfDescribingValueIterator(java.util.Iterator<T> values)+
public boolean hasNext()+
hasNext
in interface java.util.Iterator<SelfDescribing>
public SelfDescribing next()+
next
in interface java.util.Iterator<SelfDescribing>
public void remove()+
remove
in interface java.util.Iterator<SelfDescribing>
Class | +Description | +
---|---|
ArrayIterator | ++ |
NullSafety | ++ |
ReflectiveTypeFinder | ++ |
SelfDescribingValue<T> | ++ |
SelfDescribingValueIterator<T> | ++ |
public static interface FileMatchers.FileStatus
+Modifier and Type | +Method and Description | +
---|---|
boolean |
+check(java.io.File actual) |
+
public final class FileMatchers
+extends java.lang.Object
+Modifier and Type | +Class and Description | +
---|---|
static interface |
+FileMatchers.FileStatus |
+
Modifier and Type | +Field and Description | +
---|---|
static FileMatchers.FileStatus |
+CAN_READ |
+
static FileMatchers.FileStatus |
+CAN_WRITE |
+
static FileMatchers.FileStatus |
+EXISTS |
+
static FileMatchers.FileStatus |
+IS_DIRECTORY |
+
static FileMatchers.FileStatus |
+IS_FILE |
+
Constructor and Description | +
---|
FileMatchers() |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.io.File> |
+aFileNamed(Matcher<java.lang.String> expected) |
+
static Matcher<java.io.File> |
+aFileWithAbsolutePath(Matcher<java.lang.String> expected) |
+
static Matcher<java.io.File> |
+aFileWithCanonicalPath(Matcher<java.lang.String> expected) |
+
static Matcher<java.io.File> |
+aFileWithSize(long size) |
+
static Matcher<java.io.File> |
+aFileWithSize(Matcher<java.lang.Long> expected) |
+
static Matcher<java.io.File> |
+anExistingDirectory() |
+
static Matcher<java.io.File> |
+anExistingFile() |
+
static Matcher<java.io.File> |
+anExistingFileOrDirectory() |
+
static Matcher<java.io.File> |
+aReadableFile() |
+
static Matcher<java.io.File> |
+aWritableFile() |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final FileMatchers.FileStatus CAN_WRITE+
public static final FileMatchers.FileStatus CAN_READ+
public static final FileMatchers.FileStatus IS_FILE+
public static final FileMatchers.FileStatus IS_DIRECTORY+
public static final FileMatchers.FileStatus EXISTS+
public static Matcher<java.io.File> anExistingDirectory()+
public static Matcher<java.io.File> anExistingFileOrDirectory()+
public static Matcher<java.io.File> anExistingFile()+
public static Matcher<java.io.File> aReadableFile()+
public static Matcher<java.io.File> aWritableFile()+
public static Matcher<java.io.File> aFileWithSize(long size)+
public static Matcher<java.io.File> aFileWithSize(Matcher<java.lang.Long> expected)+
public static Matcher<java.io.File> aFileNamed(Matcher<java.lang.String> expected)+
public static Matcher<java.io.File> aFileWithCanonicalPath(Matcher<java.lang.String> expected)+
Interface | +Description | +
---|---|
FileMatchers.FileStatus | ++ |
Class | +Description | +
---|---|
FileMatchers | ++ |
public class BigDecimalCloseTo +extends TypeSafeMatcher<java.math.BigDecimal>+
Constructor and Description | +
---|
BigDecimalCloseTo(java.math.BigDecimal value,
+ java.math.BigDecimal error) |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.math.BigDecimal> |
+closeTo(java.math.BigDecimal operand,
+ java.math.BigDecimal error)
+Creates a matcher of
+BigDecimal s that matches when an examined BigDecimal is equal
+ to the specified operand , within a range of +/- error . |
+
void |
+describeMismatchSafely(java.math.BigDecimal item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.math.BigDecimal item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public BigDecimalCloseTo(java.math.BigDecimal value, + java.math.BigDecimal error)+
public boolean matchesSafely(java.math.BigDecimal item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.math.BigDecimal>
public void describeMismatchSafely(java.math.BigDecimal item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.math.BigDecimal>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, + java.math.BigDecimal error)+
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 BigDecimal.compareTo(java.math.BigDecimal)
method.
+ For example:
+ assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
operand
- the expected value of matching BigDecimalserror
- the delta (+/-) within which matches will be allowedpublic class IsCloseTo +extends TypeSafeMatcher<java.lang.Double>+
Constructor and Description | +
---|
IsCloseTo(double value,
+ double error) |
+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.lang.Double> |
+closeTo(double operand,
+ double error)
+Creates a matcher of
+Double s that matches when an examined double is equal
+ to the specified operand , within a range of +/- error . |
+
void |
+describeMismatchSafely(java.lang.Double item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.lang.Double item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsCloseTo(double value, + double error)+
public boolean matchesSafely(java.lang.Double item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.Double>
public void describeMismatchSafely(java.lang.Double item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.Double>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.Double> closeTo(double operand, + double error)+
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)))
operand
- the expected value of matching doubleserror
- the delta (+/-) within which matches will be allowedpublic final class IsNaN +extends TypeSafeMatcher<java.lang.Double>+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.Double item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.lang.Double item)
+Subclasses should implement this.
+ |
+
static Matcher<java.lang.Double> |
+notANumber()
+Creates a matcher of
+Double s that matches when an examined double is not a number. |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.lang.Double item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.Double>
public void describeMismatchSafely(java.lang.Double item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.Double>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.Double> notANumber()+
Double
s that matches when an examined double is not a number.
+ For example:
+ assertThat(Double.NaN, is(notANumber()))
public class OrderingComparison
+extends java.lang.Object
+Modifier and Type | +Method and Description | +
---|---|
static <T extends java.lang.Comparable<T>> |
+comparesEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ equal to the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <T extends java.lang.Comparable<T>> |
+greaterThan(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ greater than the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <T extends java.lang.Comparable<T>> |
+greaterThanOrEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ greater than or equal to the specified value, as reported by the compareTo method
+ of the examined object. |
+
static <T extends java.lang.Comparable<T>> |
+lessThan(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ less than the specified value, as reported by the compareTo method of the
+ examined object. |
+
static <T extends java.lang.Comparable<T>> |
+lessThanOrEqualTo(T value)
+Creates a matcher of
+Comparable object that matches when the examined object is
+ less than or equal to the specified value, as reported by the compareTo method
+ of the examined object. |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static <T extends java.lang.Comparable<T>> Matcher<T> comparesEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> greaterThan(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return greater
+ than zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return greater
+ than or equal to zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> lessThan(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return less
+ than zeropublic static <T extends java.lang.Comparable<T>> Matcher<T> lessThanOrEqualTo(T value)+
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))
value
- the value which, when passed to the compareTo method of the examined object, should return less
+ than or equal to zeroClass | +Description | +
---|---|
BigDecimalCloseTo | ++ |
IsCloseTo | +
+ Is the value a number equal to a value within some range of
+ acceptable error?
+ |
+
IsNaN | +
+ Is the value a number actually not a number (NaN)?
+ |
+
OrderingComparison | ++ |
Matchers that perform numeric comparisons.
public class HasEqualValues<T> +extends TypeSafeDiagnosingMatcher<T>+
Constructor and Description | +
---|
HasEqualValues(T expectedObject) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
protected boolean |
+matchesSafely(T item,
+ Description mismatch)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public HasEqualValues(T expectedObject)+
protected boolean matchesSafely(T item, + Description mismatch)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<T>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public class HasToString<T> +extends FeatureMatcher<T,java.lang.String>+
Constructor and Description | +
---|
HasToString(Matcher<? super java.lang.String> toStringMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
protected java.lang.String |
+featureValueOf(T actual)
+Implement this to extract the interesting feature.
+ |
+
static <T> Matcher<T> |
+hasToString(Matcher<? super java.lang.String> toStringMatcher)
+Creates a matcher that matches any examined object whose
+toString method
+ returns a value that satisfies the specified matcher. |
+
static <T> Matcher<T> |
+hasToString(java.lang.String expectedToString)
+Creates a matcher that matches any examined object whose
+toString method
+ returns a value equalTo the specified string. |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public HasToString(Matcher<? super java.lang.String> toStringMatcher)+
protected java.lang.String featureValueOf(T actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<T,java.lang.String>
actual
- the target objectpublic static <T> Matcher<T> hasToString(Matcher<? super java.lang.String> toStringMatcher)+
toString
method
+ returns a value that satisfies the specified matcher.
+ For example:
+ assertThat(true, hasToString(equalTo("TRUE")))
toStringMatcher
- the matcher used to verify the toString resultpublic static <T> Matcher<T> hasToString(java.lang.String expectedToString)+
toString
method
+ returns a value equalTo the specified string.
+ For example:
+ assertThat(true, hasToString("TRUE"))
expectedToString
- the expected toString resultpublic class IsCompatibleType<T> +extends TypeSafeMatcher<java.lang.Class<?>>+
Constructor and Description | +
---|
IsCompatibleType(java.lang.Class<T> type) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.Class<?> cls,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.lang.Class<?> cls)
+Subclasses should implement this.
+ |
+
static <T> Matcher<java.lang.Class<?>> |
+typeCompatibleWith(java.lang.Class<T> baseType)
+Creates a matcher of
+Class that matches when the specified baseType is
+ assignable from the examined class. |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsCompatibleType(java.lang.Class<T> type)+
public boolean matchesSafely(java.lang.Class<?> cls)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.Class<?>>
public void describeMismatchSafely(java.lang.Class<?> cls, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.Class<?>>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static <T> Matcher<java.lang.Class<?>> typeCompatibleWith(java.lang.Class<T> baseType)+
Class
that matches when the specified baseType is
+ assignable from the examined class.
+ For example:
+ assertThat(Integer.class, typeCompatibleWith(Number.class))
baseType
- the base class to examine classes againstpublic class IsEventFrom +extends TypeSafeDiagnosingMatcher<java.util.EventObject>+
Constructor and Description | +
---|
IsEventFrom(java.lang.Class<?> eventClass,
+ java.lang.Object source) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.util.EventObject> |
+eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass,
+ java.lang.Object source)
+Creates a matcher of
+EventObject that matches any object
+ derived from eventClass announced by source. |
+
static Matcher<java.util.EventObject> |
+eventFrom(java.lang.Object source)
+Creates a matcher of
+EventObject that matches any EventObject
+ announced by source. |
+
boolean |
+matchesSafely(java.util.EventObject item,
+ Description mismatchDescription)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsEventFrom(java.lang.Class<?> eventClass, + java.lang.Object source)+
public boolean matchesSafely(java.util.EventObject item, + Description mismatchDescription)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<java.util.EventObject>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.util.EventObject> eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass, + java.lang.Object source)+
EventObject
that matches any object
+ derived from eventClass announced by source.
+ For example:
+ assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
eventClass
- the class of the event to match onsource
- the source of the eventpublic static Matcher<java.util.EventObject> eventFrom(java.lang.Object source)+
EventObject
that matches any EventObject
+ announced by source.
+ For example:
+ assertThat(myEvent, is(eventFrom(myBean)))
source
- the source of the eventClass | +Description | +
---|---|
HasEqualValues<T> | ++ |
HasToString<T> | ++ |
IsCompatibleType<T> | ++ |
IsEventFrom | +
+ Tests if the value is an event announced by a specific object.
+ |
+
Matchers that inspect objects and classes.
Interface | +Description | +
---|---|
Condition.Step<I,O> | ++ |
Description | +
+ A description of a Matcher.
+ |
+
Matcher<T> | +
+
+ A matcher over acceptable values.
+ |
+
SelfDescribing | +
+ The ability of an object to describe itself.
+ |
+
Class | +Description | +
---|---|
BaseDescription | +
+ A
+Description that is stored as a string. |
+
BaseMatcher<T> | +
+ BaseClass for all Matcher implementations.
+ |
+
Condition<T> | +
+ A Condition implements part of a multi-step match.
+ |
+
CoreMatchers | ++ |
CustomMatcher<T> | +
+ Utility class for writing one off matchers.
+ |
+
CustomTypeSafeMatcher<T> | +
+ Utility class for writing one off matchers.
+ |
+
Description.NullDescription | ++ |
DiagnosingMatcher<T> | +
+ TODO(ngd): Document.
+ |
+
FeatureMatcher<T,U> | +
+ Supporting class for matching a feature of an object.
+ |
+
MatcherAssert | ++ |
Matchers | ++ |
StringDescription | +
+ A
+Description that is stored as a string. |
+
TypeSafeDiagnosingMatcher<T> | +
+ Convenient base class for Matchers that require a non-null value of a specific type
+ and that will report why the received value has been rejected.
+ |
+
TypeSafeMatcher<T> | +
+ Convenient base class for Matchers that require a non-null value of a specific type.
+ |
+
public class CharSequenceLength +extends FeatureMatcher<java.lang.CharSequence,java.lang.Integer>+
Constructor and Description | +
---|
CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
protected java.lang.Integer |
+featureValueOf(java.lang.CharSequence actual)
+Implement this to extract the interesting feature.
+ |
+
static Matcher<java.lang.CharSequence> |
+hasLength(int length)
+Creates a matcher of
+CharSequence that matches when a char sequence has the given length
+ For example: |
+
static Matcher<java.lang.CharSequence> |
+hasLength(Matcher<? super java.lang.Integer> lengthMatcher)
+Creates a matcher of
+CharSequence that matches when a char sequence has the given length
+ For example: |
+
describeTo, matchesSafely
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher)+
lengthMatcher
- The matcher to apply to the featureprotected java.lang.Integer featureValueOf(java.lang.CharSequence actual)+
FeatureMatcher
featureValueOf
in class FeatureMatcher<java.lang.CharSequence,java.lang.Integer>
actual
- the target objectpublic static Matcher<java.lang.CharSequence> hasLength(int length)+
CharSequence
that matches when a char sequence has the given length
+ For example:
+
+ + assertThat("text", hasLength(4)) +
length
- the expected length of the stringpublic static Matcher<java.lang.CharSequence> hasLength(Matcher<? super java.lang.Integer> lengthMatcher)+
CharSequence
that matches when a char sequence has the given length
+ For example:
+
+ + assertThat("text", hasLength(lessThan(4))) +
lengthMatcher
- the expected length of the stringpublic final class IsBlankString +extends TypeSafeMatcher<java.lang.String>+
Modifier and Type | +Method and Description | +
---|---|
static Matcher<java.lang.String> |
+blankOrNullString()
+Creates a matcher of
+String that matches when the examined string is null , or
+ contains zero or more whitespace characters and nothing else. |
+
static Matcher<java.lang.String> |
+blankString()
+Creates a matcher of
+String that matches when the examined string contains
+ zero or more whitespace characters and nothing else. |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
describeMismatch, describeMismatchSafely, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.String> blankString()+
String
that matches when the examined string contains
+ zero or more whitespace characters and nothing else.
+ For example:
+ assertThat(" ", is(blankString()))
public static Matcher<java.lang.String> blankOrNullString()+
String
that matches when the examined string is null
, or
+ contains zero or more whitespace characters and nothing else.
+ For example:
+ assertThat(((String)null), is(blankOrNullString()))
public final class IsEmptyString +extends TypeSafeMatcher<java.lang.String>+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.lang.String> |
+emptyOrNullString()
+Creates a matcher of
+String that matches when the examined string is null , or
+ has zero length. |
+
static Matcher<java.lang.String> |
+emptyString()
+Creates a matcher of
+String that matches when the examined string has zero length. |
+
static Matcher<java.lang.String> |
+isEmptyOrNullString()
+Deprecated.
+
+use is(emptyOrNullString()) instead
+ |
+
static Matcher<java.lang.String> |
+isEmptyString()
+Deprecated.
+
+use is(emptyString()) instead
+ |
+
boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
describeMismatch, describeMismatchSafely, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.@Deprecated +public static Matcher<java.lang.String> isEmptyString()+
String
that matches when the examined string has zero length.
+ For example:
+ assertThat("", isEmptyString())
public static Matcher<java.lang.String> emptyString()+
String
that matches when the examined string has zero length.
+ For example:
+ assertThat("", is(emptyString()))
@Deprecated +public static Matcher<java.lang.String> isEmptyOrNullString()+
String
that matches when the examined string is null
, or
+ has zero length.
+ For example:
+ assertThat(((String)null), isEmptyOrNullString())
public static Matcher<java.lang.String> emptyOrNullString()+
String
that matches when the examined string is null
, or
+ has zero length.
+ For example:
+ assertThat(((String)null), is(emptyOrNullString()))
public class IsEqualCompressingWhiteSpace +extends TypeSafeMatcher<java.lang.String>+
Constructor and Description | +
---|
IsEqualCompressingWhiteSpace(java.lang.String string) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.String item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.lang.String> |
+equalToCompressingWhiteSpace(java.lang.String expectedString)
+Creates a matcher of
+String that matches when the examined string is equal to
+ the specified expectedString, when whitespace differences are (mostly) ignored. |
+
static Matcher<java.lang.String> |
+equalToIgnoringWhiteSpace(java.lang.String expectedString)
+Deprecated.
+
+
+ |
+
boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
java.lang.String |
+stripSpaces(java.lang.String toBeStripped) |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsEqualCompressingWhiteSpace(java.lang.String string)+
public boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeMismatchSafely(java.lang.String item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public java.lang.String stripSpaces(java.lang.String toBeStripped)+
public static Matcher<java.lang.String> equalToIgnoringWhiteSpace(java.lang.String expectedString)+
equalToCompressingWhiteSpace(String)
expectedString
- the expected value of matched stringspublic static Matcher<java.lang.String> equalToCompressingWhiteSpace(java.lang.String expectedString)+
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:
+ assertThat(" my\tfoo bar ", equalToCompressingWhiteSpace(" my foo bar"))
expectedString
- the expected value of matched stringspublic class IsEqualIgnoringCase +extends TypeSafeMatcher<java.lang.String>+
Constructor and Description | +
---|
IsEqualIgnoringCase(java.lang.String string) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.String item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.lang.String> |
+equalToIgnoringCase(java.lang.String expectedString)
+Creates a matcher of
+String that matches when the examined string is equal to
+ the specified expectedString, ignoring case. |
+
boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IsEqualIgnoringCase(java.lang.String string)+
public boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeMismatchSafely(java.lang.String item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.String> equalToIgnoringCase(java.lang.String expectedString)+
String
that matches when the examined string is equal to
+ the specified expectedString, ignoring case.
+ For example:
+ assertThat("Foo", equalToIgnoringCase("FOO"))
expectedString
- the expected value of matched stringspublic class MatchesPattern +extends TypeSafeMatcher<java.lang.String>+
Constructor and Description | +
---|
MatchesPattern(java.util.regex.Pattern pattern) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<java.lang.String> |
+matchesPattern(java.util.regex.Pattern pattern)
+Creates a matcher of
+String that matches when the examined string
+ exactly matches the given Pattern . |
+
static Matcher<java.lang.String> |
+matchesPattern(java.lang.String regex)
+Creates a matcher of
+String that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern . |
+
protected boolean |
+matchesSafely(java.lang.String item)
+Subclasses should implement this.
+ |
+
describeMismatch, describeMismatchSafely, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public MatchesPattern(java.util.regex.Pattern pattern)+
protected boolean matchesSafely(java.lang.String item)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.String> matchesPattern(java.util.regex.Pattern pattern)+
String
that matches when the examined string
+ exactly matches the given Pattern
.public static Matcher<java.lang.String> matchesPattern(java.lang.String regex)+
String
that matches when the examined string
+ exactly matches the given regular expression, treated as a Pattern
.public class StringContainsInOrder +extends TypeSafeMatcher<java.lang.String>+
Constructor and Description | +
---|
StringContainsInOrder(java.lang.Iterable<java.lang.String> substrings) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeMismatchSafely(java.lang.String item,
+ Description mismatchDescription)
+Subclasses should override this.
+ |
+
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
boolean |
+matchesSafely(java.lang.String s)
+Subclasses should implement this.
+ |
+
static Matcher<java.lang.String> |
+stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings)
+Creates a matcher of
+String that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance. |
+
static Matcher<java.lang.String> |
+stringContainsInOrder(java.lang.String... substrings)
+Creates a matcher of
+String that matches when the examined string contains all of
+ the specified substrings, considering the order of their appearance. |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public StringContainsInOrder(java.lang.Iterable<java.lang.String> substrings)+
public boolean matchesSafely(java.lang.String s)+
TypeSafeMatcher
matchesSafely
in class TypeSafeMatcher<java.lang.String>
public void describeMismatchSafely(java.lang.String item, + Description mismatchDescription)+
TypeSafeMatcher
describeMismatchSafely
in class TypeSafeMatcher<java.lang.String>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<java.lang.String> stringContainsInOrder(java.lang.Iterable<java.lang.String> substrings)+
String
that 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"
substrings
- the substrings that must be contained within matching stringspublic static Matcher<java.lang.String> stringContainsInOrder(java.lang.String... substrings)+
String
that 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"
substrings
- the substrings that must be contained within matching stringsClass | +Description | +
---|---|
CharSequenceLength | ++ |
IsBlankString | +
+ Matches blank Strings (and null).
+ |
+
IsEmptyString | +
+ Matches empty Strings (and null).
+ |
+
IsEqualCompressingWhiteSpace | +
+ Tests if a string is equal to another string, compressing any changes in whitespace.
+ |
+
IsEqualIgnoringCase | +
+ Tests if a string is equal to another string, regardless of the case.
+ |
+
MatchesPattern | ++ |
StringContainsInOrder | ++ |
Matchers that perform text comparisons.
public class HasXPath +extends TypeSafeDiagnosingMatcher<org.w3c.dom.Node>+
Modifier and Type | +Field and Description | +
---|---|
static javax.xml.namespace.NamespaceContext |
+NO_NAMESPACE_CONTEXT |
+
Constructor and Description | +
---|
HasXPath(java.lang.String xPathExpression,
+ Matcher<java.lang.String> valueMatcher) |
+
HasXPath(java.lang.String xPathExpression,
+ javax.xml.namespace.NamespaceContext namespaceContext,
+ Matcher<java.lang.String> valueMatcher) |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+describeTo(Description description)
+Generates a description of the object.
+ |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath)
+Creates a matcher of
+Node s that matches when the examined node contains a node
+ at the specified xPath , with any content. |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ Matcher<java.lang.String> valueMatcher)
+Creates a matcher of
+Node s that matches when the examined node has a value at the
+ specified xPath that satisfies the specified valueMatcher . |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ javax.xml.namespace.NamespaceContext namespaceContext)
+Creates a matcher of
+Node s that matches when the examined node contains a node
+ at the specified xPath within the specified namespace context, with any content. |
+
static Matcher<org.w3c.dom.Node> |
+hasXPath(java.lang.String xPath,
+ javax.xml.namespace.NamespaceContext namespaceContext,
+ Matcher<java.lang.String> valueMatcher)
+Creates a matcher of
+Node s that matches when the examined node has a value at the
+ specified xPath , within the specified namespaceContext , that satisfies
+ the specified valueMatcher . |
+
boolean |
+matchesSafely(org.w3c.dom.Node item,
+ Description mismatch)
+Subclasses should implement this.
+ |
+
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static final javax.xml.namespace.NamespaceContext NO_NAMESPACE_CONTEXT+
public HasXPath(java.lang.String xPathExpression, + Matcher<java.lang.String> valueMatcher)+
xPathExpression
- XPath expression.valueMatcher
- Matcher to use at given XPath.
+ May be null to specify that the XPath must exist but the value is irrelevant.public HasXPath(java.lang.String xPathExpression, + javax.xml.namespace.NamespaceContext namespaceContext, + Matcher<java.lang.String> valueMatcher)+
xPathExpression
- XPath expression.namespaceContext
- Resolves XML namespace prefixes in the XPath expressionvalueMatcher
- Matcher to use at given XPath.
+ May be null to specify that the XPath must exist but the value is irrelevant.public boolean matchesSafely(org.w3c.dom.Node item, + Description mismatch)+
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
public void describeTo(Description description)+
SelfDescribing
description
- The description to be built or appended to.public static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + Matcher<java.lang.String> valueMatcher)+
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")))
xPath
- the target xpathvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + javax.xml.namespace.NamespaceContext namespaceContext, + Matcher<java.lang.String> valueMatcher)+
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")))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodesvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath)+
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"))
xPath
- the target xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, + javax.xml.namespace.NamespaceContext namespaceContext)+
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))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodesClass | +Description | +
---|---|
HasXPath | +
+ Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression.
+ |
+
Matchers of XML documents.
+ + diff --git a/docs/javadoc/2.1/overview-summary.html b/docs/javadoc/2.1/overview-summary.html new file mode 100644 index 00000000..ce4b1d80 --- /dev/null +++ b/docs/javadoc/2.1/overview-summary.html @@ -0,0 +1,190 @@ + + + + + +
Package | +Description | +
---|---|
org.hamcrest | ++ |
org.hamcrest.beans | +
+ Matchers of Java Bean properties and their values.
+ |
+
org.hamcrest.collection | +
+ Matchers of arrays and collections.
+ |
+
org.hamcrest.comparator | ++ |
org.hamcrest.core | +
+ Fundamental matchers of objects and values, and composite matchers.
+ |
+
org.hamcrest.internal | ++ |
org.hamcrest.io | ++ |
org.hamcrest.number | +
+ Matchers that perform numeric comparisons.
+ |
+
org.hamcrest.object | +
+ Matchers that inspect objects and classes.
+ |
+
org.hamcrest.text | +
+ Matchers that perform text comparisons.
+ |
+
org.hamcrest.xml | +
+ Matchers of XML documents.
+ |
+