Matchers are intended to organize complex test conditions into a one flexible expression.

Each matcher is requirements specification and verification method which identifies if submitted test value satisfies matcher specification or not.

Matcher interface is base entry for each matcher.
Verification is performed using Matcher.match() method. Result of verification is MatchResult which is simply satisfied / unsatisfied Boolean and String message describing matching operation.

Matchers may be combined with each other using logical operators: and or or which are methods of Matcher interface. Also a matcher can be reverted from satisfied to unsatisfied state and visa versa using Matcher.not() method.

Example:

asyncTestContext.assertThat(joda, IsType<Jedi>().and(Mapping((Master master)=>master.padawans, Contains(luke)));

Matchers are aimed to be used in conjunction with AsyncTestContext.assertThat() method.

Custom matchers: just implement Matcher interface.


By: Lis
Since 0.4.0
Interfaces
Matchershared Matcher<in Value>

Matcher is a rule and verification method which identifies if submitted test value satisfies this rule or not.

Verification is performed using Matcher.match() method. Result of verification is represented using MatchResult.

Matchers may be combined with each other using and or or methods of Matcher interface.


Classes
AllOfshared AllOf<Value>

Accepted if all matchers from the given list are accepted otherwise rejected.

Anyshared Any<Value>

Verifies if matching stream of Iterable has at least a one element that satisfies the given predicate function.

AnyOfshared AnyOf<Value>

Verifies if matching stream of Iterable has at least a one element that satisfies the given matcher.

Beginningshared Beginning<Value>

Verifies if matching List value is beginning point of the given list.

CloseToshared CloseTo<Value>
given Value satisfies Number<Value>

Verifies if matching value is close to merit with the given tolerance.

Containedshared Contained<Value>

Verifies if matching value is contained in the given stream of Sequence.

Note: Iterable is lazy and there is no quarantee to get the same stream when it is iterating second time. While Sequence is eager and repeatably iterated.

Containsshared Contains<Value>

Verifies if matching stream of Iterable contains the given item.

ContainsAnyshared ContainsAny<Value>

Verifies if matching stream of Iterable contains at least one item from the given elements stream.

ContainsEveryshared ContainsEvery<Value>

Verifies if matching stream of Iterable contains every item from the given elements stream.

ContainsItemshared ContainsItem<Value>
given Value satisfies Object

Verifies if matching map contains the given item item.

ContainsNoDuplicatesshared ContainsNoDuplicates<Value>

Verifies if matching stream of Sequence does not contain duplicate elements.

DefinesKeyshared DefinesKey<Value>
given Value satisfies Object

Verifies if matching map defines the given key key, see Map.defines.

DoesNotContainshared DoesNotContain<Value>

Verifies if matching stream of Iterable does not contain the given item.

DoesNotContainItemshared DoesNotContainItem<Value>
given Value satisfies Object

Verifies if matching map doesn't contain the given item item.

DoesNotDefineKeyshared DoesNotDefineKey<Value>
given Value satisfies Object

Verifies if matching map doesn't define the given key key, see Map.defines.

Emptyshared Empty

Verifies if matching stream of Iterable is empty.

EndsWithshared EndsWith<Value>

Verifies if matching List value ends with the given subList.

EqualContentshared EqualContent<Value>

Verifies if matching stream contains the same elements as the given one.
The matcher doesn't rely on exact stream type - just content is compared.

EqualToshared EqualTo<Value>
given Value satisfies Object

Verifies if matching value equals to merit using operator ==.

EqualWithshared EqualWith<Value>

Verifies if matching value is equal to merit using given comparator.

Everyshared Every<Value>

Verifies if matching stream of Iterable has all elements satisfy the given predicate function.

EveryOfshared EveryOf<Value>

Verifies if matching stream of Iterable has all elements that satisfies the given matcher.

ExceptionHasCauseshared ExceptionHasCause

Verifies if matching exception has any cause.

ExceptionHasMessageshared ExceptionHasMessage

Verifies if matching exception has message equaled to messageCondition.

ExceptionHasNoCauseshared ExceptionHasNoCause

Verifies if matching exception doesn't have any cause.

ExceptionHasTypeshared ExceptionHasType<ExceptionType>
given ExceptionType satisfies Throwable

Verifies if matching exception has type of ExceptionType.

Finishingshared Finishing<Value>

Verifies if matching List value is finishing point of the given list.

Firstshared First<Value>

Verifies if matching value is the first in the given stream of Sequence.

Note: Iterable is lazy and there is no quarantee to get the same stream when it is iterating second time. While Sequence is eager and repeatably iterated.

Greatershared Greater<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is greater than given merit.

GreaterOrEqualshared GreaterOrEqual<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is greater or equal to given merit.

HasKeyshared HasKey<Value>
given Value satisfies Object

Verifies if matching value is a key in the given map, see Map.defines.

Identicalshared Identical<Value>
given Value satisfies Identifiable

Verifies if matching value is identical to merit using operator ===.

InRangeshared InRange<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is within given range of lower to upper including bounds. This is equal to greaterOrEqual(lower).and(lessOrEqual(upper)).

Includedshared Included<Value>

Verifies if matching List value is included in the given list.
SearchableList.includes is used in order to perform the verification.

IncludedAtshared IncludedAt<Value>

Verifies if matching List value is included in the given list at the given index of the list.
SearchableList.includesAt is used in order to perform the verification.

Includesshared Includes<Value>

Verifies if matching SearchableList value includes the given list.
SearchableList.includes is used in order to perform the verification.

IncludesAtshared IncludesAt<Value>

Verifies if matching SearchableList value includes the given list at the given index.
SearchableList.includesAt is used in order to perform the verification.

IsControlshared IsControl

Verifies if matching character is an ISO control character.

IsDefinedshared IsDefined

Verifies if matching value is defined i.e. is not NaN.

IsDigitshared IsDigit

Verifies if matching character is a numeric digit.

IsEvenshared IsEven

Verifies if matching integer is even, i.e. if exists number that i=2*k.

IsFalseshared IsFalse

Verifies if matching value is false.

IsFiniteshared IsFinite

Verifies if matching value is finite.

IsInfiniteshared IsInfinite

Verifies if matching value is infinite.

IsLettershared IsLetter

Verifies if matching character is a letter.

IsLowercaseshared IsLowercase

Verifies if matching character is a lowercase representation of the character.

IsNegativeshared IsNegative<Value>
given Value satisfies Number<Value>

Verifies if matching value is negative, i.e. is < 0.

IsNotNegativeshared IsNotNegative<Value>
given Value satisfies Number<Value>

Verifies if matching value is not negative, i.e. is >= 0.

IsNotNullshared IsNotNull

Verifies if matching value is not null.

IsNotPositiveshared IsNotPositive<Value>
given Value satisfies Number<Value>

Verifies if matching value is not positive, i.e. is <= 0.

IsNotTypeshared IsNotType<Check>

Verifies if matching value is not of Check type.

IsNotZeroshared IsNotZero<Value>
given Value satisfies Number<Value>

Verifies if matching value is not zero.

IsNullshared IsNull

Verifies if matching value is null.

IsOddshared IsOdd

Verifies if matching integer is odd, i.e. if exists number that i=2*k+1.

IsPositiveshared IsPositive<Value>
given Value satisfies Number<Value>

Verifies if matching value is positive, i.e. is > 0.

IsSortedshared IsSorted<Value>

Verifies if matching stream is sorted.

IsTitlecaseshared IsTitlecase

Verifies if matching character is a titlecase representation of the character.

IsTrueshared IsTrue

Verifies if matching value is true.

IsTypeshared IsType<Check>

Verifies if matching value is of Check type.

IsUndefinedshared IsUndefined

Verifies if matching value is undefined i.e. is not a number or NaN.

IsUppercaseshared IsUppercase

Verifies if matching character is a uppercase representation of the character.

IsWhitespaceshared IsWhitespace

Verifies if matching character is whitespace character.

IsZeroshared IsZero<Value>
given Value satisfies Number<Value>

Verifies if matching value is zero.

ItemAtKeyshared ItemAtKey<Value>
given Value satisfies Object

Verifies if the given map contains the given item item at the matching value as key. Items are compared using operator ==.

ItemByKeyshared ItemByKey<Value>
given Value satisfies Object

Verifies if matching map contains the given item item with the given key key. Items are compared using operator ==.

Lastshared Last<Value>

Verifies if matching value is the last in the given stream of Sequence.

Note: Iterable is lazy and there is no quarantee to get the same stream when it is iterating second time. While Sequence is eager and repeatably iterated.

Lessshared Less<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is less than given merit.

LessOrEqualshared LessOrEqual<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is less or equal to given merit.

LongerThanshared LongerThan

Verifies if matching stream of Iterable is longer than the given size.

MapExistedshared MapExisted<From,To>

Maps matching value if it is not null to another type To using convert and passes converted to the given matcher.
Rejects matching if value is null.

Mappingshared Mapping<From,To>

Maps matching value to another one using convert and passes converted value to the given matcher.

MatchResultshared final MatchResult

Represents a result of matching operation:

  • state - accepted or rejected
  • String message with operation details
NoneOfshared NoneOf<Value>

Accepted if no one matcher from the given list is accepted and rejected if all matchers from the given list are rejected.

NotContainedshared NotContained<Value>

Verifies if matching value is not contained in the given stream of Sequence.

Note: Iterable is lazy and there is no quarantee to get the same stream when it is iterating second time. While Sequence is eager and repeatably iterated.

NotEmptyshared NotEmpty

Verifies if matching stream of Iterable is not empty.

NotEqualToshared NotEqualTo<Value>
given Value satisfies Object

Verifies if matching value is not equal to merit using operator !=.

NotEqualWithshared NotEqualWith<Value>
given Value satisfies Identifiable

Verifies if matching value is not equal to merit using given comparator.

NotIdenticalshared NotIdentical<Value>
given Value satisfies Identifiable

Verifies if matching value is not identical to merit using operator ===.

NotInRangeshared NotInRange<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is not within given range of lower to upper including bounds. This is equal to less(lower).or(greater(upper)).

NotWithinshared NotWithin<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is not within given range of lower to upper excluding bounds. This is equal to lessOrEqual(lower).or(greaterOrEqual(upper)).

Occuredshared Occured<Value>

Verifies if matching value occurs in the given list at any index within from:length segment.
SearchableList.occurs is used in order to perform the verification.

OccuredAtshared OccuredAt<Value>

Verifies if matching value occurs in the given list at the given index.
SearchableList.occursAt is used in order to perform the verification.

Occursshared Occurs<Value>

Verifies if the given element occurs in matching SearchableList value within from:length segment.
SearchableList.occurs is used in order to perform the verification.

OccursAtshared OccursAt<Value>

Verifies if the given element occurs in matching SearchableList value at the given index.
SearchableList.occursAt is used in order to perform the verification.

OneOfshared OneOf<Value>

Accepted if one and only one from the given matchers is accepted otherwise rejected.

PassExistedshared PassExisted<Value>
given Value satisfies Object

Pass matching value to the given matcher if the value is not null.
Rejects matching if the value is null.

PassTypeshared PassType<Value>

Pass matching value if it satisfies given type Value to another matcher.
Rejects matching if value is is not Value.

Predicateshared Predicate<Value>

Redirects matching to a predicate function.
If predicate returns true matching is accepted otherwise it is rejected

ShorterThanshared ShorterThan

Verifies if matching stream of Iterable is shorter than the given size.

SizeOfshared SizeOf

Verifies if matching stream of Iterable has the given size.

SomeOfshared SomeOf<Value>

Accepted if some from the given matchers is accepted and rejected only if all matchers are rejected.

StartsWithshared StartsWith<Value>

Verifies if matching List value starts with the given subList.

Subsetshared Subset<Value>

Verifies if the given subset is subset of matching set.

SubsetOfshared SubsetOf<Value>

Verifies if matching set is subset of the given superset.

Supersetshared Superset<Value>

Verifies if the given superset is superset of matching set.

SupersetOfshared SupersetOf<Value>

Verifies if matching set is superset of the given subset.

ValueEqualityshared ValueEquality<Value>
given Value satisfies Object

The matcher is useful to test classes which implements equals method. It verifies value equality rules i.e.:

  • reflexivity, x==x
  • symmetry, if x==y then y==x
  • trasitivity, if x==y and y==z then x==z
  • 'hashivity', if x==y then x.hash==y.hash

In order to have value to compare to clone function is used. The function has to return new object which has to be equal to the passed to.

Withinshared Within<Value>
given Value satisfies Comparable<Value>

Verifies if matching value is within given range of lower to upper excluding bounds. This is equal to greater(lower).and(less(upper)).