File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
mockito-kotlin/src/main/kotlin/org/mockito/kotlin
tests/src/test/kotlin/test Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import kotlinx.coroutines.runBlocking
30
30
import org.mockito.Mockito
31
31
import org.mockito.exceptions.misusing.NotAMockException
32
32
import org.mockito.stubbing.OngoingStubbing
33
+ import org.mockito.stubbing.Stubber
33
34
import kotlin.reflect.KClass
34
35
35
36
@@ -85,4 +86,8 @@ class KStubbing<out T : Any>(val mock: T) {
85
86
): OngoingStubbing <R > {
86
87
return runBlocking { Mockito .`when `(mock.m()) }
87
88
}
89
+
90
+ fun Stubber.on (methodCall : T .() -> Unit ) {
91
+ this .`when `(mock).methodCall()
92
+ }
88
93
}
Original file line number Diff line number Diff line change @@ -100,4 +100,13 @@ class StubberTest : TestBase() {
100
100
mock.go()
101
101
}
102
102
}
103
+
104
+ @Test
105
+ fun testStubberOnBlockExtension () {
106
+ val mock = mock<Methods > {
107
+ doReturn(" Test" ).on { stringResult() }
108
+ }
109
+
110
+ expect(mock.stringResult()).toBe(" Test" )
111
+ }
103
112
}
You can’t perform that action at this time.
0 commit comments