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.tester...
(for instance
testerOfMatcher(Class)
) that can be used with the
@TestDelegate
annotation to test some standard classes
(like Matchers, Comparator, Function, etc).
Modifier and Type | Interface and Description |
---|---|
static interface |
ConverterMethod.NoArgumentWithThrowableMethod
Functional Interface for exception method conversion.
|
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> 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 TestRule |
afterContextAware(Consumer<TestContext<Object>>... afters)
Build a after testrule that will receive the
TestContext . |
default <T> Matcher<T> |
allOf(Iterable<Matcher<? super T>> matchers)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <T> Matcher<T> |
allOf(Matcher<? super T>... matchers)
Creates a matcher that matches if the examined object matches ALL
of the specified matchers.
|
default <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.
|
default <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.
|
default <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.
|
default <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.
|
default <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.
|
default <T> 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> AnyOf<T> |
anyOf(Iterable<Matcher<? super T>> matchers)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <T> AnyOf<T> |
anyOf(Matcher<? super T>... matchers)
Creates a matcher that matches if the examined object matches ANY
of the specified matchers.
|
default <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.
|
default <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.
|
default <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.
|
default <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.
|
default <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.
|
default Matcher<Object> |
anything()
Creates a matcher that always matches, regardless of the examined object.
|
default 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> IsArray<T> |
array(Matcher<? super T>... elementMatchers)
Creates a matcher that matches arrays whose elements are satisfied by the
specified matchers.
|
default <E> 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> Matcher<E[]> |
arrayContaining(List<Matcher<? super E>> itemMatchers)
Creates a matcher for arrays that matches when each item in the examined
array satisfies the corresponding matcher in the specified list of
matchers.
|
default <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.
|
default <E> Matcher<E[]> |
arrayContainingInAnyOrder(Collection<Matcher<? super E>> itemMatchers)
Creates an order agnostic matcher for arrays that matches when each item
in the examined array satisfies one matcher anywhere in the specified
collection of matchers.
|
default <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.
|
default <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.
|
default <E> Matcher<E[]> |
arrayWithSize(int size)
Creates a matcher for arrays that matches when the
length of
the array equals the specified size . |
default <E> Matcher<E[]> |
arrayWithSize(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> AssertThatCastableObject<T> |
assertThat(String msg,
T obj)
Assert the value of an object.
|
default <T> AssertThatCastableObject<T> |
assertThat(T obj)
Assert the value of an object.
|
default <T,U,R> AssertThatCastableObject<R> |
assertThatBiFunction(BiFunction<T,U,R> function,
T input1,
U input2)
Assert on a bifunction.
|
default <T,U,R> AssertThatCastableObject<R> |
assertThatBiFunction(String msg,
BiFunction<T,U,R> function,
T input1,
U input2)
Assert on a bifunction.
|
default <T,R> AssertThatCastableObject<R> |
assertThatFunction(Function<T,R> function,
T input)
Assert on a function.
|
default <T,R> AssertThatCastableObject<R> |
assertThatFunction(String msg,
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 Exception> |
assertWhen(Callable<?> underTest)
Assert that a statement (a piece of code) throw an exception.
|
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 Exception> |
assertWhen(String msg,
Callable<?> underTest)
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 <P1,P2,T extends RuntimeException> |
assertWhenBiFunction(BiFunction<P1,P2,?> bifunction,
P1 param1,
P2 param2)
Assert that a bifunction throw an exception.
|
default <P1,P2,T extends RuntimeException> |
assertWhenBiFunction(String msg,
BiFunction<P1,P2,?> bifunction,
P1 param1,
P2 param2)
Assert that a bifunction throw an exception.
|
default <P,T extends RuntimeException> |
assertWhenFunction(Function<P,?> function,
P param)
Assert that a function throw an exception.
|
default <P,T extends RuntimeException> |
assertWhenFunction(String msg,
Function<P,?> function,
P param)
Assert that a function throw an exception.
|
default Statement<?,Throwable> |
asStatement(ConverterMethod.NoArgumentWithThrowableMethod method)
Converter a piece of code to statement.
|
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> AssertThatCastableObject<T> |
assumeThat(String msg,
T obj)
Assume the value of an object.
|
default <T> AssertThatCastableObject<T> |
assumeThat(T obj)
Assume the value of an object.
|
default <T,U,R> AssertThatCastableObject<R> |
assumeThatBiFunction(BiFunction<T,U,R> function,
T input1,
U input2)
Assume on a bifunction.
|
default <T,U,R> AssertThatCastableObject<R> |
assumeThatBiFunction(String msg,
BiFunction<T,U,R> function,
T input1,
U input2)
Assume on a bifunction.
|
default <T,R> AssertThatCastableObject<R> |
assumeThatFunction(Function<T,R> function,
T input)
Assume on a function.
|
default <T,R> AssertThatCastableObject<R> |
assumeThatFunction(String msg,
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 Exception> |
assumeWhen(Callable<?> underTest)
Assume that a statement (a piece of code) throw an exception.
|
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 Exception> |
assumeWhen(String msg,
Callable<?> underTest)
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 <P1,P2,T extends RuntimeException> |
assumeWhenBiFunction(BiFunction<P1,P2,?> bifunction,
P1 param1,
P2 param2)
Assume that a bifunction throw an exception.
|
default <P1,P2,T extends RuntimeException> |
assumeWhenBiFunction(String msg,
BiFunction<P1,P2,?> bifunction,
P1 param1,
P2 param2)
Assume that a bifunction throw an exception.
|
default <P,T extends RuntimeException> |
assumeWhenFunction(Function<P,?> function,
P param)
Assume that a function throw an exception.
|
default <P,T extends RuntimeException> |
assumeWhenFunction(String msg,
Function<P,?> function,
P param)
Assume that a function throw an exception.
|
default TestRule |
before(Runnable... befores)
Build a before testrule.
|
default TestRule |
beforeContextAware(Consumer<TestContext<Object>>... befores)
Build a before testrule that will receive the
TestContext . |
default <LHS> CombinableMatcher.CombinableBothMatcher<LHS> |
both(Matcher<? super LHS> matcher)
Creates a matcher that matches when both of the specified matchers match
the examined object.
|
default Matcher<Calendar> |
calendarIsAfter(Calendar other)
Verify that a
Calendar calendarIs after another one. |
default Matcher<Calendar> |
calendarIsApril()
Verify that the
Calendar calendarIs in april. |
default Matcher<Calendar> |
calendarIsAugust()
Verify that the
Calendar calendarIs in august. |
default Matcher<Calendar> |
calendarIsBefore(Calendar other)
Verify that a
Calendar calendarIs before another one. |
default Matcher<Calendar> |
calendarIsDayOfMonth(int dayOfMonth)
Verify that a
Calendar has a specify
day of month . |
default Matcher<Calendar> |
calendarIsDayOfWeek(int dayOfWeek)
Verify that a
Calendar has a specify day of week . |
default Matcher<Calendar> |
calendarIsDecember()
Verify that the
Calendar calendarIs in december. |
default Matcher<Calendar> |
calendarIsFebruary()
Verify that the
Calendar calendarIs in february. |
default Matcher<Calendar> |
calendarIsFriday()
Verify that the
Calendar calendarIs a friday. |
default Matcher<Calendar> |
calendarIsHourOfDay(int hourOfDay)
Verify that a
Calendar has a specify hour of day . |
default Matcher<Calendar> |
calendarIsJanuary()
Verify that the
Calendar calendarIs in january. |
default Matcher<Calendar> |
calendarIsJuly()
Verify that the
Calendar calendarIs in july. |
default Matcher<Calendar> |
calendarIsJune()
Verify that the
Calendar calendarIs in june. |
default Matcher<Calendar> |
calendarIsMarch()
Verify that the
Calendar calendarIs in march. |
default Matcher<Calendar> |
calendarIsMay()
Verify that the
Calendar calendarIs in may. |
default Matcher<Calendar> |
calendarIsMillisecond(int millisecond)
Verify that a
Calendar has a specify millisecond . |
default Matcher<Calendar> |
calendarIsMinute(int minute)
|
default Matcher<Calendar> |
calendarIsMonday()
Verify that the
Calendar calendarIs a monday. |
default Matcher<Calendar> |
calendarIsMonth(int month)
|
static Matcher<Calendar> |
calendarIsNovember()
Verify that the
Calendar calendarIs in november. |
default Matcher<Calendar> |
calendarIsOctober()
Verify that the
Calendar calendarIs in october. |
default Matcher<Calendar> |
calendarIsSaturday()
Verify that the
Calendar calendarIs a saturday. |
default Matcher<Calendar> |
calendarIsSecond(int second)
|
default Matcher<Calendar> |
calendarIsSeptember()
Verify that the
Calendar calendarIs in september. |
default Matcher<Calendar> |
calendarIsSunday()
Verify that the
Calendar calendarIs a sunday. |
default Matcher<Calendar> |
calendarIsThurday()
Verify that the
Calendar calendarIs a thurday. |
default Matcher<Calendar> |
calendarIsTuesday()
Verify that the
Calendar calendarIs a tuesday. |
default Matcher<Calendar> |
calendarIsWednesday()
Verify that the
Calendar calendarIs a wednesday. |
default Matcher<Calendar> |
calendarIsYear(int year)
|
default Function<Calendar,Date> |
calendarToDate()
|
default Matcher<BigDecimal> |
closeTo(BigDecimal operand,
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 . |
default Matcher<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 . |
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> Matcher<Iterable<? extends E>> |
contains(E... items)
|
default <E> Matcher<Iterable<? extends E>> |
contains(List<Matcher<? super E>> itemMatchers)
|
default <E> Matcher<Iterable<? extends E>> |
contains(Matcher<? super E>... itemMatchers)
|
default <E> Matcher<Iterable<? extends E>> |
contains(Matcher<? super E> itemMatcher)
|
default <T> Matcher<Iterable<? extends T>> |
containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers)
|
default <T> Matcher<Iterable<? extends T>> |
containsInAnyOrder(Matcher<? super T>... itemMatchers)
|
default <T> Matcher<Iterable<? extends T>> |
containsInAnyOrder(T... items)
|
default Matcher<String> |
containsString(String substring)
|
default Function<Date,Calendar> |
dateToCalendar()
|
default <T> Matcher<T> |
describedAs(String description,
Matcher<T> matcher,
Object... values)
Wraps an existing matcher, overriding its description with that
specified.
|
default SystemStreamRule |
disableBothStreams()
Provide a test rule that suppress both
system
err and system out . |
default SystemStreamRule |
disableErrStream()
Provide a test rule that suppress the
system
err stream. |
default SystemStreamRule |
disableOutStream()
Provide a test rule that suppress the
system
out stream. |
default <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> |
either(Matcher<? super LHS> matcher)
Creates a matcher that matches when either of the specified matchers
match the examined object.
|
default <E> Matcher<Collection<? extends E>> |
empty()
|
default <E> Matcher<E[]> |
emptyArray()
Creates a matcher for arrays that matches when the
length of
the array is zero. |
default <E> Matcher<Collection<E>> |
emptyCollectionOf(Class<E> type)
|
default <E> Matcher<Iterable<? extends E>> |
emptyIterable()
Creates a matcher for
Iterable s matching examined iterables that
yield no items. |
default <E> Matcher<Iterable<E>> |
emptyIterableOf(Class<E> type)
Creates a matcher for
Iterable s matching examined iterables that
yield no items. |
default Matcher<String> |
endsWith(String suffix)
|
default <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. |
default 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 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 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 Matcher<EventObject> |
eventFrom(Object source)
Creates a matcher of
EventObject that matches any
EventObject announced by source. |
default <U> Matcher<Iterable<U>> |
everyItem(Matcher<U> itemMatcher)
|
default Matcher<Throwable> |
exceptionMessage(Matcher<? super String> matching)
Validate the message of an exception
|
default Matcher<Throwable> |
exceptionMessage(String message)
Validate the message of an exception
|
default boolean |
fail()
Always produce a failure.
|
default boolean |
fail(String msg)
Always produce a failure.
|
default boolean |
fail(String msg,
Throwable innerError)
Always produce a failure.
|
default boolean |
fail(Throwable innerError)
Always produce a failure.
|
default <T,F> Matcher<T> |
featureMatcher(Class<T> clazz,
Class<F> featureClazz,
String featureName,
Function<T,F> featureExtractor,
Matcher<? super F> subMatcher)
Create a feature matcher, on the fly.
|
default Matcher<File> |
fileCanExecute(boolean canExecute)
Validate that a file can execute.
|
default Matcher<File> |
fileCanExecute(Matcher<? super Boolean> matcher)
Validate that a file can execute.
|
default Matcher<File> |
fileCanRead(boolean canRead)
Validate that a file can read.
|
default Matcher<File> |
fileCanRead(Matcher<? super Boolean> matcher)
Validate that a file can read.
|
default Matcher<File> |
fileCanWrite(boolean canWrite)
Validate that a file can write.
|
default Matcher<File> |
fileCanWrite(Matcher<? super Boolean> matcher)
Validate that a file can write.
|
default Matcher<File> |
fileContains(Matcher<String[]> matcher)
Validate that a file contains something.
|
default Matcher<File> |
fileContains(String atLeastThisName)
Validate that a file contains some other file name.
|
default Matcher<File> |
fileExists(boolean exists)
Validate that a file exists.
|
default Matcher<File> |
fileExists(Matcher<? super Boolean> matcher)
Validate that a file exists.
|
default Matcher<File> |
fileIsAbsolute(boolean absolute)
Validate that a file is absolute.
|
default Matcher<File> |
fileIsAbsolute(Matcher<? super Boolean> matcher)
Validate that a file is absolute.
|
default Matcher<File> |
fileIsDirectory(boolean isDirectory)
Validate that a file is a directory.
|
default Matcher<File> |
fileIsDirectory(Matcher<? super Boolean> matcher)
Validate that a file is a directory.
|
default Matcher<File> |
fileNamed(Matcher<? super String> matcher)
Validate that a file has some name.
|
default Matcher<File> |
fileNamed(String name)
Validate that a file has some name.
|
default <T> Matcher<Future<T>> |
futureIsBeforeTimeout(Matcher<? super T> matching,
long timeout,
TimeUnit unit)
Retrieve the value of a
Future , with timeout support and validate
the value. |
default <T> Matcher<Future<T>> |
futureIsCancelled(boolean expected)
Verify if a
Future is cancelled. |
default <T> Matcher<Future<T>> |
futureIsDone(boolean expected)
Verify if a
Future is done. |
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> Matcher<Map<? extends K,? extends V>> |
hasEntry(K key,
V value)
|
default <K,V> Matcher<Map<? extends K,? extends V>> |
hasEntry(Matcher<? super K> keyMatcher,
Matcher<? super V> valueMatcher)
|
default <T> Matcher<Iterable<? super T>> |
hasItem(Matcher<? super T> itemMatcher)
|
default <T> Matcher<Iterable<? super T>> |
hasItem(T item)
|
default <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 . |
default <T> Matcher<T[]> |
hasItemInArray(T element)
A shortcut to the frequently used
hasItemInArray(equalTo(x))
. |
default <T> Matcher<Iterable<T>> |
hasItems(Matcher<? super T>... itemMatchers)
|
default <T> Matcher<Iterable<T>> |
hasItems(T... items)
|
default <K> Matcher<Map<? extends K,?>> |
hasKey(K key)
|
default <K> Matcher<Map<? extends K,?>> |
hasKey(Matcher<? super K> keyMatcher)
|
default <T> Matcher<T> |
hasProperty(String propertyName)
Creates a matcher that matches when the examined object has a JavaBean
property with the specified name.
|
default <T> Matcher<T> |
hasProperty(String propertyName,
Matcher<?> valueMatcher)
Creates a matcher that matches when the examined object has a JavaBean
property with the specified name whose value satisfies the specified
matcher.
|
default <E> Matcher<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 . |
default <E> Matcher<Collection<? extends E>> |
hasSize(Matcher<? super Integer> sizeMatcher)
Creates a matcher for
Collection s that matches when the
size() method returns a value that satisfies the specified
matcher. |
default <T> Matcher<T> |
hasToString(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> 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> Matcher<Map<?,? extends V>> |
hasValue(Matcher<? super V> valueMatcher)
|
default <V> Matcher<Map<?,? extends V>> |
hasValue(V value)
|
default Matcher<Node> |
hasXPath(String xPath)
Creates a matcher of
Node s that matches when the
examined node contains a node at the specified xPath , with
any content. |
default Matcher<Node> |
hasXPath(String xPath,
Matcher<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 . |
default Matcher<Node> |
hasXPath(String xPath,
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. |
default Matcher<Node> |
hasXPath(String xPath,
NamespaceContext namespaceContext,
Matcher<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 . |
default <T> 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> Matcher<T> |
is(Matcher<T> matcher)
Decorates another Matcher, retaining its behaviour, but allowing tests to
be slightly more expressive.
|
default <T> Matcher<T> |
is(T value)
A shortcut to the frequently used
is(equalTo(x)) . |
default <T> Matcher<T> |
isA(Class<T> type)
A shortcut to the frequently used
is(instanceOf(SomeClass.class)) . |
default Matcher<String> |
isEmptyOrNullString()
Creates a matcher of
String that matches when the examined string
is null , or has zero length. |
default Matcher<String> |
isEmptyString()
Creates a matcher of
String that matches when the examined string
has zero length. |
default <T> Matcher<T> |
isIn(Collection<T> collection)
Creates a matcher that matches when the examined object is found within
the specified collection.
|
default <T> Matcher<T> |
isIn(T[] param1) |
default <T> Matcher<T> |
isOneOf(T... elements)
Creates a matcher that matches when the examined object is equal to one
of the specified elements.
|
default <E> Matcher<Iterable<E>> |
iterableWithSize(int size)
|
default <E> Matcher<Iterable<E>> |
iterableWithSize(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 Matcher<LocalDate> |
localDateIsDayOfMonth(int day)
Verify the day of a
LocalDate . |
default Matcher<LocalDate> |
localDateIsMonth(Month month)
Verify the month of a
LocalDate . |
default Matcher<LocalDate> |
localDateIsYear(int year)
Verify the year of a
LocalDate . |
default Matcher<LocalTime> |
localTimeIsHour(int hour)
Verify the hour of a
LocalTime . |
default Matcher<LocalTime> |
localTimeIsMinute(int minute)
Verify the minute of a
LocalTime . |
default Matcher<LocalTime> |
localTimeIsNano(int nano)
Verify the nano of a
LocalTime . |
default Matcher<LocalTime> |
localTimeIsSecond(int second)
Verify the second of a
LocalTime . |
default <K,V> Function<Map<K,V>,V> |
mapToValue(K key)
Return a function that get a value from a
Map , as converter. |
default <T> Predicate<T> |
matcherPredicate(Matcher<T> matcher)
Expose a matcher as a predicate.
|
default Matcher<String> |
matchesRegex(Pattern pattern)
Validate a string with a
Pattern . |
default Matcher<String> |
matchesRegex(String regex)
Validate a string with a regex.
|
default TestRule |
mockitoRule()
Create a rule to support mockito.
|
default <T> Matcher<T> |
not(Matcher<T> matcher)
Creates a matcher that wraps an existing matcher, but inverts the logic
by which it will match.
|
default <T> Matcher<T> |
not(T value)
A shortcut to the frequently used
not(equalTo(x)) . |
default Matcher<Object> |
notNullValue()
A shortcut to the frequently used
not(nullValue()) . |
default <T> Matcher<T> |
notNullValue(Class<T> type)
A shortcut to the frequently used
not(nullValue(X.class)). |
default <T,R> Function<T,R> |
nullToNullConverter(Function<T,R> converter)
Return a converter that return null if the receiver is null or else
return the result of the received converter.
|
default Matcher<Object> |
nullValue()
Creates a matcher that matches if examined object is
null . |
default <T> Matcher<T> |
nullValue(Class<T> type)
Creates a matcher that matches if examined object is
null . |
default Matcher<OptionalDouble> |
optionalDoubleIs(Matcher<? super Double> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default Matcher<OptionalDouble> |
optionalDoubleIsNotPresent()
Check that the passed optional is not present.
|
default Matcher<OptionalDouble> |
optionalDoubleIsPresent()
Check that the passed optional is present.
|
default Matcher<OptionalInt> |
optionalIntIs(Integer target)
Check that the passed optional is some target value.
|
default Matcher<OptionalInt> |
optionalIntIs(Matcher<? super Integer> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default Matcher<OptionalInt> |
optionalIntIsNotPresent()
Check that the passed optional is not present.
|
default Matcher<OptionalInt> |
optionalIntIsPresent()
Check that the passed optional is present.
|
default <T> Matcher<Optional<? super T>> |
optionalIs(Matcher<? super T> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default <T> Matcher<Optional<? super T>> |
optionalIs(T target)
Check that the passed optional is some target value.
|
default <T> Matcher<Optional<T>> |
optionalIsNotPresent()
Check that the passed optional is not present.
|
default <T> Matcher<Optional<T>> |
optionalIsPresent()
Check that the passed optional is present.
|
default Matcher<OptionalLong> |
optionalLongIs(Long target)
Check that the passed optional is some target value.
|
default Matcher<OptionalLong> |
optionalLongIs(Matcher<? super Long> subMatcher)
Check that the passed optional is accepted by some matcher.
|
default Matcher<OptionalLong> |
optionalLongIsNotPresent()
Check that the passed optional is not present.
|
default Matcher<OptionalLong> |
optionalLongIsPresent()
Check that the passed optional is present.
|
default Predicate<Object[]> |
parametersFilterUsingMatcher(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,
Function<T,R> mapFunction)
Start building a Parameter Mapper function, with an initial converter.
|
default Matcher<Path> |
pathMatchedAsFile(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 SystemStreamRule |
replaceBothStream(PrintStream outReplacement,
PrintStream errRemplacement)
Provide a test rule that replace both
system
err and system out with the provided one. |
default SystemStreamRule |
replaceErrStream(PrintStream errReplacement)
Privde a test rule that replace the
system
err stream with the provided one |
default SystemStreamRule |
replaceOutStream(PrintStream outReplacement)
Privde a test rule that replace the
system
out stream with the provided one |
default Matcher<Calendar> |
sameDate(Calendar other)
Verify that the
Calendar calendarIs on same day (year, month, day
of month) that another one. |
default <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.
|
default <T> 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 Matcher<String> |
startsWith(String prefix)
|
default 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,
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,U,R> BiFunctionTesterStartDSL<T,U,R> |
testerOfBiFunction(BiFunction<T,U,R> bifunctionUnderTest)
Use this method to start the DSL to test a bifunction.
|
default <T,R> CollectorTesterDSL0<T,?,R> |
testerOfCollector(Class<T> inputClass,
Class<T> outputClass,
Collector<T,?,R> collectorToTest)
Return a builder to create a tester of
Collector . |
default <T,R> CollectorTesterDSL0<T,?,R> |
testerOfCollector(Collector<T,?,R> collectorToTest)
Return a builder to create a tester of
Collector . |
default <O,C extends Comparator<O>> |
testerOfComparator(Class<C> comparatorClass)
Use this method to start the DSL to test a comparator.
|
default <T,R> FunctionTesterStartDSL<T,R> |
testerOfFunction(Function<T,R> functionUnderTest)
Use this method to start the DSL to test a function.
|
default <T extends Matcher<?>> |
testerOfMatcher(Class<T> matcherClass)
Start the creation of a tester definition for a matcher.
|
default PatternTester0 |
testerOfPattern(Pattern pattern)
Start the DSL to create a tester of Pattern, based on a String.
|
default PatternTester0 |
testerOfPattern(String pattern)
Start the DSL to create a tester of Pattern, based on a String.
|
default TestListenerRule |
testListenerRuleOf(Consumer<TestContext<Object>> onStart,
Consumer<TestContext<Object>> onEnd,
BiConsumer<TestContext<Object>,AssertionError> onFailure,
BiConsumer<TestContext<Object>,Throwable> onError,
BiConsumer<TestContext<Object>,AssumptionError> onAssumptionSkip)
Build a
TestListenerRule based on the various method. |
default TestListenerRule |
testListenerRuleOnEnd(Consumer<TestContext<Object>> onEnd)
Build a
TestListenerRule with only an action at end. |
default TestListenerRule |
testListenerRuleOnStart(Consumer<TestContext<Object>> onStart)
Build a
TestListenerRule with only an action at start. |
default <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.
|
default <T> 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, as 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
.Rule
default TestRule beforeContextAware(Consumer<TestContext<Object>>... befores)
TestContext
.
The passed consumer 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 = beforeContextAware(this::beforeMethodName);
befores
- the beforesthe rule chain
.Rule
default 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
.Rule
default TestRule afterContextAware(Consumer<TestContext<Object>>... afters)
TestContext
.
The passed consumer 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 = afterContextAware(this::afterMethodName);
afters
- the aftersthe rule chain
.Rule
default TestRule mockitoRule()
This provide a way to setup Mockito before each test.
the rule chain
.Rule
default 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
).Rule
default 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.
Rule
default TestRule systemPropertiesRule(String... propertiesName)
propertiesName
- the properties to be restoredthe rule chain
.Rule
default TestRule systemProperty(String propertyName, Supplier<String> propertyValue)
propertyName
- the name of the propertypropertyValue
- the value of the propertythe rule chain
.Rule
default TestRule systemProperty(String propertyName, String propertyValue)
propertyName
- the name of the propertypropertyValue
- the value of the propertythe rule chain
.Rule
default <T,R> StreamParametersMapFunction<T> parametersMap(int idx, 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> Function<Object[],Object[]> addFieldToEachEntry(T field)
T
- The object type to be added.field
- The field to be added.Stream.map(Function)
).default Predicate<Object[]> parametersFilterUsingMatcher(Matcher<Object[]> matcher)
matcher
- the matcherdefault <T> Predicate<T> matcherPredicate(Matcher<T> matcher)
T
- The target object typematcher
- the matcher.default SystemStreamRule disableBothStreams()
system
err
and system out
.The complete description of the
functionnality of the rule.
default SystemStreamRule replaceBothStream(PrintStream outReplacement, PrintStream errRemplacement)
system
err
and system out
with the provided one.outReplacement
- the replacement of the system out
stream.errRemplacement
- the replacement of the system err
stream.The complete description of the
functionnality of the rule.
default SystemStreamRule disableOutStream()
system
out
stream.The complete description of the
functionnality of the rule.
default SystemStreamRule disableErrStream()
system
err
stream.The complete description of the
functionnality of the rule.
default SystemStreamRule replaceOutStream(PrintStream outReplacement)
system
out
stream with the provided oneoutReplacement
- the replacement of the system out
stream.The complete description of the
functionnality of the rule.
default SystemStreamRule replaceErrStream(PrintStream errReplacement)
system
err
stream with the provided oneerrReplacement
- the replacement of the system err
stream.The complete description of the
functionnality of the rule.
default TestListenerRule testListenerRuleOf(Consumer<TestContext<Object>> onStart, Consumer<TestContext<Object>> onEnd, BiConsumer<TestContext<Object>,AssertionError> onFailure, BiConsumer<TestContext<Object>,Throwable> onError, BiConsumer<TestContext<Object>,AssumptionError> onAssumptionSkip)
TestListenerRule
based on the various method.onStart
- the action to be
done before the test start
. If null, nothing is done.onEnd
- the action to be
done after the test end
. If null, nothing is done.onFailure
- the action to be done in case of failure
. If null, nothing is
done.onError
- the
action to be done in case of error
. If null, nothing is done.onAssumptionSkip
- the action to be done in case of assumption skipped
. If null
nothing is done.default TestListenerRule testListenerRuleOnStart(Consumer<TestContext<Object>> onStart)
TestListenerRule
with only an action at start.onStart
- the action to be
done before the test start
.default TestListenerRule testListenerRuleOnEnd(Consumer<TestContext<Object>> onEnd)
TestListenerRule
with only an action at end.onEnd
- the action to be
done after the test end
.default <T> AssertThatCastableObject<T> assertThat(T obj)
For instance
assertThat(myObject).is(myOtherObject);This will check that
myObject
is myOtherObject
(using the equalTo
Hamcrest matcher). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the object type.obj
- the objectthe assert DSL on this object
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T> AssertThatCastableObject<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). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the object type.msg
- a messageobj
- the objectthe assert DSL on this object
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default AssertThatString assertThat(String obj)
For instance
assertThat(myString).is("");This will check that
myString
is ""
(using the
equalTo
Hamcrest matcher). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. obj
- the Stringthe assert DSL on this object
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default AssertThatString assertThat(String msg, String obj)
For instance
assertThat("msg", myString).is("");This will check that
myString
is ""
(using the
equalTo
Hamcrest matcher). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. msg
- a messageobj
- the Stringthe assert DSL on this object
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T> AssertThatIterable<T> assertThatIterable(Iterable<T> obj)
For instance
assertThatIterable(myIterable).hasSize(0);This will check that
myIterable
has a size of 0. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the element type.obj
- the object (Iterable)the assert DSL on this iterable
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <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. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the element type.msg
- a messageobj
- the object (Iterable)the assert DSL on this iterable
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T,R> AssertThatCastableObject<R> assertThatFunction(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). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. 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 function
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T,R> AssertThatCastableObject<R> assertThatFunction(String msg, 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). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. 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 function
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T,U,R> AssertThatCastableObject<R> assertThatBiFunction(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). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. 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 bifunction
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T,U,R> AssertThatCastableObject<R> assertThatBiFunction(String msg, 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). fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. 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
bifunction
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <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
. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the exception typeunderTest
- the Statement
(p)->{}
the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T extends Exception> AssertThatException<T> assertWhen(Callable<?> underTest)
The goal of assertWhen
is to provide a way to validate that
an exception is thrown.
For instance, having this method :
public static void method1() throws Exception { throw new Exception("demo1"); }It can be tested by :
@Test public void testNoArgNoReturn() { assertWhen(asStatement(DemoAssertThatExceptionTest::method1)) .throwException(exceptionMessage("demo1")); }By default, assertThat can only be used from the main thread of the test ; When used from another thread, the assertion will be lost. In the case the
fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the exception typeunderTest
- the Callable
the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <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
. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. P
- the type of the parameterT
- the exception typeunderTest
- the Statement
(p)->{}
param
- the parameter for the statement underTestthe assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <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
. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. T
- the exception typemsg
- a messageunderTest
- the statement (p)->{}
the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <T extends Exception> AssertThatException<T> assertWhen(String msg, Callable<?> underTest)
The goal of assertWhen
is to provide a way to validate that
an exception is thrown.
By default, assertThat can only be used from the main thread of the
test ; When used from another thread, the assertion will be lost. In the
case the fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance.
T
- the exception typemsg
- a messageunderTest
- the callablethe assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <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
. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. 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 exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <P,T extends RuntimeException> AssertThatException<T> assertWhenFunction(String msg, Function<P,?> function, P param)
Function
signature
doesn't throws exception, it should be a RuntimeException. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. P
- the type of the parameterT
- the exception typemsg
- a messagefunction
- the function to be executed and that should return an
exceptionparam
- the parameter to be passed to the function.the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <P,T extends RuntimeException> AssertThatException<T> assertWhenFunction(Function<P,?> function, P param)
Function
signature
doesn't throws exception, it should be a RuntimeException. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. P
- the type of the parameterT
- the exception typefunction
- the function to be executed and that should return an
exceptionparam
- the parameter to be passed to the function.the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <P1,P2,T extends RuntimeException> AssertThatException<T> assertWhenBiFunction(String msg, BiFunction<P1,P2,?> bifunction, P1 param1, P2 param2)
BiFunction
signature doesn't throws exception, it should be a RuntimeException. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. P1
- the type of the first parameterP2
- the type of the second parameterT
- the exception typemsg
- a messagebifunction
- the bifunction to be executed and that should return an
exceptionparam1
- the first parameter to be used.param2
- the second parameter to be used.the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default <P1,P2,T extends RuntimeException> AssertThatException<T> assertWhenBiFunction(BiFunction<P1,P2,?> bifunction, P1 param1, P2 param2)
BiFunction
signature doesn't throws exception, it should be a RuntimeException. fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. P1
- the type of the first parameterP2
- the type of the second parameterT
- the exception typebifunction
- the bifunction to be executed and that should return an
exceptionparam1
- the first parameter to be used.param2
- the second parameter to be used.the assert DSL on the exception
The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this assertion.
default boolean fail()
For instance :
fail();will immediately fail the current test.
fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. Test.fastFail()
: If true
, then
fail the test, else, return false and the test will be failed
later.The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this failure.
default boolean fail(String msg)
For instance :
fail("my message");will immediately fail the current test.
fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. msg
- a messageTest.fastFail()
: If true
, then
fail the test, else, return false and the test will be failed
later.The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this failure.
default boolean fail(String msg, Throwable innerError)
For instance :
fail("my message", t);will immediately fail the current test.
fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. msg
- a messageinnerError
- the error causeTest.fastFail()
: If true
, then
fail the test, else, return false and the test will be failed
later.The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this failure.
default boolean fail(Throwable innerError)
For instance :
fail(t);will immediately fail the current test.
fastFail
attribute of @Test
annotation is used, the assertion may not be lost, in case the thread use
an assertion method from the test object instance. innerError
- the error causeTest.fastFail()
: If true
, then
fail the test, else, return false and the test will be failed
later.The documentation of the fastFail
attribute of the @Test
annotation, regarding the action
done by this failure.
default <T> AssertThatCastableObject<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 object
default <T> AssertThatCastableObject<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 object
default 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 object
default 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 object
default <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 iterable
default <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 iterable
default <T,R> AssertThatCastableObject<R> assumeThatFunction(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 function
default <T,R> AssertThatCastableObject<R> assumeThatFunction(String msg, 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 function
default <T,U,R> AssertThatCastableObject<R> assumeThatBiFunction(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 bifunction
default <T,U,R> AssertThatCastableObject<R> assumeThatBiFunction(String msg, 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 bifunction
default <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 exception
default <T extends Exception> AssertThatException<T> assumeWhen(Callable<?> underTest)
The goal of assumeWhen
is to provide a way to validate that
an exception is thrown.
By default, assumeThat can only be used from the main thread of the
test ; When used from another thread, the assumption will be lost.
T
- the exception typeunderTest
- the Callable
the assert DSL on the exception
default <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 exception
default <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 exception
default <T extends Exception> AssertThatException<T> assumeWhen(String msg, Callable<?> underTest)
By default, assumeThat can only be used from the main thread of the
test ; When used from another thread, the assumption will be lost.
T
- the exception typemsg
- a messageunderTest
- the callablethe assert DSL on the exception
default <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 exception
default <P,T extends RuntimeException> AssertThatException<T> assumeWhenFunction(String msg, Function<P,?> function, P param)
Function
signature
doesn't throws exception, it should be a RuntimeException. P
- the type of the parameterT
- the exception typemsg
- a messagefunction
- the function to be executed and that should return an
exceptionparam
- the parameter to be passed to the function.the assert DSL on the exception
default <P,T extends RuntimeException> AssertThatException<T> assumeWhenFunction(Function<P,?> function, P param)
Function
signature
doesn't throws exception, it should be a RuntimeException. P
- the type of the parameterT
- the exception typefunction
- the function to be executed and that should return an
exceptionparam
- the parameter to be passed to the function.the assert DSL on the exception
default <P1,P2,T extends RuntimeException> AssertThatException<T> assumeWhenBiFunction(String msg, BiFunction<P1,P2,?> bifunction, P1 param1, P2 param2)
BiFunction
signature doesn't throws exception, it should be a RuntimeException. P1
- the type of the first parameterP2
- the type of the second parameterT
- the exception typemsg
- a messagebifunction
- the bifunction to be executed and that should return an
exceptionparam1
- the first parameter to be used.param2
- the second parameter to be used.the assert DSL on the exception
default <P1,P2,T extends RuntimeException> AssertThatException<T> assumeWhenBiFunction(BiFunction<P1,P2,?> bifunction, P1 param1, P2 param2)
BiFunction
signature doesn't throws exception, it should be a RuntimeException. P1
- the type of the first parameterP2
- the type of the second parameterT
- the exception typebifunction
- the bifunction to be executed and that should return an
exceptionparam1
- the first parameter to be used.param2
- the second parameter to be used.the assert DSL on the exception
default 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 Matcher<Throwable> exceptionMessage(Matcher<? super String> matching)
matching
- the matcher on the messagedefault Matcher<Throwable> exceptionMessage(String message)
message
- the expected Messagedefault <T> Matcher<Optional<T>> optionalIsPresent()
T
- the type for what is inside the optionaldefault <T> Matcher<Optional<T>> optionalIsNotPresent()
T
- the type for what is inside the optionaldefault <T> Matcher<Optional<? super T>> optionalIs(Matcher<? super T> subMatcher)
T
- the type for what is inside the optionalsubMatcher
- the matcher on the datadefault <T> Matcher<Optional<? super T>> optionalIs(T target)
T
- the type for what is inside the optionaltarget
- the target valuedefault Matcher<OptionalDouble> optionalDoubleIsPresent()
default Matcher<OptionalDouble> optionalDoubleIsNotPresent()
default Matcher<OptionalDouble> optionalDoubleIs(Matcher<? super Double> subMatcher)
subMatcher
- the matcher on the datadefault Matcher<OptionalInt> optionalIntIsPresent()
default Matcher<OptionalInt> optionalIntIsNotPresent()
default Matcher<OptionalInt> optionalIntIs(Matcher<? super Integer> subMatcher)
subMatcher
- the matcher on the datadefault Matcher<OptionalInt> optionalIntIs(Integer target)
target
- the target valuedefault Matcher<OptionalLong> optionalLongIsPresent()
default Matcher<OptionalLong> optionalLongIsNotPresent()
default Matcher<OptionalLong> optionalLongIs(Matcher<? super Long> subMatcher)
subMatcher
- the matcher on the datadefault Matcher<OptionalLong> optionalLongIs(Long target)
target
- the target valuedefault Matcher<String> matchesRegex(Pattern pattern)
Pattern
.
assertThat("abc").is(matchesRegex(Pattern.compile("ˆ[a-z]$"));
pattern
- the pattern to be used.default Matcher<String> matchesRegex(String regex)
assertThat("abc").is matchesRegex("ˆ[a-z]+$"));
regex
- The regex to be used for the validation.default <T,F> Matcher<T> featureMatcher(Class<T> clazz, Class<F> featureClazz, String featureName, Function<T,F> featureExtractor, Matcher<? super F> subMatcher)
T
- the type for the matcher.F
- the feature returned by the extractor.clazz
- the clazz of the object supported by the Matcher.featureClazz
- the clazz of the feature.featureName
- the name of the feature.featureExtractor
- the Function
to extract the feature.subMatcher
- the matcher to be applied on the feature.default <T> Matcher<T> allOf(Iterable<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> Matcher<T> allOf(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> Matcher<T> allOf(Matcher<? super T> first, 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> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, 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> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, 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> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, 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> 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)
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> AnyOf<T> anyOf(Iterable<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> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, 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> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, 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> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, 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> 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)
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> AnyOf<T> anyOf(Matcher<T> first, 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> AnyOf<T> anyOf(Matcher<? super T>... matchers)
For example:
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
T
- The type of the objectmatchers
- the matchersdefault <LHS> CombinableMatcher.CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher)
For example:
assertThat("fab", both(containsString("a")).and(containsString("b")))
LHS
- Left Hand Sidematcher
- the second matcherdefault <LHS> CombinableMatcher.CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher)
For example:
assertThat("fan", either(containsString("a")).and(containsString("b")))
LHS
- Left Hand Sidematcher
- the second matcherdefault <T> Matcher<T> describedAs(String description, 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> Matcher<Iterable<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")))
U
- The item typeitemMatcher
- the matcher to apply to every item provided by the examined
Iterable
default <T> 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> Matcher<T> is(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> 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 Matcher<Object> anything()
default Matcher<Object> anything(String description)
String
.description
- a meaningful String
used when describing itselfdefault <T> Matcher<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"))
T
- element Typeitem
- the item to compare against the items provided by the examined
Iterable
default <T> Matcher<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")))
T
- the element typeitemMatcher
- the matcher to apply to items provided by the examined
Iterable
default <T> Matcher<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"))
T
- the element type.items
- the items to compare against the items provided by the
examined Iterable
default <T> Matcher<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")))
T
- the element typeitemMatchers
- the matchers to apply to items provided by the examined
Iterable
default <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.
For example:
assertThat("foo", equalTo("foo")); assertThat(new String[] { "foo", "bar" }, equalTo(new String[] { "foo", "bar" }));
T
- The typeoperand
- the target value.default <T> 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> 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> Matcher<T> not(Matcher<T> matcher)
For example:
assertThat(cheese, is(not(equalTo(smelly))))
T
- The typematcher
- the matcher whose sense should be inverteddefault <T> 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 Matcher<Object> nullValue()
null
.
For example:
assertThat(cheese, is(nullValue())
default <T> 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 Matcher<Object> notNullValue()
not(nullValue())
.
For example:
assertThat(cheese, is(notNullValue()))instead of:
assertThat(cheese, is(not(nullValue())))
default <T> 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> Matcher<T> sameInstance(T target)
T
- The typetarget
- the target instance against which others should be assesseddefault <T> Matcher<T> theInstance(T target)
T
- The typetarget
- the target instance against which others should be assesseddefault 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 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 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> IsArray<T> array(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> 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> 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")))
T
- The element typeelementMatcher
- the matcher to apply to elements in examined arraysdefault <E> Matcher<E[]> arrayContaining(List<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> 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> Matcher<E[]> arrayContaining(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> 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> Matcher<E[]> arrayContainingInAnyOrder(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> Matcher<E[]> arrayContainingInAnyOrder(Collection<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> Matcher<E[]> arrayWithSize(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> 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> Matcher<E[]> emptyArray()
length
of
the array is zero.
For example:
assertThat(new String[0], emptyArray())
E
- The element typedefault <E> Matcher<Collection<? extends E>> hasSize(Matcher<? super 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)))
E
- The element typesizeMatcher
- a matcher for the size of an examined
Collection
default <E> Matcher<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))
E
- The element typesize
- the expected size of an examined Collection
default <E> Matcher<Collection<? extends E>> empty()
Collection
s matching examined
collections whose isEmpty
method returns true
.
For example:
assertThat(new ArrayList<String>(), is(empty()))
E
- The element typedefault <E> Matcher<Collection<E>> emptyCollectionOf(Class<E> type)
Collection
s 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> Matcher<Iterable<? extends E>> emptyIterable()
Iterable
s matching examined iterables that
yield no items.
For example:
assertThat(new ArrayList<String>(), is(emptyIterable()))
E
- The element typedefault <E> Matcher<Iterable<E>> emptyIterableOf(Class<E> type)
Iterable
s 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> Matcher<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")))
E
- The element typeitemMatchers
- the matchers that must be satisfied by the items provided by
an examined Iterable
default <E> Matcher<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"))
E
- the element typeitems
- the items that must equal the items provided by an examined
Iterable
default <E> Matcher<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")))
E
- the element typeitemMatcher
- the matcher that must be satisfied by the single item provided
by an examined Iterable
default <E> Matcher<Iterable<? extends E>> contains(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"))))
E
- the element typeitemMatchers
- a list of matchers, each of which must be satisfied by the
corresponding item provided by an examined Iterable
default <T> Matcher<Iterable<? extends T>> containsInAnyOrder(T... items)
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"))
T
- the element typeitems
- the items that must equal the items provided by an examined
Iterable
in any orderdefault <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers)
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"))))
T
- the type elementitemMatchers
- a list of matchers, each of which must be satisfied by an item
provided by an examined Iterable
default <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers)
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")))
T
- the type elementitemMatchers
- a list of matchers, each of which must be satisfied by an item
provided by an examined Iterable
default <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super 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)))
E
- the element typesizeMatcher
- a matcher for the number of items that should be yielded by an
examined Iterable
default <E> Matcher<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))
E
- the element typesize
- the number of items that should be yielded by an examined
Iterable
default <K,V> Matcher<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"))
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> Matcher<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")))
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> Matcher<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")))
K
- the key typekeyMatcher
- the matcher that must be satisfied by at least one keydefault <K> Matcher<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"))
K
- the key typekey
- the key that satisfying maps must containdefault <V> Matcher<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"))
V
- the value typevalue
- the value that satisfying maps must containdefault <V> Matcher<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")))
V
- the value typevalueMatcher
- the matcher that must be satisfied by at least one valuedefault <T> 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> Matcher<T> isOneOf(T... elements)
For example:
assertThat("foo", isIn("bar", "foo"))
T
- the typeelements
- the elements amongst which matching items will be founddefault Matcher<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 alloweddefault Matcher<BigDecimal> closeTo(BigDecimal operand, 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 alloweddefault <T extends 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))
T
- the typevalue
- the value which, when passed to the compareTo method of the
examined object, should return zerodefault <T extends 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))
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>> 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>> 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>> 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 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 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 Matcher<String> isEmptyString()
String
that matches when the examined string
has zero length.
For example:
assertThat("", isEmptyString())
default Matcher<String> isEmptyOrNullString()
String
that matches when the examined string
is null
, or has zero length.
For example:
assertThat(((String) null), isEmptyString())
default 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> Matcher<T> hasToString(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> 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> 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 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 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> 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> Matcher<T> hasProperty(String propertyName, 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> Matcher<T> samePropertyValuesAs(T expectedBean)
For example:
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
T
- The TypeexpectedBean
- the bean against which examined beans are compareddefault Matcher<Node> hasXPath(String xPath, 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 nodesdefault Matcher<Node> hasXPath(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 xpathdefault Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<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 xpathdefault Matcher<Node> hasXPath(String xPath, Matcher<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 xpathdefault Matcher<File> fileCanExecute(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanExecute(is(true)));
matcher
- the matcher on the can execute flag.default Matcher<File> fileCanExecute(boolean canExecute)
For example :
assertThat(myFile).is(fileCanExecute(true);
canExecute
- the expected value for the can execute flag.default Matcher<File> fileCanRead(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanRead(is(true)));
matcher
- the matcher on the can read flag.default Matcher<File> fileCanRead(boolean canRead)
For example :
assertThat(myFile).is(fileCanRead(true);
canRead
- the expected value for the can read flag.default Matcher<File> fileCanWrite(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileCanWrite(is(true)));
matcher
- the matcher on the can write flag.default Matcher<File> fileCanWrite(boolean canWrite)
For example :
assertThat(myFile).is(fileCanWrite(true);
canWrite
- the expected value for the can write flag.default Matcher<File> fileIsDirectory(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileIsDirectory(is(true)));
matcher
- the matcher on the is directory flag.default Matcher<File> fileIsDirectory(boolean isDirectory)
For example :
assertThat(myFile).is(fileIsDirectory(true);
isDirectory
- the expected value for the is directory flag.default Matcher<File> fileExists(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileExists(is(true)));
matcher
- the matcher on the exists flag.default Matcher<File> fileExists(boolean exists)
For example :
assertThat(myFile).is(fileExists(true);
exists
- the expected value for the exists flag.default Matcher<File> fileIsAbsolute(Matcher<? super Boolean> matcher)
For example :
assertThat(myFile).is(fileIsAbsolute(is(true)));
matcher
- the matcher on the absolute flag.default Matcher<File> fileIsAbsolute(boolean absolute)
For example :
assertThat(myFile).is(fileIsAbsolute(true);
absolute
- the expected value for the absolute flag.default Matcher<File> fileContains(Matcher<String[]> matcher)
The returned String[] is the one produced by list().
matcher
- the matcher on the list() result.default Matcher<File> fileContains(String atLeastThisName)
atLeastThisName
- the file name.default Matcher<File> fileNamed(Matcher<? super String> matcher)
For example :
assertThat(myFile).is(fileNamed(is("x")));
matcher
- the matcher on the name.default Matcher<File> fileNamed(String name)
For example :
assertThat(myFile).is(fileNamed("x"));
name
- the expected value for the name.default Matcher<Path> pathMatchedAsFile(Matcher<? super File> matcher)
matcher
- the matcher on File.default Matcher<Calendar> calendarIsYear(int year)
year
- the yearCalendar
.default Matcher<Calendar> calendarIsDayOfMonth(int dayOfMonth)
Calendar
has a specify
day of month
.dayOfMonth
- the day of monthCalendar
.default Matcher<Calendar> calendarIsMonth(int month)
month
- the monthCalendar
.default Matcher<Calendar> calendarIsHourOfDay(int hourOfDay)
Calendar
has a specify hour of day
.hourOfDay
- the hour of dayCalendar
.default Matcher<Calendar> calendarIsMinute(int minute)
minute
- the minuteCalendar
.default Matcher<Calendar> calendarIsSecond(int second)
second
- the secondCalendar
.default Matcher<Calendar> calendarIsDayOfWeek(int dayOfWeek)
Calendar
has a specify day of week
.dayOfWeek
- the day of weekCalendar
.default Matcher<Calendar> calendarIsMillisecond(int millisecond)
Calendar
has a specify millisecond
.millisecond
- the millisecondCalendar
.default Matcher<Calendar> calendarIsMonday()
Calendar
calendarIs a monday.Calendar
.default Matcher<Calendar> calendarIsThurday()
Calendar
calendarIs a thurday.Calendar
.default Matcher<Calendar> calendarIsWednesday()
Calendar
calendarIs a wednesday.Calendar
.default Matcher<Calendar> calendarIsTuesday()
Calendar
calendarIs a tuesday.Calendar
.default Matcher<Calendar> calendarIsFriday()
Calendar
calendarIs a friday.Calendar
.default Matcher<Calendar> calendarIsSaturday()
Calendar
calendarIs a saturday.Calendar
.default Matcher<Calendar> calendarIsSunday()
Calendar
calendarIs a sunday.Calendar
.default Matcher<Calendar> calendarIsJanuary()
Calendar
calendarIs in january.Calendar
.default Matcher<Calendar> calendarIsFebruary()
Calendar
calendarIs in february.Calendar
.default Matcher<Calendar> calendarIsMarch()
Calendar
calendarIs in march.Calendar
.default Matcher<Calendar> calendarIsApril()
Calendar
calendarIs in april.Calendar
.default Matcher<Calendar> calendarIsMay()
Calendar
calendarIs in may.Calendar
.default Matcher<Calendar> calendarIsJune()
Calendar
calendarIs in june.Calendar
.default Matcher<Calendar> calendarIsJuly()
Calendar
calendarIs in july.Calendar
.default Matcher<Calendar> calendarIsAugust()
Calendar
calendarIs in august.Calendar
.default Matcher<Calendar> calendarIsSeptember()
Calendar
calendarIs in september.Calendar
.default Matcher<Calendar> calendarIsOctober()
Calendar
calendarIs in october.Calendar
.static Matcher<Calendar> calendarIsNovember()
Calendar
calendarIs in november.Calendar
.default Matcher<Calendar> calendarIsDecember()
Calendar
calendarIs in december.Calendar
.default Matcher<Calendar> sameDate(Calendar other)
Calendar
calendarIs on same day (year, month, day
of month) that another one.default Matcher<Calendar> calendarIsBefore(Calendar other)
Calendar
calendarIs before another one.default Matcher<Calendar> calendarIsAfter(Calendar other)
Calendar
calendarIs after another one.default Matcher<LocalTime> localTimeIsHour(int hour)
LocalTime
.hour
- the hour.LocalTime
.default Matcher<LocalTime> localTimeIsMinute(int minute)
LocalTime
.minute
- the minute.LocalTime
.default Matcher<LocalTime> localTimeIsSecond(int second)
LocalTime
.second
- the second.LocalTime
.default Matcher<LocalTime> localTimeIsNano(int nano)
LocalTime
.nano
- the nano.LocalTime
.default Matcher<LocalDate> localDateIsYear(int year)
LocalDate
.year
- the yearLocalDate
.default Matcher<LocalDate> localDateIsMonth(Month month)
LocalDate
.month
- the monthLocalDate
.default Matcher<LocalDate> localDateIsDayOfMonth(int day)
LocalDate
.day
- the day of the monthLocalDate
.default <T> Matcher<Future<T>> futureIsCancelled(boolean expected)
Future
is cancelled.default <T> Matcher<Future<T>> futureIsDone(boolean expected)
Future
is done.default <T> Matcher<Future<T>> futureIsBeforeTimeout(Matcher<? super T> matching, long timeout, TimeUnit unit)
Future
, with timeout support and validate
the value.
For instance :
assertThat(Executors.newSingleThreadExecutor().submit(DemoFutureTest::run1)) .is(futureIsBeforeTimeout(notNullValue(), 10, TimeUnit.SECONDS));
default <T extends Matcher<?>> ch.powerunit.matchers.lang.MatcherTesterDSL1<T> testerOfMatcher(Class<T> matcherClass)
Please refer to
the complete documentation
T
- The matcher classmatcherClass
- the class of the Matcher.The DSL
MatcherTester.of(Class)
,
TestDelegate
default <O,C extends Comparator<O>> ComparatorTesterDSLStart<O,C> testerOfComparator(Class<C> comparatorClass)
Please refer
to the complete documentation
For example :
@TestDelegate public final ComparatorTester<Integer, MyComparator> direct = testerOfComparator( MyComparator.class).withLessSamples(-6).withEqualSamples(12) .withGreaterSamples(16).build();
O
- The object of the comparatorC
- The comparator undertestcomparatorClass
- the class of the Comparatorthe
DSL
ComparatorTester.of(Class)
,
TestDelegate
default <T,R> FunctionTesterStartDSL<T,R> testerOfFunction(Function<T,R> functionUnderTest)
T
- The input argument typeR
- The result typefunctionUnderTest
- the function to be testedthe DSL
FunctionTester.of(Function)
,
TestDelegate
default <T,U,R> BiFunctionTesterStartDSL<T,U,R> testerOfBiFunction(BiFunction<T,U,R> bifunctionUnderTest)
Please
refer to the complete documentation
For example :
@TestDelegate public final BiFunctionTester<Short, Integer, Long> tester1 = testerOfBiFunction( this::bifunctionToBeTested).passingAsParameter((short) 1, 2) .thenExpectingResult(3l).testNamed("tested") .passingAsParameter((short) 2, 4).thenExpectingResult(6l).build();
T
- The first input argument typeU
- the second input argument typeR
- The result typebifunctionUnderTest
- the bifunction to be testedthe
DSL
BiFunctionTester.of(BiFunction)
,
TestDelegate
default PatternTester0 testerOfPattern(String pattern)
The passed String will be compiled as a Pattern.
For instance :
@TestDelegate public final PatternTester sample1 = testerOfPattern("a+").receiving("b") .thenNoMatching().receiving("aa").thenMatching().build();
pattern
- the pattern, as a StringThe next step of the
DSL.
testerOfPattern(Pattern)
,
PatternTester
default PatternTester0 testerOfPattern(Pattern pattern)
For instance :
@TestDelegate public final PatternTester sample1 = testerOfPattern(Pattern.compile("a+")) .receiving("b").thenNoMatching().receiving("aa").thenMatching().build();
pattern
- the pattern.The next step of the
DSL.
PatternTester
default <T,R> CollectorTesterDSL0<T,?,R> testerOfCollector(Collector<T,?,R> collectorToTest)
Collector
.
The documentation of the
tester for the exact that are applied.
T
- the input type of the Collector
.R
- the return type of the Collector
.collectorToTest
- the Collector
to be tested.the DSL to build the tester
testerOfCollector(Class, Class, Collector)
default <T,R> CollectorTesterDSL0<T,?,R> testerOfCollector(Class<T> inputClass, Class<T> outputClass, Collector<T,?,R> collectorToTest)
Collector
.
The documentation of the
tester for the exact that are applied.
T
- the input type of the Collector
.R
- the return type of the Collector
.inputClass
- the class of the input of the
Collector
.outputClass
- the class of the output of the
Collector
.collectorToTest
- the Collector
to be tested.the DSL to build the tester
testerOfCollector(Collector)
default <T,R> Function<T,R> nullToNullConverter(Function<T,R> converter)
T
- input type of the converter.R
- output type of the converter.converter
- the converter to be used if the received is not null.default Function<Date,Calendar> dateToCalendar()
default Function<Calendar,Date> calendarToDate()
default <K,V> Function<Map<K,V>,V> mapToValue(K key)
Map
, as converter.default Statement<?,Throwable> asStatement(ConverterMethod.NoArgumentWithThrowableMethod method)
method
- the no arg no return piece of code to be tested.Copyright © 2015 Powerunit. All rights reserved.