doThrow

infix fun <T> OngoingStubbing<T>.doThrow(throwable: Throwable): OngoingStubbing<T>

Sets a throwable to be thrown when the stubbed method/function is being called. E.g:

    whenever { mock.someFunction() } doThrow RuntimeException()

This function is an alias for Mockito's OngoingStubbing.thenThrow.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

throwable

to be thrown on method/function invocations.


fun <T> OngoingStubbing<T>.doThrow(throwable: Throwable, vararg throwables: Throwable): OngoingStubbing<T>

Sets throwables to be thrown when the stubbed method/function is being called consecutively. E.g:

    whenever { mock.someFunction() }.doThrow(RuntimeException(), IOException())

You can specify throwables to be thrown for consecutive invocations. In that case the last throwable determines the behavior of further consecutive invocations.

This function is an alias for Mockito's OngoingStubbing.thenThrow.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

throwable

to be thrown on the first method/function invocation.

throwables

to be thrown on the next method/function invocations.


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

Sets a throwable type to be thrown when the stubbed method/function is being called. E.g:

    whenever { mock.someFunction() } doThrow IllegalArgumentException::class

This function is an alias for Mockito's OngoingStubbing.thenThrow.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

throwableType

to be thrown on the method/function invocation.


fun <T> OngoingStubbing<T>.doThrow(throwableType: KClass<out Throwable>, vararg throwableTypes: KClass<out Throwable>): OngoingStubbing<T>

Sets throwable types to be thrown when the stubbed method is called consecutively. E.g:

    whenever { mock.someFunction() }.doThrow(IllegalArgumentException::class, NullPointerException::class)

You can specify throwableTypes to be thrown for consecutive invocations. In that case the last throwable type determines the behavior of further consecutive invocations.

This function is an alias for Mockito's OngoingStubbing.thenThrow.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

throwableType

to be thrown on the first method/function invocation.

throwableTypes

to be thrown on the next method/function invocations.


fun doThrow(throwable: Throwable): Stubber

Sets a throwable to be thrown, to be applied in reverse stubbing.

Example:

    doThrow(IllegalArgumentException()).whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doThrow.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

throwable

to be thrown on the method/function invocation.


fun doThrow(throwable: Throwable, vararg throwables: Throwable): Stubber

Sets throwables to be thrown on consecutive calls, to be applied in reverse stubbing.

Example:

    doThrow(RuntimeException(), IOException()).whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doThrow.

You can specify throwables to be thrown for consecutive invocations. In that case the last throwable determines the behavior of further consecutive invocations.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

throwable

to be thrown on the first method/function invocation.

throwables

to be thrown on the next method/function invocations.


fun doThrow(throwableType: KClass<out Throwable>): Stubber

Sets a throwable type to be thrown, to be applied in reverse stubbing.

Example:

    doThrow(IllegalArgumentException::class).whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doThrow.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

throwableType

to be thrown on the method/function invocation.


fun doThrow(throwableType: KClass<out Throwable>, vararg throwableTypes: KClass<out Throwable>): Stubber

Sets throwable types to be thrown on consecutive calls, to be applied in reverse stubbing.

Example:

    doThrow(IllegalArgumentException::class, NullPointerException::class)
.whenever(mock)
.someMethod()

This function is an alias for Mockito's Mockito.doThrow.

You can specify throwableTypes to be thrown for consecutive invocations. In that case the last throwable type determines the behavior of further consecutive invocations.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

throwableType

to be thrown on the first method/function invocation.

throwableTypes

to be thrown on the next method/function invocations.