Package-level declarations

Types

Link copied to clipboard
class ArgumentCaptorHolder4<out A, out B, out C, out D>(val first: A, val second: B, val third: C, val fourth: D)
Link copied to clipboard
class ArgumentCaptorHolder5<out A, out B, out C, out D, out E>(val first: A, val second: B, val third: C, val fourth: D, val fifth: E)
Link copied to clipboard
class InOrderOnType<T>(t: T) : KInOrder
Link copied to clipboard
class KArgumentCaptor<out T>(captor: ArgumentCaptor<T>, tClass: KClass<*>)
Link copied to clipboard
interface KInOrder : InOrder
Link copied to clipboard
class KStubbing<out T : Any>(val mock: T)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class VerifyScope<out T>(val mock: T)

Properties

Link copied to clipboard
val <T> ArgumentCaptor<T>.firstValue: T
Link copied to clipboard
val <T> ArgumentCaptor<T>.lastValue: T
Link copied to clipboard
val <T> ArgumentCaptor<T>.secondValue: T
Link copied to clipboard
val <T> ArgumentCaptor<T>.thirdValue: T

Functions

Link copied to clipboard
fun after(millis: Long): VerificationAfterDelay

Allows verifying over a given period. It causes a verify to wait for a specified period of time for a desired interaction rather than failing immediately if has not already happened. May be useful for testing in concurrent conditions.

Link copied to clipboard
inline fun <T : Any> any(): T

Matches any object, excluding nulls.

Link copied to clipboard
inline fun <T> anyArray(): Array<T>

Matches any array of type T.

Link copied to clipboard
inline fun <T : Any> anyOrNull(): T

Matches anything, including nulls.

Link copied to clipboard
inline fun <T : Any> anyVararg(): T

Matches any vararg object, including nulls.

fun <T : Any> anyVararg(clazz: KClass<T>): T
Link copied to clipboard
inline fun <T : Any> argForWhich(noinline predicate: T.() -> Boolean): T

Alias for argThat.

Link copied to clipboard
inline fun <T : Any> argThat(noinline predicate: T.() -> Boolean): T

Creates a custom argument matcher. null values will never evaluate to true.

inline fun <T : Any> argThat(matcher: ArgumentMatcher<T>): T

Registers a custom ArgumentMatcher. The original Mockito function registers the matcher and returns null, here the required type is returned.

Link copied to clipboard
inline fun <T : Any> argumentCaptor(): KArgumentCaptor<T>

Creates a KArgumentCaptor for given type.

Creates a KArgumentCaptor for given type, taking in a lambda to allow fast verification.

inline fun <A : Any, B : Any> argumentCaptor(a: KClass<A> = A::class, b: KClass<B> = B::class): Pair<KArgumentCaptor<A>, KArgumentCaptor<B>>

Creates 2 KArgumentCaptors for given types.

inline fun <A : Any, B : Any, C : Any> argumentCaptor(a: KClass<A> = A::class, b: KClass<B> = B::class, c: KClass<C> = C::class): Triple<KArgumentCaptor<A>, KArgumentCaptor<B>, KArgumentCaptor<C>>

Creates 3 KArgumentCaptors for given types.

inline fun <A : Any, B : Any, C : Any, D : Any> argumentCaptor(a: KClass<A> = A::class, b: KClass<B> = B::class, c: KClass<C> = C::class, d: KClass<D> = D::class): ArgumentCaptorHolder4<KArgumentCaptor<A>, KArgumentCaptor<B>, KArgumentCaptor<C>, KArgumentCaptor<D>>
inline fun <A : Any, B : Any, C : Any, D : Any, E : Any> argumentCaptor(a: KClass<A> = A::class, b: KClass<B> = B::class, c: KClass<C> = C::class, d: KClass<D> = D::class, e: KClass<E> = E::class): ArgumentCaptorHolder5<KArgumentCaptor<A>, KArgumentCaptor<B>, KArgumentCaptor<C>, KArgumentCaptor<D>, KArgumentCaptor<E>>

Creates 4 KArgumentCaptors for given types.

