File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/kotlin/com/nhaarman/mockitokotlin2 Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,11 @@ fun <T> reset(vararg mocks: T) = Mockito.reset(*mocks)
243243fun <T > same (value : T ): T = Mockito .same(value) ? : value
244244
245245inline fun <reified T : Any > spy (): T = Mockito .spy(T ::class .java)!!
246+ inline fun <reified T : Any > spy (stubbing : KStubbing <T >.(T ) -> Unit ): T = Mockito .spy(T ::class .java)
247+ .apply { KStubbing (this ).stubbing(this ) }!!
246248fun <T > spy (value : T ): T = Mockito .spy(value)!!
249+ inline fun <reified T > spy (value : T , stubbing : KStubbing <T >.(T ) -> Unit ): T = spy(value)
250+ .apply { KStubbing (this ).stubbing(this ) }!!
247251
248252fun timeout (millis : Long ): VerificationWithTimeout = Mockito .timeout(millis)!!
249253fun times (numInvocations : Int ): VerificationMode = Mockito .times(numInvocations)!!
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class SpyTest : TestBase() {
7171 fun doNothingWithSpy () {
7272 val date = spy(Date (0 ))
7373 doNothing().whenever(date).time = 5L
74- date.time = 5L ;
74+ date.time = 5L
7575 expect(date.time).toBe(0L )
7676 }
7777
@@ -90,6 +90,28 @@ class SpyTest : TestBase() {
9090 expect(date.time).toBe(0L )
9191 }
9292
93+ @Test
94+ fun doReturnWithDefaultInstanceSpyStubbing () {
95+ val timeVal = 12L
96+
97+ val dateSpy = spy<Date > {
98+ on { time } doReturn timeVal
99+ }
100+
101+ expect(dateSpy.time).toBe(timeVal)
102+ }
103+
104+ @Test
105+ fun doReturnWithSpyStubbing () {
106+ val timeVal = 15L
107+
108+ val dateSpy = spy(Date (0 )) {
109+ on { time } doReturn timeVal
110+ }
111+
112+ expect(dateSpy.time).toBe(timeVal)
113+ }
114+
93115 private interface MyInterface
94116 private open class MyClass : MyInterface
95117 private class ClosedClass
You can’t perform that action at this time.
0 commit comments