mockito-kotlin / com.nhaarman.mockitokotlin2

Package com.nhaarman.mockitokotlin2

Types

KArgumentCaptor

class KArgumentCaptor<out T>

KStubbing

class KStubbing<out T>

VerifyScope

class VerifyScope<T>

Exceptions

MockitoKotlinException

class MockitoKotlinException : RuntimeException

Extensions for External Classes

org.mockito.ArgumentCaptor

org.mockito.BDDMockito.BDDMyOngoingStubbing

org.mockito.stubbing.OngoingStubbing

org.mockito.stubbing.Stubber

Functions

after

fun after(millis: Long): VerificationAfterDelay

any

fun <T : Any> any(): T

Matches any object, excluding nulls.

anyArray

fun <T> anyArray(): Array<T>

Matches any array of type T.

anyOrNull

fun <T : Any> anyOrNull(): T

Matches anything, including nulls.

anyVararg

fun <T : Any> anyVararg(): T

Matches any vararg object, including nulls.

argForWhich

fun <T : Any> argForWhich(predicate: T.() -> Boolean): T

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

argThat

fun <T : Any> argThat(predicate: T.() -> Boolean): T

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

argWhere

fun <T : Any> argWhere(predicate: (T) -> Boolean): T

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

argumentCaptor

fun <T : Any> argumentCaptor(): KArgumentCaptor<T>

atLeast

fun atLeast(numInvocations: Int): VerificationMode

atLeastOnce

fun atLeastOnce(): VerificationMode

atMost

fun atMost(maxNumberOfInvocations: Int): VerificationMode

calls

fun calls(wantedNumberOfInvocations: Int): VerificationMode

capture

fun <T : Any> capture(captor: ArgumentCaptor<T>): T

check

fun <T : Any> check(predicate: (T) -> Unit): T

For usage with verification only.

clearInvocations

fun <T> clearInvocations(vararg mocks: T): Unit

createInstance

fun <T : Any> createInstance(): T
fun <T : Any> createInstance(kClass: KClass<T>): T

description

fun description(description: String): VerificationMode

doAnswer

fun <T> doAnswer(answer: (InvocationOnMock) -> T?): Stubber

doCallRealMethod

fun doCallRealMethod(): Stubber

doNothing

fun doNothing(): Stubber

doReturn

fun doReturn(value: Any?): Stubber
fun doReturn(toBeReturned: Any?, vararg toBeReturnedNext: Any?): Stubber

doThrow

fun doThrow(toBeThrown: KClass<out Throwable>): Stubber
fun doThrow(vararg toBeThrown: Throwable): Stubber

eq

fun <T> eq(value: T): T

given

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

ignoreStubs

fun ignoreStubs(vararg mocks: Any): Array<out Any>

inOrder

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

isA

fun <T : Any> isA(): T

isNotNull

fun <T : Any> isNotNull(): T?

isNull

fun <T : Any> isNull(): T?

mock

fun <T : Any> mock(extraInterfaces: Array<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, useConstructor: Boolean = false, outerInstance: Any? = null): T
fun <T : Any> mock(extraInterfaces: Array<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, useConstructor: Boolean = false, outerInstance: Any? = null, stubbing: KStubbing<T>.(T) -> Unit): T
fun <T : Any> mock(a: Answer<Any>): T
fun <T : Any> mock(s: String): T
fun <T : Any> mock(s: MockSettings): T

mockingDetails

fun mockingDetails(toInspect: Any): MockingDetails

never

fun never(): VerificationMode

notNull

fun <T : Any> notNull(): T?

nullableArgumentCaptor

fun <T : Any> nullableArgumentCaptor(): KArgumentCaptor<T?>

only

fun only(): VerificationMode

refEq

fun <T> refEq(value: T, vararg excludeFields: String): T?

reset

fun <T> reset(vararg mocks: T): Unit

same

fun <T> same(value: T): T

spy

fun <T : Any> spy(): T
fun <T> spy(value: T): T

stub

fun <T : Any> T.stub(stubbing: KStubbing<T>.(T) -> Unit): T

then

fun <T> then(mock: T): Then<T>

timeout

fun timeout(millis: Long): VerificationWithTimeout

times

fun times(numInvocations: Int): VerificationMode

validateMockitoUsage

fun validateMockitoUsage(): Unit

verify

fun <T> verify(mock: T): T
fun <T> verify(mock: T, mode: VerificationMode): Tfun <T> verify(mock: T, block: VerifyScope<T>.() -> Unit): Unit

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

verifyNoMoreInteractions

fun <T> verifyNoMoreInteractions(vararg mocks: T): Unit

verifyZeroInteractions

fun verifyZeroInteractions(vararg mocks: Any): Unit

whenever

fun <T> whenever(methodCall: T): OngoingStubbing<T>

withSettings

fun withSettings(extraInterfaces: Array<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, useConstructor: Boolean = false, outerInstance: Any? = null): MockSettings