Link copied to clipboard
inline fun <T : Any> argWhere(noinline predicate: (T) -> Boolean): T

Creates a custom argument matcher. null values will never evaluate to true.

Link copied to clipboard
fun atLeast(numInvocations: Int): VerificationMode

Allows at-least-x verification.

Link copied to clipboard
fun atLeastOnce(): VerificationMode

Allows at-least-once verification.

Link copied to clipboard
fun atMost(maxNumberOfInvocations: Int): VerificationMode

Allows at-most-x verification.

Link copied to clipboard
fun calls(wantedNumberOfInvocations: Int): VerificationMode

Allows non-greedy verification in order.

Link copied to clipboard
inline fun <T : Any> capture(captor: ArgumentCaptor<T>): T

Alias for ArgumentCaptor.capture.

Link copied to clipboard
inline fun <T : Any> check(noinline predicate: (T) -> Unit): T

For usage with verification only.

Link copied to clipboard
fun <T> clearInvocations(vararg mocks: T)

Use this method in order to only clear invocations, when stubbing is non-trivial.

Link copied to clipboard
fun description(description: String): VerificationMode

Adds a description to be printed if verification fails.

Link copied to clipboard
fun <T> doAnswer(answer: (InvocationOnMock) -> T?): Stubber
Link copied to clipboard
infix fun <T> OngoingStubbing<T>.doAnswer(answer: (InvocationOnMock) -> T?): OngoingStubbing<T>

Sets a generic Answer for the method using a lambda.

infix fun <T> OngoingStubbing<T>.doAnswer(answer: Answer<*>): OngoingStubbing<T>

Sets a generic Answer for the method.

Link copied to clipboard
fun doCallRealMethod(): Stubber
Link copied to clipboard
fun doNothing(): Stubber
Link copied to clipboard
fun doReturn(value: Any?): Stubber
fun doReturn(toBeReturned: Any?, vararg toBeReturnedNext: Any?): Stubber
Link copied to clipboard
infix fun <T> OngoingStubbing<T>.doReturn(t: T): OngoingStubbing<T>

Sets a return value to be returned when the method is called.

fun <T> OngoingStubbing<T>.doReturn(t: T, vararg ts: T): OngoingStubbing<T>

Sets consecutive return values to be returned when the method is called.

Link copied to clipboard
infix inline fun <T> OngoingStubbing<T>.doReturnConsecutively(ts: List<T>): OngoingStubbing<T>

Sets consecutive return values to be returned when the method is called.

Link copied to clipboard
infix fun <T> OngoingStubbing<T>.doSuspendableAnswer(answer: suspend (InvocationOnMock) -> T?): OngoingStubbing<T>
Link copied to clipboard
fun doThrow(vararg toBeThrown: Throwable): Stubber
fun doThrow(toBeThrown: KClass<out Throwable>): Stubber
Link copied to clipboard
infix fun <T> OngoingStubbing<T>.doThrow(t: Throwable): OngoingStubbing<T>
fun <T> OngoingStubbing<T>.doThrow(t: Throwable, vararg ts: Throwable): OngoingStubbing<T>

Sets Throwable objects to be thrown when the method is called.

infix fun <T> OngoingStubbing<T>.doThrow(t: KClass<out Throwable>): OngoingStubbing<T>

Sets a Throwable type to be thrown when the method is called.

fun <T> OngoingStubbing<T>.doThrow(t: KClass<out Throwable>, vararg ts: KClass<out Throwable>): OngoingStubbing<T>

Sets Throwable classes to be thrown when the method is called.

Link copied to clipboard
fun <T> eq(value: T): T

Object argument that is equal to the given value.

Link copied to clipboard
fun <T> given(methodCall: T): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BDDMockito.given.

fun <T> given(methodCall: () -> T): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BDDMockito.given with a lambda.

Link copied to clipboard
fun <T> givenBlocking(methodCall: suspend CoroutineScope.() -> T): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BDDMockito.given with a suspending lambda

Link copied to clipboard
fun ignoreStubs(vararg mocks: Any): Array<out Any>

Ignores stubbed methods of given mocks for the sake of verification.

