VarArgMatcher

sealed interface VarArgMatcher : ArgMatcher<Any?> (source)

Deprecated

Obsolete varargs API. Read `VarArgMatcher` docs for more details.

Wildcard vararg matcher that checks a subset of varargs. It can occur only once. To provide your own implementation use Base.

Vararg matchers are DEPRECATED

Since Mokkery 3, it is possible to use any matcher that accepts an array with the spread operator (*), making vararg matchers obsolete. They have been replaced with matchers that are more versatile and can be used with arrays in any context.

Examples:

// Mokkery 2
every { mock.callWithVarargs(1, *anyIntVarargs(), 10) } returns 1
every { mock.callWithVarargs(1, *varargsIntAll { it % 2 == 0 }, 10) } returns 1

// Mokkery 3
every { mock.callWithVarargs(1, *any(), 10) } returns 1
every { mock.callWithVarargs(1, *containsAllInts { it % 2 == 0 }, 10) } returns 1

The new approach allows you to easily create custom matchers and use them with the spread operator:

every { mock.callWithVarargs(1, *matches { it.size > 2 }, 10) } returns 1
// Matches a call with varargs that starts with 1, ends with 10, and has at least two elements in between.

Inheritors

Types

Link copied to clipboard
class AllThat<T>(type: KClass<*>, predicate: (T) -> Boolean) : VarArgMatcher.Base<T>

Matches a sequence of varargs with all elements matching the predicate.

Link copied to clipboard

Matches any sequence of varargs.

Link copied to clipboard
class AnyThat<T>(type: KClass<*>, predicate: (T) -> Boolean) : VarArgMatcher.Base<T>

Matches a sequence of varargs with any element matching the predicate.

Link copied to clipboard
abstract class Base<in T> : VarArgMatcher

Base class for any VarArgMatcher. Returns false if arg is not an array or list.

Functions

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

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