public interface TestSuite
This interface is only used to provide the DSL capabilities for the test ; It is not used as a marker by the framework.
Several functionalities are provided here :
before(Runnable...) to setup a before action.after(Runnable...) to setup a after action.mockitoRule() to setup mockito.systemPropertiesRule(String...) to restore
properties system after test ; Several others method related to
systemProperties exist.temporaryFolder() to support temporary folder.parametersMap(int, Function) to create Map function
to be used on the stream to be provided by the @Parameters. Other variants of this method may exist.| Modifier and Type | Field and Description |
|---|---|
static TestSuite |
DSL
A static field that is a testsuite (to avoid implementing TestSuite in
test, in the rare case when it may be required).
|
| Modifier and Type | Method and Description |
|---|---|
default <T> java.util.function.Function<Object[],Object[]> |
addFieldToEachEntry(T field)
Provide a way to add a field to each parameter line.
|
default TestRule |
after(Runnable... afters)
Build a after testrule.
|
default <T> org.hamcrest.Matcher<T> |
allOf(Iterable<org.hamcrest.Matcher<? super T>> matchers)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T>... matchers)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T> first,
org.hamcrest.Matcher<? super T> second)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth,
org.hamcrest.Matcher<? super T> fifth)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
allOf(org.hamcrest.Matcher<? super T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth,
org.hamcrest.Matcher<? super T> fifth,
org.hamcrest.Matcher<? super T> sixth)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> org.hamcrest.Matcher<T> |
any(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. |
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(Iterable<org.hamcrest.Matcher<? super T>> matchers)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<? super T>... matchers)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth,
org.hamcrest.Matcher<? super T> fifth)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> org.hamcrest.core.AnyOf<T> |
anyOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third,
org.hamcrest.Matcher<? super T> fourth,
org.hamcrest.Matcher<? super T> fifth,
org.hamcrest.Matcher<? super T> sixth)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default org.hamcrest.Matcher<Object> |
anything()
Creates a matcher that always matches, regardless of the examined object.
|
default org.hamcrest.Matcher<Object> |
anything(String description)
Creates a matcher that always matches, regardless of the examined object,
but describes itself with the specified
String. |
default <T> org.hamcrest.collection.IsArray<T> |
array(org.hamcrest.Matcher<? super T>... elementMatchers)
Creates a matcher that matches arrays whose elements are satisfied by the
specified matchers.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayContaining(E... items)
Creates a matcher for arrays that matcheswhen each item in the examined
array is logically equal to the corresponding item in the specified
items.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayContaining(List<org.hamcrest.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.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayContaining(org.hamcrest.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.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayContainingInAnyOrder(Collection<org.hamcrest.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.
|
default <E> org.hamcrest.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.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayContainingInAnyOrder(org.hamcrest.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.
|
default <E> org.hamcrest.Matcher<E[]> |
arrayWithSize(int size)
Creates a matcher for arrays that matches when the
length of
the array equals the specified size. |
default <E> org.hamcrest.Matcher<E[]> |
arrayWithSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
Creates a matcher for arrays that matches when the
length of
the array satisfies the specified matcher. |
default AssertThatString |
assertThat(String obj)
Assert the value of a String.
|
default AssertThatString |
assertThat(String msg,
String obj)
Assert the value of a String.
|
default <T> AssertThatObject<T> |
assertThat(String msg,
T obj)
Assert the value of an object.
|
default <T> AssertThatObject<T> |
assertThat(T obj)
Assert the value of an object.
|
default <T,U,R> AssertThatObject<R> |
assertThatBiFunction(java.util.function.BiFunction<T,U,R> function,
T input1,
U input2)
Assert on a bifunction.
|
default <T,U,R> AssertThatObject<R> |
assertThatBiFunction(String msg,
java.util.function.BiFunction<T,U,R> function,
T input1,
U input2)
Assert on a bifunction.
|
default <T,R> AssertThatObject<R> |
assertThatFunction(java.util.function.Function<T,R> function,
T input)
Assert on a function.
|
default <T,R> AssertThatObject<R> |
assertThatFunction(String msg,
java.util.function.Function<T,R> function,
T input)
Assert on a function.
|
default <T> AssertThatIterable<T> |
assertThatIterable(Iterable<T> obj)
Assert on an iterable object.
|
default <T> AssertThatIterable<T> |
assertThatIterable(String msg,
Iterable<T> obj)
Assert on an iterable object.
|
default <T extends Throwable> |
assertWhen(Statement<?,T> underTest)
Assert that a statement (a piece of code) throw an exception.
|
default <P,T extends Throwable> |
assertWhen(Statement<P,T> underTest,
P param)
Assert that a statement (a piece of code) throw an exception.
|
default <T extends Throwable> |
assertWhen(String msg,
Statement<?,T> underTest)
Assert that a statement (a piece of code) throw an exception.
|
default <P,T extends Throwable> |
assertWhen(String msg,
Statement<P,T> underTest,
P param)
Assert that a statement (a piece of code) throw an exception.
|
default AssertThatString |
assumeThat(String obj)
Assume the value of a String.
|
default AssertThatString |
assumeThat(String msg,
String obj)
Assume the value of a String.
|
default <T> AssertThatObject<T> |
assumeThat(String msg,
T obj)
Assume the value of an object.
|
default <T> AssertThatObject<T> |
assumeThat(T obj)
Assume the value of an object.
|
default <T,U,R> AssertThatObject<R> |
assumeThatBiFunction(java.util.function.BiFunction<T,U,R> function,
T input1,
U input2)
Assume on a bifunction.
|
default <T,U,R> AssertThatObject<R> |
assumeThatBiFunction(String msg,
java.util.function.BiFunction<T,U,R> function,
T input1,
U input2)
Assume on a bifunction.
|
default <T,R> AssertThatObject<R> |
assumeThatFunction(java.util.function.Function<T,R> function,
T input)
Assume on a function.
|
default <T,R> AssertThatObject<R> |
assumeThatFunction(String msg,
java.util.function.Function<T,R> function,
T input)
Assume on a function.
|
default <T> AssertThatIterable<T> |
assumeThatIterable(Iterable<T> obj)
Assume on an iterable object.
|
default <T> AssertThatIterable<T> |
assumeThatIterable(String msg,
Iterable<T> obj)
Assume on an iterable object.
|
default <T extends Throwable> |
assumeWhen(Statement<?,T> underTest)
Assume that a statement (a piece of code) throw an exception.
|
default <P,T extends Throwable> |
assumeWhen(Statement<P,T> underTest,
P param)
Assume that a statement (a piece of code) throw an exception.
|
default <T extends Throwable> |
assumeWhen(String msg,
Statement<?,T> underTest)
Assume that a statement (a piece of code) throw an exception.
|
default <P,T extends Throwable> |
assumeWhen(String msg,
Statement<P,T> underTest,
P param)
Assume that a statement (a piece of code) throw an exception.
|
default TestRule |
before(Runnable... befores)
Build a before testrule.
|
default <LHS> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<LHS> |
both(org.hamcrest.Matcher<? super LHS> matcher)
Creates a matcher that matches when both of the specified matchers match
the examined object.
|
default org.hamcrest.Matcher<BigDecimal> |
closeTo(BigDecimal operand,
BigDecimal error)
Creates a matcher of
BigDecimals that matches when an
examined BigDecimal is equal to the specified operand,
within a range of +/- error. |
default org.hamcrest.Matcher<Double> |
closeTo(double operand,
double error)
Creates a matcher of
Doubles that matches when an examined double
is equal to the specified operand, within a range of +/-
error. |
default <T extends 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. |
default <E> org.hamcrest.Matcher<Iterable<? extends E>> |
contains(E... items)
|
default <E> org.hamcrest.Matcher<Iterable<? extends E>> |
contains(List<org.hamcrest.Matcher<? super E>> itemMatchers)
|
default <E> org.hamcrest.Matcher<Iterable<? extends E>> |
contains(org.hamcrest.Matcher<? super E>... itemMatchers)
|
default <E> org.hamcrest.Matcher<Iterable<? extends E>> |
contains(org.hamcrest.Matcher<? super E> itemMatcher)
|
default <T> org.hamcrest.Matcher<Iterable<? extends T>> |
containsInAnyOrder(Collection<org.hamcrest.Matcher<? super T>> itemMatchers)
|
default <T> org.hamcrest.Matcher<Iterable<? extends T>> |
containsInAnyOrder(org.hamcrest.Matcher<? super T>... itemMatchers)
|
default <T> org.hamcrest.Matcher<Iterable<? extends T>> |
containsInAnyOrder(T... items)
|
default org.hamcrest.Matcher<String> |
containsString(String substring)
|
default <T> org.hamcrest.Matcher<T> |
describedAs(String description,
org.hamcrest.Matcher<T> matcher,
Object... values)
Wraps an existing matcher, overriding its description with that
specified.
|
default <LHS> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<LHS> |
either(org.hamcrest.Matcher<? super LHS> matcher)
Creates a matcher that matches when either of the specified matchers
match the examined object.
|
default <E> org.hamcrest.Matcher<Collection<? extends E>> |
empty()
|
default <E> org.hamcrest.Matcher<E[]> |
emptyArray()
Creates a matcher for arrays that matches when the
length of
the array is zero. |
default <E> org.hamcrest.Matcher<Collection<E>> |
emptyCollectionOf(Class<E> type)
|
default <E> org.hamcrest.Matcher<Iterable<? extends E>> |
emptyIterable()
Creates a matcher for
Iterables matching examined iterables that
yield no items. |
default <E> org.hamcrest.Matcher<Iterable<E>> |
emptyIterableOf(Class<E> type)
Creates a matcher for
Iterables matching examined iterables that
yield no items. |
default org.hamcrest.Matcher<String> |
endsWith(String suffix)
|
default <T> org.hamcrest.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. |
default org.hamcrest.Matcher<String> |
equalToIgnoringCase(String expectedString)
Creates a matcher of
String that matches when the examined string
is equal to the specified expectedString, ignoring case. |
default org.hamcrest.Matcher<String> |
equalToIgnoringWhiteSpace(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. |
default org.hamcrest.Matcher<EventObject> |
eventFrom(Class<? extends EventObject> eventClass,
Object source)
Creates a matcher of
EventObject that matches any
object derived from eventClass announced by source. |
default org.hamcrest.Matcher<EventObject> |
eventFrom(Object source)
Creates a matcher of
EventObject that matches any
EventObject announced by source. |
default <U> org.hamcrest.Matcher<Iterable<U>> |
everyItem(org.hamcrest.Matcher<U> itemMatcher)
|
default org.hamcrest.Matcher<Throwable> |
exceptionMessage(org.hamcrest.Matcher<? super String> matching)
Validate the message of an exception
|
default org.hamcrest.Matcher<Throwable> |
exceptionMessage(String message)
Validate the message of an exception
|
default void |
fail()
Always produce a failure.
|
default void |
fail(String msg)
Always produce a failure.
|
default void |
fail(String msg,
Throwable innerError)
Always produce a failure.
|
default org.hamcrest.Matcher<File> |
fileCanExecute(boolean canExecute)
Validate that a file can execute.
|
default org.hamcrest.Matcher<File> |
fileCanExecute(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file can execute.
|
default org.hamcrest.Matcher<File> |
fileCanRead(boolean canRead)
Validate that a file can read.
|
default org.hamcrest.Matcher<File> |
fileCanRead(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file can read.
|
default org.hamcrest.Matcher<File> |
fileCanWrite(boolean canWrite)
Validate that a file can write.
|
default org.hamcrest.Matcher<File> |
fileCanWrite(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file can write.
|
default org.hamcrest.Matcher<File> |
fileContains(org.hamcrest.Matcher<String[]> matcher)
Validate that a file contains something.
|
default org.hamcrest.Matcher<File> |
fileContains(String atLeastThisName)
Validate that a file contains some other file name.
|
default org.hamcrest.Matcher<File> |
fileExists(boolean exists)
Validate that a file exists.
|
default org.hamcrest.Matcher<File> |
fileExists(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file exists.
|
default org.hamcrest.Matcher<File> |
fileIsAbsolute(boolean absolute)
Validate that a file is absolute.
|
default org.hamcrest.Matcher<File> |
fileIsAbsolute(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file is absolute.
|
default org.hamcrest.Matcher<File> |
fileIsDirectory(boolean isDirectory)
Validate that a file is a directory.
|
default org.hamcrest.Matcher<File> |
fileIsDirectory(org.hamcrest.Matcher<? super Boolean> matcher)
Validate that a file is a directory.
|
default org.hamcrest.Matcher<File> |
fileNamed(org.hamcrest.Matcher<? super String> matcher)
Validate that a file has some name.
|
default org.hamcrest.Matcher<File> |
fileNamed(String name)
Validate that a file has some name.
|
default <T extends 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. |
default <T extends 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. |
default <K,V> org.hamcrest.Matcher<Map<? extends K,? extends V>> |
hasEntry(K key,
V value)
|
default <K,V> org.hamcrest.Matcher<Map<? extends K,? extends V>> |
hasEntry(org.hamcrest.Matcher<? super K> keyMatcher,
org.hamcrest.Matcher<? super V> valueMatcher)
|
default <T> org.hamcrest.Matcher<Iterable<? super T>> |
hasItem(org.hamcrest.Matcher<? super T> itemMatcher)
|
default <T> org.hamcrest.Matcher<Iterable<? super T>> |
hasItem(T item)
|
default <T> org.hamcrest.Matcher<T[]> |
hasItemInArray(org.hamcrest.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. |
default <T> org.hamcrest.Matcher<T[]> |
hasItemInArray(T element)
A shortcut to the frequently used
hasItemInArray(equalTo(x))
. |
default <T> org.hamcrest.Matcher<Iterable<T>> |
hasItems(org.hamcrest.Matcher<? super T>... itemMatchers)
|
default <T> org.hamcrest.Matcher<Iterable<T>> |
hasItems(T... items)
|
default <K> org.hamcrest.Matcher<Map<? extends K,?>> |
hasKey(K key)
|
default <K> org.hamcrest.Matcher<Map<? extends K,?>> |
hasKey(org.hamcrest.Matcher<? super K> keyMatcher)
|
default <T> org.hamcrest.Matcher<T> |
hasProperty(String propertyName)
Creates a matcher that matches when the examined object has a JavaBean
property with the specified name.
|
default <T> org.hamcrest.Matcher<T> |
hasProperty(String propertyName,
org.hamcrest.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.
|
default <E> org.hamcrest.Matcher<Collection<? extends E>> |
hasSize(int size)
Creates a matcher for
Collections that matches when the
size() method returns a value equal to the specified
size. |
default <E> org.hamcrest.Matcher<Collection<? extends E>> |
hasSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
Creates a matcher for
Collections that matches when the
size() method returns a value that satisfies the specified
matcher. |
default <T> org.hamcrest.Matcher<T> |
hasToString(org.hamcrest.Matcher<? super String> toStringMatcher)
Creates a matcher that matches any examined object whose
toString method returns a value that satisfies the specified
matcher. |
default <T> org.hamcrest.Matcher<T> |
hasToString(String expectedToString)
Creates a matcher that matches any examined object whose
toString method returns a value equalTo the specified
string. |
default <V> org.hamcrest.Matcher<Map<?,? extends V>> |
hasValue(org.hamcrest.Matcher<? super V> valueMatcher)
|
default <V> org.hamcrest.Matcher<Map<?,? extends V>> |
hasValue(V value)
|
default org.hamcrest.Matcher<Node> |
hasXPath(String xPath)
Creates a matcher of
Nodes that matches when the
examined node contains a node at the specified xPath, with
any content. |
default org.hamcrest.Matcher<Node> |
hasXPath(String xPath,
org.hamcrest.Matcher<String> valueMatcher)
Creates a matcher of
Nodes that matches when the
examined node has a value at the specified xPath that
satisfies the specified valueMatcher. |
default org.hamcrest.Matcher<Node> |
hasXPath(String xPath,
NamespaceContext namespaceContext)
Creates a matcher of
Nodes that matches when the
examined node contains a node at the specified xPath within
the specified namespace context, with any content. |
default org.hamcrest.Matcher<Node> |
hasXPath(String xPath,
NamespaceContext namespaceContext,
org.hamcrest.Matcher<String> valueMatcher)
Creates a matcher of
Nodes that matches when the
examined node has a value at the specified xPath, within the
specified namespaceContext, that satisfies the specified
valueMatcher. |
default <T> org.hamcrest.Matcher<T> |
instanceOf(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. |
default <T> org.hamcrest.Matcher<T> |
is(org.hamcrest.Matcher<T> matcher)
Decorates another Matcher, retaining its behaviour, but allowing tests to
be slightly more expressive.
|
default <T> org.hamcrest.Matcher<T> |
is(T value)
A shortcut to the frequently used
is(equalTo(x)). |
default <T> org.hamcrest.Matcher<T> |
isA(Class<T> type)
A shortcut to the frequently used
is(instanceOf(SomeClass.class)). |
default org.hamcrest.Matcher<String> |
isEmptyOrNullString()
Creates a matcher of
String that matches when the examined string
is null, or has zero length. |
default org.hamcrest.Matcher<String> |
isEmptyString()
Creates a matcher of
String that matches when the examined string
has zero length. |
default <T> org.hamcrest.Matcher<T> |
isIn(Collection<T> collection)
Creates a matcher that matches when the examined object is found within
the specified collection.
|
default <T> org.hamcrest.Matcher<T> |
isIn(T[] param1) |
default <T> org.hamcrest.Matcher<T> |
isOneOf(T... elements)
Creates a matcher that matches when the examined object is equal to one
of the specified elements.
|
default <E> org.hamcrest.Matcher<Iterable<E>> |
iterableWithSize(int size)
|
default <E> org.hamcrest.Matcher<Iterable<E>> |
iterableWithSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
|
default <T extends 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. |
default <T extends 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. |
default <T> java.util.function.Predicate<T> |
matcherPredicate(org.hamcrest.Matcher<T> matcher)
Expose a matcher as a predicate.
|
default org.hamcrest.Matcher<String> |
matchesRegex(Pattern pattern)
Validate a string with a
Pattern. |
default org.hamcrest.Matcher<String> |
matchesRegex(String regex)
Validate a string with a regex.
|
default TestRule |
mockitoRule()
Create a rule to support mockito.
|
default <T> org.hamcrest.Matcher<T> |
not(org.hamcrest.Matcher<T> matcher)
Creates a matcher that wraps an existing matcher, but inverts the logic
by which it will match.
|
default <T> org.hamcrest.Matcher<T> |
not(T value)
A shortcut to the frequently used
not(equalTo(x)). |
default org.hamcrest.Matcher<Object> |
notNullValue()
A shortcut to the frequently used
not(nullValue()). |
default <T> org.hamcrest.Matcher<T> |
notNullValue(Class<T> type)
A shortcut to the frequently used
not(nullValue(X.class)). |
default org.hamcrest.Matcher<Object> |
nullValue()
Creates a matcher that matches if examined object is
null. |
default <T> org.hamcrest.Matcher<T> |
nullValue(Class<T> type)
Creates a matcher that matches if examined object is
null. |
default org.hamcrest.Matcher<OptionalDouble> |
optionalDoubleIs(org.hamcrest.Matcher<? super Double> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default org.hamcrest.Matcher<OptionalDouble> |
optionalDoubleIsNotPresent()
Check that the passed optional is not present.
|
default org.hamcrest.Matcher<OptionalDouble> |
optionalDoubleIsPresent()
Check that the passed optional is present.
|
default org.hamcrest.Matcher<OptionalInt> |
optionalIntIs(Integer target)
Check that the passed optional is some target value.
|
default org.hamcrest.Matcher<OptionalInt> |
optionalIntIs(org.hamcrest.Matcher<? super Integer> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default org.hamcrest.Matcher<OptionalInt> |
optionalIntIsNotPresent()
Check that the passed optional is not present.
|
default org.hamcrest.Matcher<OptionalInt> |
optionalIntIsPresent()
Check that the passed optional is present.
|
default <T> org.hamcrest.Matcher<Optional<? super T>> |
optionalIs(org.hamcrest.Matcher<? super T> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default <T> org.hamcrest.Matcher<Optional<? super T>> |
optionalIs(T target)
Check that the passed optional is some target value.
|
default <T> org.hamcrest.Matcher<Optional<T>> |
optionalIsNotPresent()
Check that the passed optional is not present.
|
default <T> org.hamcrest.Matcher<Optional<T>> |
optionalIsPresent()
Check that the passed optional is present.
|
default org.hamcrest.Matcher<OptionalLong> |
optionalLongIs(Long target)
Check that the passed optional is some target value.
|
default org.hamcrest.Matcher<OptionalLong> |
optionalLongIs(org.hamcrest.Matcher<? super Long> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default org.hamcrest.Matcher<OptionalLong> |
optionalLongIsNotPresent()
Check that the passed optional is not present.
|
default org.hamcrest.Matcher<OptionalLong> |
optionalLongIsPresent()
Check that the passed optional is present.
|
default java.util.function.Predicate<Object[]> |
parametersFilterUsingMatcher(org.hamcrest.Matcher<Object[]> matcher)
Provide a filter for stream parameters, to keep only parameters accepted
by a matcher.
|
default <T,R> StreamParametersMapFunction<T> |
parametersMap(int idx,
java.util.function.Function<T,R> mapFunction)
Start building a Parameter Mapper function, with an initial converter.
|
default org.hamcrest.Matcher<Path> |
pathMatchedAsFile(org.hamcrest.Matcher<? super File> matcher)
This is a special matcher that apply the toFile() method to the in
matching path, and then apply the specified matcher.
|
default <T> org.hamcrest.Matcher<T> |
sameInstance(T target)
Creates a matcher that matches only when the examined object is the same
instance as the specified target object.
|
default <T> org.hamcrest.Matcher<T> |
samePropertyValuesAs(T expectedBean)
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.
|
default void |
skip()
Always produce a skip.
|
default void |
skip(String msg)
Always produce a skip.
|
default org.hamcrest.Matcher<String> |
startsWith(String prefix)
|
default org.hamcrest.Matcher<String> |
stringContainsInOrder(Iterable<String> substrings)
Creates a matcher of
String that matches when the examined string
contains all of the specified substrings, regardless of the order of
their appearance. |
default StreamParametersMapFunction<String> |
stringToParameterMap(Class<?> testClass)
Start building a Parameter Mapper function, assuming that the input are
String, and using the type of the
@Parameter field. |
default TestRule |
systemPropertiesRule(String... propertiesName)
Create a rule to restore some system properties after the test
|
default TestRule |
systemProperty(String propertyName,
String propertyValue)
Set a property before the run and ensure correct restore.
|
default TestRule |
systemProperty(String propertyName,
java.util.function.Supplier<String> propertyValue)
Set a property before the run and ensure correct restore.
|
default TemporaryFolder |
temporaryFolder()
Produces a new rule for the temporary folder.
|
default TemporaryFolder.TemporaryFolderBuilder |
temporaryFolderBuilder()
Produces a new rule builder for the temporary folder.
|
default <T> org.hamcrest.Matcher<T> |
theInstance(T target)
Creates a matcher that matches only when the examined object is the same
instance as the specified target object.
|
default <T> org.hamcrest.Matcher<Class<?>> |
typeCompatibleWith(Class<T> baseType)
Creates a matcher of
Class that matches when the specified
baseType is assignable from the examined class. |
static final TestSuite DSL
The main use case is to access the stream functionnalities from a
@Parameters annotated method, has this method must
be static.
default TestRule before(Runnable... befores)
The passed runnable will be used before each test. The exact location of the execution is depending on where this used on the testRule chain.
In the much simple case (just one method to be executed before each test), the syntax is :
@Rule public TestRule rule = before(this::beforeMethodName);
befores - the beforesthe rule chain.Ruledefault TestRule after(Runnable... afters)
The passed runnable will be used after each test. The exact location of the execution is depending on where this used on the testRule chain.
In the much simple case (just one method to be executed after each test), the syntax is :
@Rule public TestRule rule = after(this::afterMethodName);
afters - the aftersthe rule chain.Ruledefault TestRule mockitoRule()
This provide a way to setup Mockito before each test.
the rule chain.Ruledefault TemporaryFolder temporaryFolder()
As the TemporaryFolder rule provides several methods that are
required for the test, except in the case when only this rule is
required, a direct usage in the rule DSL is not adapted.
For instance, assuming that it is required to mix a before and the
TemporaryFolder rule, the code will look like :
private TemporaryFolder temporary = temporaryFolder(); @Rule public TestRule rule = before(this::beforeMethodName).around(temporary);This is required to ensure that the method of the
TemporaryFolder
object can be used (using the field named temporary).Ruledefault TemporaryFolder.TemporaryFolderBuilder temporaryFolderBuilder()
As the TemporaryFolder rule provides several methods that are
required for the test, except in the case when only this rule is
required, a direct usage in the rule DSL is not adapted.
For instance, assuming that it is required to mix a before and the
TemporaryFolder rule, the code will look like :
private TemporaryFolder temporary = temporaryFolderBuilder().build(); @Rule public TestRule rule = before(this::beforeMethodName).around(temporary);This is required to ensure that the method of the
TemporaryFolder
object can be used (using the field named temporary).
The builder provide several capabilities to create initial folder structure at the same time than the temporary folder itself.
Ruledefault TestRule systemPropertiesRule(String... propertiesName)
propertiesName - the properties to be restoredthe rule chain.Ruledefault TestRule systemProperty(String propertyName, java.util.function.Supplier<String> propertyValue)
propertyName - the name of the propertypropertyValue - the value of the propertythe rule chain.Ruledefault TestRule systemProperty(String propertyName, String propertyValue)
propertyName - the name of the propertypropertyValue - the value of the propertythe rule chain.Ruledefault <T,R> StreamParametersMapFunction<T> parametersMap(int idx, java.util.function.Function<T,R> mapFunction)
Not specified index are considered transformed by identity function.
T - The input type for the functionR - the result type for the functionidx - The parameter indexmapFunction - the function to be applieddefault StreamParametersMapFunction<String> stringToParameterMap(Class<?> testClass)
@Parameter field.
Fields not supported will not be mapped and must be handled manually,
using andMap
method to avoid any unexpected error.
The goal of this method is to provide a way to receive so generic parameter and not having to care about typing. Let's take for example the following use case :
map method can be used to
transform the received data into another format. Here, using the result
of this method as parameter of the map method will ensure the
transformation of the String to the right type, for simple type.andMap (on the
returned object of this method), to add manual transformation.
In this context, as the @Parameters annotated
method must be static, access to this method can be done using
DSL. prefix.
testClass - the testClass, as this method is to be used in static mode.default <T> java.util.function.Function<Object[],Object[]> addFieldToEachEntry(T field)
T - The object type to be added.field - The field to be added.Stream.map(Function)).default java.util.function.Predicate<Object[]> parametersFilterUsingMatcher(org.hamcrest.Matcher<Object[]> matcher)
matcher - the matcherdefault <T> java.util.function.Predicate<T> matcherPredicate(org.hamcrest.Matcher<T> matcher)
T - The target object typematcher - the matcher.default <T> AssertThatObject<T> assertThat(T obj)
For instance
assertThat(myObject).is(myOtherObject);This will check that
myObject is myOtherObject
(using the equalTo Hamcrest matcher).T - the object type.obj - the objectthe assert DSL on this objectdefault <T> AssertThatObject<T> assertThat(String msg, T obj)
For instance
assertThat("msg", myObject).is(myOtherObject);
This will check that myObject is myOtherObject
(using the equalTo Hamcrest matcher).T - the object type.msg - a messageobj - the objectthe assert DSL on this objectdefault AssertThatString assertThat(String obj)
For instance
assertThat(myString).is("");
This will check that myString is "" (using the
equalTo Hamcrest matcher).obj - the Stringthe assert DSL on this objectdefault AssertThatString assertThat(String msg, String obj)
For instance
assertThat("msg", myString).is("");
This will check that myString is "" (using the
equalTo Hamcrest matcher).msg - a messageobj - the Stringthe assert DSL on this objectdefault <T> AssertThatIterable<T> assertThatIterable(Iterable<T> obj)
For instance
assertThatIterable(myIterable).hasSize(0);This will check that
myIterable has a size of 0.T - the element type.obj - the object (Iterable)the assert DSL on this iterabledefault <T> AssertThatIterable<T> assertThatIterable(String msg, Iterable<T> obj)
For instance
assertThatIterable("msg", myIterable).hasSize(0);
This will check that myIterable has a size of 0.T - the element type.msg - a messageobj - the object (Iterable)the assert DSL on this iterabledefault <T,R> AssertThatObject<R> assertThatFunction(java.util.function.Function<T,R> function, T input)
The purpose of this variant of assertThat provides a way to apply a function on some input and to check the result.
For instance
assertThatFunction((a) -> a + "x", "b").is("bx")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the input of the functionR - the object type of the resultfunction - the functioninput - the input to the functionthen assert DSL on the result of the
functiondefault <T,R> AssertThatObject<R> assertThatFunction(String msg, java.util.function.Function<T,R> function, T input)
The purpose of this variant of assertThat provides a way to apply a function on some input and to check the result.
For instance
assertThatFunction("msg", (a) -> a + "x", "b").is("bx")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the input of the functionR - the object type of the resultmsg - a messagefunction - the functioninput - the input to the functionthen assert DSL on the result of the
functiondefault <T,U,R> AssertThatObject<R> assertThatBiFunction(java.util.function.BiFunction<T,U,R> function, T input1, U input2)
The purpose of this variant of assertThat provides a way to apply a bifunction on some input and to check the result.
For instance
assertThatBiFunction((a, b) -> a + b, "a", "b").is("ab")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the first input of the functionU - the object type fo the second input of the functionR - the object type of the resultfunction - the functioninput1 - the first input to the functioninput2 - the second input to the functionthen assert DSL on the result of the
bifunctiondefault <T,U,R> AssertThatObject<R> assertThatBiFunction(String msg, java.util.function.BiFunction<T,U,R> function, T input1, U input2)
The purpose of this variant of assertThat provides a way to apply a bifunction on some input and to check the result.
For instance
assertThatBiFunction((a, b) -> a + b, "a", "b").is("ab")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the first input of the functionU - the object type fo the second input of the functionR - the object type of the resultmsg - a messagefunction - the functioninput1 - the first input to the functioninput2 - the second input to the functionthen assert DSL on the result of the
bifunctiondefault <T extends Throwable> AssertThatException<T> assertWhen(Statement<?,T> underTest)
The goal of assertWhen is to provide a way to validate that
an exception is thrown.
For instance
assertWhen((p) -> {
throw new Throwable("test");
}).throwException(exceptionMessage("test"));
Will run a piece of code that always thrown an exception and then
validate that the message of the exception is test.T - the exception typeunderTest - the Statement (p)->{}the assert DSL on the exceptiondefault <P,T extends Throwable> AssertThatException<T> assertWhen(Statement<P,T> underTest, P param)
The goal of assertWhen is to provide a way to validate that
an exception is thrown.
For instance
assertWhen((p) -> {
throw new Throwable("test");
}, null).throwException(exceptionMessage("test"));
Will run a piece of code, passing null as parameter, that always thrown
an exception and then validate that the message of the exception is
test.P - the type of the parameterT - the exception typeunderTest - the Statement (p)->{}param - the parameter for the statement underTestthe assert DSL on the exceptiondefault <T extends Throwable> AssertThatException<T> assertWhen(String msg, Statement<?,T> underTest)
The goal of assertWhen is to provide a way to validate that
an exception is thrown.
For instance
assertWhen("msg", (p) -> {
throw new Throwable("test");
}).throwException(exceptionMessage("test"));
Will run a piece of code that always thrown an exception and then
validate that the message of the exception is test.T - the exception typemsg - a messageunderTest - the statement (p)->{}the assert DSL on the exceptiondefault <P,T extends Throwable> AssertThatException<T> assertWhen(String msg, Statement<P,T> underTest, P param)
The goal of assertWhen is to provide a way to validate that
an exception is thrown.
For instance
assertWhen("msg", (p) -> {
throw new Throwable("test");
}, null).throwException(exceptionMessage("test"));
Will run a piece of code, passing null as parameter, that always thrown
an exception and then validate that the message of the exception is
test.P - the type of the parameterT - the exception typemsg - a messageunderTest - the statement (p)->{}param - the parameter for the statement underTestthe assert DSL on the exceptiondefault void fail()
For instance :
fail();will immediately fail the current test.
default void fail(String msg)
For instance :
fail("my message");
will immediately fail the current test.msg - a messagedefault void fail(String msg, Throwable innerError)
For instance :
fail("my message", t);
will immediately fail the current test.msg - a messageinnerError - the error causedefault <T> AssertThatObject<T> assumeThat(T obj)
For instance
assumeThat(myObject).is(myOtherObject);This will check that
myObject is myOtherObject
(using the equalTo Hamcrest matcher).T - the object type.obj - the objectthe assert DSL on this objectdefault <T> AssertThatObject<T> assumeThat(String msg, T obj)
For instance
assumeThat("msg", myObject).is(myOtherObject);
This will check that myObject is myOtherObject
(using the equalTo Hamcrest matcher).T - the object type.msg - a messageobj - the objectthe assert DSL on this objectdefault AssertThatString assumeThat(String obj)
For instance
assumeThat(myString).is("");
This will check that myString is "" (using the
equalTo Hamcrest matcher).obj - the Stringthe assert DSL on this objectdefault AssertThatString assumeThat(String msg, String obj)
For instance
assumeThat("msg", myString).is("");
This will check that myString is "" (using the
equalTo Hamcrest matcher).msg - a messageobj - the Stringthe assert DSL on this objectdefault <T> AssertThatIterable<T> assumeThatIterable(Iterable<T> obj)
For instance
assumeThatIterable(myIterable).hasSize(0);This will check that
myIterable has a size of 0.T - the element type.obj - the object (Iterable)the assert DSL on this iterabledefault <T> AssertThatIterable<T> assumeThatIterable(String msg, Iterable<T> obj)
For instance
assumeThatIterable("msg", myIterable).hasSize(0);
This will check that myIterable has a size of 0.T - the element type.msg - a messageobj - the object (Iterable)the assert DSL on this iterabledefault <T,R> AssertThatObject<R> assumeThatFunction(java.util.function.Function<T,R> function, T input)
The purpose of this variant of assumeThat provides a way to apply a function on some input and to check the result.
For instance
assumeThatFunction((a) -> a + "x", "b").is("bx")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the input of the functionR - the object type of the resultfunction - the functioninput - the input to the functionthen assert DSL on the result of the
functiondefault <T,R> AssertThatObject<R> assumeThatFunction(String msg, java.util.function.Function<T,R> function, T input)
The purpose of this variant of assertThat provides a way to apply a function on some input and to check the result.
For instance
assumeThatFunction("msg", (a) -> a + "x", "b").is("bx")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the input of the functionR - the object type of the resultmsg - a messagefunction - the functioninput - the input to the functionthen assert DSL on the result of the
functiondefault <T,U,R> AssertThatObject<R> assumeThatBiFunction(java.util.function.BiFunction<T,U,R> function, T input1, U input2)
The purpose of this variant of assumeThat provides a way to apply a bifunction on some input and to check the result.
For instance
assumeThatBiFunction((a, b) -> a + b, "a", "b").is("ab")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the first input of the functionU - the object type fo the second input of the functionR - the object type of the resultfunction - the functioninput1 - the first input to the functioninput2 - the second input to the functionthen assert DSL on the result of the
bifunctiondefault <T,U,R> AssertThatObject<R> assumeThatBiFunction(String msg, java.util.function.BiFunction<T,U,R> function, T input1, U input2)
The purpose of this variant of assumeThat provides a way to apply a bifunction on some input and to check the result.
For instance
assumeThatBiFunction((a, b) -> a + b, "a", "b").is("ab")
This will pass the b string to the passed function (which
add a x add the end of the string and then it will check
that this string is bx (which is the case).T - the object type of the first input of the functionU - the object type fo the second input of the functionR - the object type of the resultmsg - a messagefunction - the functioninput1 - the first input to the functioninput2 - the second input to the functionthen assert DSL on the result of the
bifunctiondefault <T extends Throwable> AssertThatException<T> assumeWhen(Statement<?,T> underTest)
The goal of assumeWhen is to provide a way to validate that
an exception is thrown.
For instance
assumeWhen((p) -> {
throw new Throwable("test");
}).throwException(exceptionMessage("test"));
Will run a piece of code that always thrown an exception and then
validate that the message of the exception is test.T - the exception typeunderTest - the Statement (p)->{}the assert DSL on the exceptiondefault <P,T extends Throwable> AssertThatException<T> assumeWhen(Statement<P,T> underTest, P param)
The goal of assumeWhen is to provide a way to validate that
an exception is thrown.
For instance
assumeWhen((p) -> {
throw new Throwable("test");
}, null).throwException(exceptionMessage("test"));
Will run a piece of code, passing null as parameter, that always thrown
an exception and then validate that the message of the exception is
test.P - the type of the parameterT - the exception typeunderTest - the Statement (p)->{}param - the parameter for the statement underTestthe assert DSL on the exceptiondefault <T extends Throwable> AssertThatException<T> assumeWhen(String msg, Statement<?,T> underTest)
The goal of assumeWhen is to provide a way to validate that
an exception is thrown.
For instance
assumeWhen("msg", (p) -> {
throw new Throwable("test");
}).throwException(exceptionMessage("test"));
Will run a piece of code that always thrown an exception and then
validate that the message of the exception is test.T - the exception typemsg - a messageunderTest - the statement (p)->{}the assert DSL on the exceptiondefault <P,T extends Throwable> AssertThatException<T> assumeWhen(String msg, Statement<P,T> underTest, P param)
The goal of assumeWhen is to provide a way to validate that
an exception is thrown.
For instance
assumeWhen("msg", (p) -> {
throw new Throwable("test");
}, null).throwException(exceptionMessage("test"));
Will run a piece of code, passing null as parameter, that always thrown
an exception and then validate that the message of the exception is
test.P - the type of the parameterT - the exception typemsg - a messageunderTest - the statement (p)->{}param - the parameter for the statement underTestthe assert DSL on the exceptiondefault void skip()
For instance :
skip();will immediately skip the current test.
default void skip(String msg)
For instance :
skip("my message");
will immediately skip the current test.msg - a messagedefault org.hamcrest.Matcher<Throwable> exceptionMessage(org.hamcrest.Matcher<? super String> matching)
matching - the matcher on the messagedefault org.hamcrest.Matcher<Throwable> exceptionMessage(String message)
message - the expected Messagedefault <T> org.hamcrest.Matcher<Optional<T>> optionalIsPresent()
T - the type for what is inside the optionaldefault <T> org.hamcrest.Matcher<Optional<T>> optionalIsNotPresent()
T - the type for what is inside the optionaldefault <T> org.hamcrest.Matcher<Optional<? super T>> optionalIs(org.hamcrest.Matcher<? super T> subMatcher)
T - the type for what is inside the optionalsubMatcher - the matcher on the datadefault <T> org.hamcrest.Matcher<Optional<? super T>> optionalIs(T target)
T - the type for what is inside the optionaltarget - the target valuedefault org.hamcrest.Matcher<OptionalDouble> optionalDoubleIsPresent()
default org.hamcrest.Matcher<OptionalDouble> optionalDoubleIsNotPresent()
default org.hamcrest.Matcher<OptionalDouble> optionalDoubleIs(org.hamcrest.Matcher<? super Double> subMatcher)
subMatcher - the matcher on the datadefault org.hamcrest.Matcher<OptionalInt> optionalIntIsPresent()
default org.hamcrest.Matcher<OptionalInt> optionalIntIsNotPresent()
default org.hamcrest.Matcher<OptionalInt> optionalIntIs(org.hamcrest.Matcher<? super Integer> subMatcher)
subMatcher - the matcher on the datadefault org.hamcrest.Matcher<OptionalInt> optionalIntIs(Integer target)
target - the target valuedefault org.hamcrest.Matcher<OptionalLong> optionalLongIsPresent()
default org.hamcrest.Matcher<OptionalLong> optionalLongIsNotPresent()
default org.hamcrest.Matcher<OptionalLong> optionalLongIs(org.hamcrest.Matcher<? super Long> subMatcher)
subMatcher - the matcher on the datadefault org.hamcrest.Matcher<OptionalLong> optionalLongIs(Long target)
target - the target valuedefault org.hamcrest.Matcher<String> matchesRegex(Pattern pattern)
Pattern.
assertThat("abc").is(matchesRegex(Pattern.compile("ˆ[a-z]$"));
pattern - the pattern to be used.default org.hamcrest.Matcher<String> matchesRegex(String regex)
assertThat("abc").is matchesRegex("ˆ[a-z]+$"));
regex - The regex to be used for the validation.default <T> org.hamcrest.Matcher<T> allOf(Iterable<org.hamcrest.Matcher<? super T>> matchers)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectmatchers - the list of matcher to be applieddefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T>... matchers)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectmatchers - the list of matcher to be applieddefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherdefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherdefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherdefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherfifth - the fifth Matcherdefault <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth)
For example:
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherfifth - the fifth Matchersixth - the sixth Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(Iterable<org.hamcrest.Matcher<? super T>> matchers)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectmatchers - the list of matcher to be applieddefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherfifth - the fifth Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherthird - the third Matcherfourth - the fourth Matcherfifth - the fifth Matchersixth - the sixth Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectfirst - the first Matchersecond - the second Matcherdefault <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<? super T>... matchers)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T - The type of the objectmatchers - the matchersdefault <LHS> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<LHS> both(org.hamcrest.Matcher<? super LHS> matcher)
For example:
assertThat("fab", both(containsString("a")).and(containsString("b")))
LHS - Left Hand Sidematcher - the second matcherdefault <LHS> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<LHS> either(org.hamcrest.Matcher<? super LHS> matcher)
For example:
assertThat("fan", either(containsString("a")).and(containsString("b")))
LHS - Left Hand Sidematcher - the second matcherdefault <T> org.hamcrest.Matcher<T> describedAs(String description, org.hamcrest.Matcher<T> matcher, Object... values)
For example:
describedAs("a big decimal equal to %0", equalTo(myBigDecimal),
myBigDecimal.toPlainString())
T - the type of the objectdescription - the new description for the wrapped matchermatcher - the matcher to wrapvalues - optional values to insert into the tokenised descriptiondefault <U> org.hamcrest.Matcher<Iterable<U>> everyItem(org.hamcrest.Matcher<U> itemMatcher)
Iterables 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")))
U - The item typeitemMatcher - the matcher to apply to every item provided by the examined
Iterabledefault <T> org.hamcrest.Matcher<T> is(T value)
is(equalTo(x)).
For example:
assertThat(cheese, is(smelly))instead of:
assertThat(cheese, is(equalTo(smelly)))
T - The type of data.value - the datadefault <T> org.hamcrest.Matcher<T> is(org.hamcrest.Matcher<T> matcher)
For example:
assertThat(cheese, is(equalTo(smelly)))instead of:
assertThat(cheese, equalTo(smelly))
T - The type of data.matcher - the matcher on datadefault <T> org.hamcrest.Matcher<T> isA(Class<T> type)
is(instanceOf(SomeClass.class)).
For example:
assertThat(cheese, isA(Cheddar.class))instead of:
assertThat(cheese, is(instanceOf(Cheddar.class)))
T - The type of data.type - the expected data typedefault org.hamcrest.Matcher<Object> anything()
default org.hamcrest.Matcher<Object> anything(String description)
String.description - a meaningful String used when describing itselfdefault <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(T item)
Iterables 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"))
T - element Typeitem - the item to compare against the items provided by the examined
Iterabledefault <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher)
Iterables 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")))
T - the element typeitemMatcher - the matcher to apply to items provided by the examined
Iterabledefault <T> org.hamcrest.Matcher<Iterable<T>> hasItems(T... items)
Iterables 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"))
T - the element type.items - the items to compare against the items provided by the
examined Iterabledefault <T> org.hamcrest.Matcher<Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers)
Iterables 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")))
T - the element typeitemMatchers - the matchers to apply to items provided by the examined
Iterabledefault <T> org.hamcrest.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
Arrays, whereby it will match if both the operand and the
examined object are arrays of the same length and contain items that are
equal to each other (according to the above rules) in the same
indexes.
For example:
assertThat("foo", equalTo("foo"));
assertThat(new String[] { "foo", "bar" },
equalTo(new String[] { "foo", "bar" }));
T - The typeoperand - the target value.default <T> org.hamcrest.Matcher<T> any(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))
For example:
assertThat(new Canoe(), instanceOf(Canoe.class));
T - The typetype - the type for the instanceOfdefault <T> org.hamcrest.Matcher<T> instanceOf(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));
T - The typetype - the type for the instanceofdefault <T> org.hamcrest.Matcher<T> not(org.hamcrest.Matcher<T> matcher)
For example:
assertThat(cheese, is(not(equalTo(smelly))))
T - The typematcher - the matcher whose sense should be inverteddefault <T> org.hamcrest.Matcher<T> not(T value)
not(equalTo(x)).
For example:
assertThat(cheese, is(not(smelly)))instead of:
assertThat(cheese, is(not(equalTo(smelly))))
T - The typevalue - the value that any examined object should not equaldefault org.hamcrest.Matcher<Object> nullValue()
null.
For example:
assertThat(cheese, is(nullValue())
default <T> org.hamcrest.Matcher<T> nullValue(Class<T> type)
null.
Accepts a single dummy argument to facilitate type inference.
For example:
assertThat(cheese, is(nullValue(Cheese.class))
T - The typetype - dummy parameter used to infer the generic type of the returned
matcherdefault org.hamcrest.Matcher<Object> notNullValue()
not(nullValue()).
For example:
assertThat(cheese, is(notNullValue()))instead of:
assertThat(cheese, is(not(nullValue())))
default <T> org.hamcrest.Matcher<T> notNullValue(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))))
T - The typetype - dummy parameter used to infer the generic type of the returned
matcherdefault <T> org.hamcrest.Matcher<T> sameInstance(T target)
T - The typetarget - the target instance against which others should be assesseddefault <T> org.hamcrest.Matcher<T> theInstance(T target)
T - The typetarget - the target instance against which others should be assesseddefault org.hamcrest.Matcher<String> containsString(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 stringdefault org.hamcrest.Matcher<String> startsWith(String prefix)
String starts with
the specified String.
For example:
assertThat("myStringOfNote", startsWith("my"))
prefix - the substring that the returned matcher will expect at the
start of any examined stringdefault org.hamcrest.Matcher<String> endsWith(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 stringdefault <T> org.hamcrest.collection.IsArray<T> array(org.hamcrest.Matcher<? super T>... elementMatchers)
For example:
assertThat(new Integer[] { 1, 2, 3 },
is(array(equalTo(1), equalTo(2), equalTo(3))))
T - The element typeelementMatchers - the matchers that the elements of examined arrays should
satisfydefault <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element)
hasItemInArray(equalTo(x))
.
For example:
assertThat(hasItemInArray(x))instead of:
assertThat(hasItemInArray(equalTo(x)))
T - The element typeelement - the element that should be present in examined arraysdefault <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.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")))
T - The element typeelementMatcher - the matcher to apply to elements in examined arraysdefault <E> org.hamcrest.Matcher<E[]> arrayContaining(List<org.hamcrest.Matcher<? super E>> itemMatchers)
For example:
assertThat(new String[] { "foo", "bar" },
contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
E - The element typeitemMatchers - a list of matchers, each of which must be satisfied by the
corresponding item in an examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items)
For example:
assertThat(new String[] { "foo", "bar" }, contains("foo", "bar"))
E - The element typeitems - the items that must equal the items within an examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher<? super E>... itemMatchers)
For example:
assertThat(new String[] { "foo", "bar" },
contains(equalTo("foo"), equalTo("bar")))
E - The element typeitemMatchers - the matchers that must be satisfied by the items in the
examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(E... 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"))
E - The element typeitems - the items that must equal the entries of an examined array, in
any orderdefault <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcrest.Matcher<? super E>... itemMatchers)
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")))
E - The element typeitemMatchers - a list of matchers, each of which must be satisfied by an
entry in an examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(Collection<org.hamcrest.Matcher<? super E>> itemMatchers)
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"))))
E - The element typeitemMatchers - a list of matchers, each of which must be satisfied by an item
provided by an examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayWithSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
length of
the array satisfies the specified matcher.
For example:
assertThat(new String[] { "foo", "bar" }, arrayWithSize(equalTo(2)))
E - The element typesizeMatcher - a matcher for the length of an examined arraydefault <E> org.hamcrest.Matcher<E[]> arrayWithSize(int size)
length of
the array equals the specified size.
For example:
assertThat(new String[] { "foo", "bar" }, arrayWithSize(2))
E - The element typesize - the length that an examined array must have for a positive
matchdefault <E> org.hamcrest.Matcher<E[]> emptyArray()
length of
the array is zero.
For example:
assertThat(new String[0], emptyArray())
E - The element typedefault <E> org.hamcrest.Matcher<Collection<? extends E>> hasSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
Collections that matches when the
size() method returns a value that satisfies the specified
matcher.
For example:
assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
E - The element typesizeMatcher - a matcher for the size of an examined
Collectiondefault <E> org.hamcrest.Matcher<Collection<? extends E>> hasSize(int size)
Collections that matches when the
size() method returns a value equal to the specified
size.
For example:
assertThat(Arrays.asList("foo", "bar"), hasSize(2))
E - The element typesize - the expected size of an examined Collectiondefault <E> org.hamcrest.Matcher<Collection<? extends E>> empty()
Collections matching examined
collections whose isEmpty method returns true.
For example:
assertThat(new ArrayList<String>(), is(empty()))
E - The element typedefault <E> org.hamcrest.Matcher<Collection<E>> emptyCollectionOf(Class<E> type)
Collections matching examined
collections whose isEmpty method returns true.
For example:
assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
E - The element Typetype - the type of the collection's contentdefault <E> org.hamcrest.Matcher<Iterable<? extends E>> emptyIterable()
Iterables matching examined iterables that
yield no items.
For example:
assertThat(new ArrayList<String>(), is(emptyIterable()))
E - The element typedefault <E> org.hamcrest.Matcher<Iterable<E>> emptyIterableOf(Class<E> type)
Iterables matching examined iterables that
yield no items.
For example:
assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
E - The element typetype - the type of the iterable's contentdefault <E> org.hamcrest.Matcher<Iterable<? extends E>> contains(org.hamcrest.Matcher<? super E>... itemMatchers)
Iterables 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")))
E - The element typeitemMatchers - the matchers that must be satisfied by the items provided by
an examined Iterabledefault <E> org.hamcrest.Matcher<Iterable<? extends E>> contains(E... items)
Iterables 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"))
E - the element typeitems - the items that must equal the items provided by an examined
Iterabledefault <E> org.hamcrest.Matcher<Iterable<? extends E>> contains(org.hamcrest.Matcher<? super E> itemMatcher)
Iterables 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")))
E - the element typeitemMatcher - the matcher that must be satisfied by the single item provided
by an examined Iterabledefault <E> org.hamcrest.Matcher<Iterable<? extends E>> contains(List<org.hamcrest.Matcher<? super E>> itemMatchers)
Iterables 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"))))
E - the element typeitemMatchers - a list of matchers, each of which must be satisfied by the
corresponding item provided by an examined Iterabledefault <T> org.hamcrest.Matcher<Iterable<? extends T>> containsInAnyOrder(T... items)
Iterables 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"))
T - the element typeitems - the items that must equal the items provided by an examined
Iterable in any orderdefault <T> org.hamcrest.Matcher<Iterable<? extends T>> containsInAnyOrder(Collection<org.hamcrest.Matcher<? super T>> itemMatchers)
Iterables 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"))))
T - the type elementitemMatchers - a list of matchers, each of which must be satisfied by an item
provided by an examined Iterabledefault <T> org.hamcrest.Matcher<Iterable<? extends T>> containsInAnyOrder(org.hamcrest.Matcher<? super T>... itemMatchers)
Iterables 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")))
T - the type elementitemMatchers - a list of matchers, each of which must be satisfied by an item
provided by an examined Iterabledefault <E> org.hamcrest.Matcher<Iterable<E>> iterableWithSize(org.hamcrest.Matcher<? super Integer> sizeMatcher)
Iterables 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)))
E - the element typesizeMatcher - a matcher for the number of items that should be yielded by an
examined Iterabledefault <E> org.hamcrest.Matcher<Iterable<E>> iterableWithSize(int size)
Iterables 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))
E - the element typesize - the number of items that should be yielded by an examined
Iterabledefault <K,V> org.hamcrest.Matcher<Map<? extends K,? extends V>> hasEntry(K key, V value)
Maps 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"))
K - The key typeV - The value typekey - 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 entrydefault <K,V> org.hamcrest.Matcher<Map<? extends K,? extends V>> hasEntry(org.hamcrest.Matcher<? super K> keyMatcher, org.hamcrest.Matcher<? super V> valueMatcher)
Maps 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")))
K - the key typeV - the value typekeyMatcher - 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 entrydefault <K> org.hamcrest.Matcher<Map<? extends K,?>> hasKey(org.hamcrest.Matcher<? super K> keyMatcher)
Maps matching when the examined
Map contains at least one key that satisfies the
specified matcher.
For example:
assertThat(myMap, hasKey(equalTo("bar")))
K - the key typekeyMatcher - the matcher that must be satisfied by at least one keydefault <K> org.hamcrest.Matcher<Map<? extends K,?>> hasKey(K key)
Maps matching when the examined
Map contains at least one key that is equal to the
specified key.
For example:
assertThat(myMap, hasKey("bar"))
K - the key typekey - the key that satisfying maps must containdefault <V> org.hamcrest.Matcher<Map<?,? extends V>> hasValue(V value)
Maps matching when the examined
Map contains at least one value that is equal to the
specified value.
For example:
assertThat(myMap, hasValue("foo"))
V - the value typevalue - the value that satisfying maps must containdefault <V> org.hamcrest.Matcher<Map<?,? extends V>> hasValue(org.hamcrest.Matcher<? super V> valueMatcher)
Maps matching when the examined
Map contains at least one value that satisfies the
specified valueMatcher.
For example:
assertThat(myMap, hasValue(equalTo("foo")))
V - the value typevalueMatcher - the matcher that must be satisfied by at least one valuedefault <T> org.hamcrest.Matcher<T> isIn(Collection<T> collection)
For example:
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
T - the element typecollection - the collection in which matching items must be founddefault <T> org.hamcrest.Matcher<T> isIn(T[] param1)
default <T> org.hamcrest.Matcher<T> isOneOf(T... elements)
For example:
assertThat("foo", isIn("bar", "foo"))
T - the typeelements - the elements amongst which matching items will be founddefault org.hamcrest.Matcher<Double> closeTo(double operand, double error)
Doubles 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 alloweddefault org.hamcrest.Matcher<BigDecimal> closeTo(BigDecimal operand, BigDecimal error)
BigDecimals 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 alloweddefault <T extends Comparable<T>> org.hamcrest.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))
T - the typevalue - the value which, when passed to the compareTo method of the
examined object, should return zerodefault <T extends Comparable<T>> org.hamcrest.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))
T - the typevalue - the value which, when passed to the compareTo method of the
examined object, should return greater than zerodefault <T extends Comparable<T>> org.hamcrest.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))
T - The Typevalue - the value which, when passed to the compareTo method of the
examined object, should return greater than or equal to zerodefault <T extends Comparable<T>> org.hamcrest.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))
T - The Typevalue - the value which, when passed to the compareTo method of the
examined object, should return less than zerodefault <T extends Comparable<T>> org.hamcrest.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))
T - The Typevalue - the value which, when passed to the compareTo method of the
examined object, should return less than or equal to zerodefault org.hamcrest.Matcher<String> equalToIgnoringCase(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 stringsdefault org.hamcrest.Matcher<String> equalToIgnoringWhiteSpace(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:
For example:
assertThat(" my\tfoo bar ", equalToIgnoringWhiteSpace(" my foo bar"))
expectedString - the expected value of matched stringsdefault org.hamcrest.Matcher<String> isEmptyString()
String that matches when the examined string
has zero length.
For example:
assertThat("", isEmptyString())
default org.hamcrest.Matcher<String> isEmptyOrNullString()
String that matches when the examined string
is null, or has zero length.
For example:
assertThat(((String) null), isEmptyString())
default org.hamcrest.Matcher<String> stringContainsInOrder(Iterable<String> substrings)
String that matches when the examined string
contains all of the specified substrings, regardless of the order of
their appearance.
For example:
assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))
substrings - the substrings that must be contained within matching stringsdefault <T> org.hamcrest.Matcher<T> hasToString(org.hamcrest.Matcher<? super String> toStringMatcher)
toString method returns a value that satisfies the specified
matcher.
For example:
assertThat(true, hasToString(equalTo("TRUE")))
T - The TypetoStringMatcher - the matcher used to verify the toString resultdefault <T> org.hamcrest.Matcher<T> hasToString(String expectedToString)
toString method returns a value equalTo the specified
string.
For example:
assertThat(true, hasToString("TRUE"))
T - The TypeexpectedToString - the expected toString resultdefault <T> org.hamcrest.Matcher<Class<?>> typeCompatibleWith(Class<T> baseType)
Class that matches when the specified
baseType is assignable from the examined class.
For example:
assertThat(Integer.class, typeCompatibleWith(Number.class))
T - The TypebaseType - the base class to examine classes againstdefault org.hamcrest.Matcher<EventObject> eventFrom(Class<? extends EventObject> eventClass, 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 eventdefault org.hamcrest.Matcher<EventObject> eventFrom(Object source)
EventObject that matches any
EventObject announced by source.
For example:
assertThat(myEvent, is(eventFrom(myBean)))
source - the source of the eventdefault <T> org.hamcrest.Matcher<T> hasProperty(String propertyName)
For example:
assertThat(myBean, hasProperty("foo"))
T - The TypepropertyName - the name of the JavaBean property that examined beans should
possessdefault <T> org.hamcrest.Matcher<T> hasProperty(String propertyName, org.hamcrest.Matcher<?> valueMatcher)
For example:
assertThat(myBean, hasProperty("foo", equalTo("bar"))
T - The TypepropertyName - the name of the JavaBean property that examined beans should
possessvalueMatcher - a matcher for the value of the specified property of the
examined beandefault <T> org.hamcrest.Matcher<T> samePropertyValuesAs(T expectedBean)
For example:
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
T - The TypeexpectedBean - the bean against which examined beans are compareddefault org.hamcrest.Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext)
Nodes 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 nodesdefault org.hamcrest.Matcher<Node> hasXPath(String xPath)
Nodes 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 xpathdefault org.hamcrest.Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext, org.hamcrest.Matcher<String> valueMatcher)
Nodes 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 xpathdefault org.hamcrest.Matcher<Node> hasXPath(String xPath, org.hamcrest.Matcher<String> valueMatcher)
Nodes 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 xpathdefault org.hamcrest.Matcher<File> fileCanExecute(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanExecute(is(true)));
matcher - the matcher on the can execute flag.default org.hamcrest.Matcher<File> fileCanExecute(boolean canExecute)
For example :
assertThat(myFile).is(fileCanExecute(true);
canExecute - the expected value for the can execute flag.default org.hamcrest.Matcher<File> fileCanRead(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanRead(is(true)));
matcher - the matcher on the can read flag.default org.hamcrest.Matcher<File> fileCanRead(boolean canRead)
For example :
assertThat(myFile).is(fileCanRead(true);
canRead - the expected value for the can read flag.default org.hamcrest.Matcher<File> fileCanWrite(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanWrite(is(true)));
matcher - the matcher on the can write flag.default org.hamcrest.Matcher<File> fileCanWrite(boolean canWrite)
For example :
assertThat(myFile).is(fileCanWrite(true);
canWrite - the expected value for the can write flag.default org.hamcrest.Matcher<File> fileIsDirectory(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileIsDirectory(is(true)));
matcher - the matcher on the is directory flag.default org.hamcrest.Matcher<File> fileIsDirectory(boolean isDirectory)
For example :
assertThat(myFile).is(fileIsDirectory(true);
isDirectory - the expected value for the is directory flag.default org.hamcrest.Matcher<File> fileExists(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileExists(is(true)));
matcher - the matcher on the exists flag.default org.hamcrest.Matcher<File> fileExists(boolean exists)
For example :
assertThat(myFile).is(fileExists(true);
exists - the expected value for the exists flag.default org.hamcrest.Matcher<File> fileIsAbsolute(org.hamcrest.Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileIsAbsolute(is(true)));
matcher - the matcher on the absolute flag.default org.hamcrest.Matcher<File> fileIsAbsolute(boolean absolute)
For example :
assertThat(myFile).is(fileIsAbsolute(true);
absolute - the expected value for the absolute flag.default org.hamcrest.Matcher<File> fileContains(org.hamcrest.Matcher<String[]> matcher)
The returned String[] is the one produced by list().
matcher - the matcher on the list() result.default org.hamcrest.Matcher<File> fileContains(String atLeastThisName)
atLeastThisName - the file name.default org.hamcrest.Matcher<File> fileNamed(org.hamcrest.Matcher<? super String> matcher)
For example :
assertThat(myFile).is(fileNamed(is("x")));
matcher - the matcher on the name.default org.hamcrest.Matcher<File> fileNamed(String name)
For example :
assertThat(myFile).is(fileNamed("x"));
name - the expected value for the name.default org.hamcrest.Matcher<Path> pathMatchedAsFile(org.hamcrest.Matcher<? super File> matcher)
matcher - the matcher on File.Copyright © 2014. All rights reserved.