Link copied to clipboard
fun inOrder(vararg mocks: Any): KInOrder

Creates KInOrder object that allows verifying mocks in order.

inline fun inOrder(vararg mocks: Any, evaluation: KInOrder.() -> Unit)

Creates KInOrder object that allows verifying mocks in order. Accepts a lambda to allow easy evaluation.

Link copied to clipboard
inline fun <T> T.inOrder(block: InOrderOnType<T>.() -> Any)

Allows KInOrder verification for a single mocked instance:

Link copied to clipboard
inline fun <T : Any> isA(): T

Argument that implements the given class.

Link copied to clipboard
fun <T : Any> isNotNull(): T?

Not null argument.

Link copied to clipboard
fun <T : Any> isNull(): T?

null argument.

Link copied to clipboard
inline fun <T : Any> mock(s: String): T
inline fun <T : Any> mock(s: MockSettings): T
inline fun <T : Any> mock(a: Answer<Any>): T

inline fun <T : Any> mock(extraInterfaces: Array<out KClass<out Any>>? = null, name: String? = null, spiedInstance: Any? = null, defaultAnswer: Answer<Any>? = null, serializable: Boolean = false, serializableMode: SerializableMode? = null, verboseLogging: Boolean = false, invocationListeners: Array<InvocationListener>? = null, stubOnly: Boolean = false, @Incubating useConstructor: UseConstructor? = null, @Incubating outerInstance: Any? = null, @Incubating lenient: Boolean = false): T

Creates a mock for T.

inline fun <T : Any> mock(extraInterfaces: Array<out KClass<out Any>>? = null, name: String? = null, spiedInstance: Any? = null, defaultAnswer: Answer<Any>? = null, serializable: Boolean = false, serializableMode: SerializableMode? = null, verboseLogging: Boolean = false, invocationListeners: Array<InvocationListener>? = null, stubOnly: Boolean = false, @Incubating useConstructor: UseConstructor? = null, @Incubating outerInstance: Any? = null, @Incubating lenient: Boolean = false, stubbing: KStubbing<T>.(T) -> Unit): T

Creates a mock for T, allowing for immediate stubbing.

Link copied to clipboard
fun mockingDetails(toInspect: Any): MockingDetails
Link copied to clipboard
fun never(): VerificationMode

Alias for times with parameter 0.

Link copied to clipboard
fun <T : Any> notNull(): T?

Not null argument.

Link copied to clipboard

Creates a KArgumentCaptor for given nullable type.

Creates a KArgumentCaptor for given nullable type, taking in a lambda to allow fast verification.

Link copied to clipboard
fun only(): VerificationMode

Allows checking if given method was the only one invoked.

Link copied to clipboard
inline fun <T : Any> refEq(value: T, vararg excludeFields: String): T

Object argument that is reflection-equal to the given value with support for excluding selected fields from a class.

Link copied to clipboard
fun <T> reset(vararg mocks: T)
Link copied to clipboard
fun <T> same(value: T): T

Object argument that is the same as the given value.

Link copied to clipboard
fun <T, R> BDDMockito.Then<T>.shouldBlocking(f: suspend T.() -> R): R

Alias for Then.should, with suspending lambda.

Link copied to clipboard
inline fun <T : Any> spy(): T
fun <T> spy(value: T): T

Creates a spy of the real object. The spy calls real methods unless they are stubbed.

inline fun <T : Any> spy(stubbing: KStubbing<T>.(T) -> Unit): T
inline fun <T : Any> spy(value: T, stubbing: KStubbing<T>.(T) -> Unit): T

Creates a spy of the real object, allowing for immediate stubbing. The spy calls real methods unless they are stubbed.

Link copied to clipboard
inline fun <T : Any> T.stub(stubbing: KStubbing<T>.(T) -> Unit): T
Link copied to clipboard
inline fun <T : Any> stubbing(mock: T, stubbing: KStubbing<T>.(T) -> Unit)
Link copied to clipboard
fun <T> then(mock: T): BDDMockito.Then<T>

Alias for BDDMockito.then.

Link copied to clipboard
fun timeout(millis: Long): VerificationWithTimeout

