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)
}
}Content copied to clipboard
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)))
}Content copied to clipboard
Existing implementations:
Inheritors
Functions
Link copied to clipboard
Helper function to propagate capture for dev.mokkery.matcher.ArgMatcher.Composite.