Composite

A matcher that combines other matchers (e.g. dev.mokkery.matcher.logical.LogicalMatchers.Or).

An implementation accepts its child matchers in any form it needs (e.g. List<ArgMatcher<T>>) and must propagate Capture.capture to its direct children:

public class Or<T>(
public val matchers: List<ArgMatcher<T>>
) : ArgMatcher.Composite<T> {
override fun matches(arg: T): Boolean = matchers.any { it.matches(arg) }

override fun capture(value: T) {
matchers.propagateCapture(value)
}
}

To use it, write a MokkeryMatcherScope extension like for a regular matcher, mark the parameters that accept matchers with dev.mokkery.annotations.Matcher and turn them into matcher objects with dev.mokkery.matcher.materialize:

fun <T> MokkeryMatcherScope.or(@Matcher first: T, @Matcher second: T, @Matcher vararg others: T): T {
return matches(Or(materialize(first, second, *others)))
}

Existing implementations:

Inheritors

Functions

Link copied to clipboard
abstract override fun capture(value: T)

Propagates value to children matchers.

Link copied to clipboard
abstract fun matches(arg: T): Boolean
Link copied to clipboard

Helper function to propagate capture for dev.mokkery.matcher.ArgMatcher.Composite.