Allows verifying with timeout. It causes a verify to wait for a specified period of time for a desired interaction rather than fails immediately if has not already happened. May be useful for testing in concurrent conditions.

Link copied to clipboard
fun times(numInvocations: Int): VerificationMode

Allows verifying exact number of invocations.

Link copied to clipboard
Link copied to clipboard
fun <T> verify(mock: T): T

Verifies certain behavior happened once.

inline fun <T> verify(mock: T, block: VerifyScope<T>.() -> Unit)

Verify multiple calls on mock Supports an easier to read style of

fun <T> verify(mock: T, mode: VerificationMode): T

Verifies certain behavior happened at least once / exact number of times / never.

Link copied to clipboard
fun <T> verifyBlocking(mock: T, f: suspend T.() -> Unit)

Verifies certain suspending behavior happened once.

fun <T> verifyBlocking(mock: T, mode: VerificationMode, f: suspend T.() -> Unit)

Verifies certain behavior happened at least once / exact number of times / never.

Link copied to clipboard
fun verifyNoInteractions(vararg mocks: Any)

Checks if any of given mocks has any unverified interaction.

Link copied to clipboard
fun <T> verifyNoMoreInteractions(vararg mocks: T)

Verifies that no interactions happened on given mocks beyond the previously verified interactions.

Link copied to clipboard
inline fun <T> whenever(methodCall: T): OngoingStubbing<T>

Enables stubbing methods. Use it when you want the mock to return particular value when particular method is called.

Link copied to clipboard
inline fun <T> LenientStubber.whenever(methodCall: T): OngoingStubbing<T>
inline fun <T> LenientStubber.whenever(methodCall: () -> T): OngoingStubbing<T>
fun <T> Stubber.whenever(mock: T): T
Link copied to clipboard
fun <T> wheneverBlocking(methodCall: suspend CoroutineScope.() -> T): OngoingStubbing<T>

Enables stubbing suspending methods. Use it when you want the mock to return particular value when particular suspending method is called.

Link copied to clipboard
fun <T> Stubber.wheneverBlocking(mock: T, f: suspend T.() -> Unit)

Alias for when with suspending function

Link copied to clipboard
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BDDMyOngoingStubbing.will

Link copied to clipboard
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willAnswer(value: (InvocationOnMock) -> T?): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BBDMyOngoingStubbing.willAnswer, accepting a lambda.

Link copied to clipboard
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willReturn(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BBDMyOngoingStubbing.willReturn.

Link copied to clipboard
infix inline fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willReturnConsecutively(ts: List<T>): BDDMockito.BDDMyOngoingStubbing<T>

Sets consecutive return values to be returned when the method is called. Same as BDDMyOngoingStubbing.willReturn, but accepts list instead of varargs.

Link copied to clipboard
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willSuspendableAnswer(value: suspend (InvocationOnMock) -> T?): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BBDMyOngoingStubbing.willAnswer, accepting a suspend lambda.

Link copied to clipboard
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(value: () -> Throwable): BDDMockito.BDDMyOngoingStubbing<T>

Alias for BBDMyOngoingStubbing.willThrow.

infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(t: KClass<out Throwable>): BDDMockito.BDDMyOngoingStubbing<T>

Sets a Throwable type to be thrown when the method is called.

fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(t: KClass<out Throwable>, vararg ts: KClass<out Throwable>): BDDMockito.BDDMyOngoingStubbing<T>

Sets Throwable classes to be thrown when the method is called.

Link copied to clipboard
fun withSettings(extraInterfaces: Array<out KClass<out Any>>? = null, name: String? = null, spiedInstance: Any? = null, defaultAnswer: Answer<Any>? = null, serializable: Boolean = false, serializableMode: SerializableMode? = null, verboseLogging: Boolean = false, invocationListeners: Array<InvocationListener>? = null, stubOnly: Boolean = false, @Incubating useConstructor: UseConstructor? = null, @Incubating outerInstance: Any? = null, @Incubating lenient: Boolean = false): MockSettings

Allows mock creation with additional mock settings. See MockSettings.