Skip to content

Commit 5a5fa35

Browse files
author
pawel bochenski
committed
Added stub extension function
with this method one can define mock for class val someMock = mock<Object>() and then define stubs in test someMock.stub { on { something } doReturn somethingElse } It is useful when some tests reuse mock object but with different stubbing
1 parent 4c7c942 commit 5a5fa35

File tree

1 file changed

+2
-0
lines changed
  • mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin

1 file changed

+2
-0
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ inline fun <reified T : Any> mock(
175175
KStubbing(this).stubbing(this)
176176
}!!
177177

178+
inline fun <T : Any> T.stub(stubbing: KStubbing<T>.(T) -> Unit) = this.apply { KStubbing(this).stubbing(this) }
179+
178180
@Deprecated("Use mock() with optional arguments instead.", ReplaceWith("mock<T>(defaultAnswer = a)"), level = WARNING)
179181
inline fun <reified T : Any> mock(a: Answer<Any>): T = mock(defaultAnswer = a)
180182

0 commit comments

Comments
 (0)