Skip to content

Commit

Permalink
Added stub extension function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pawel bochenski committed Mar 30, 2017
1 parent 4c7c942 commit 5a5fa35
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ inline fun <reified T : Any> mock(
KStubbing(this).stubbing(this)
}!!

inline fun <T : Any> T.stub(stubbing: KStubbing<T>.(T) -> Unit) = this.apply { KStubbing(this).stubbing(this) }

@Deprecated("Use mock() with optional arguments instead.", ReplaceWith("mock<T>(defaultAnswer = a)"), level = WARNING)
inline fun <reified T : Any> mock(a: Answer<Any>): T = mock(defaultAnswer = a)

Expand Down

0 comments on commit 5a5fa35

Please sign in to comment.