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)
243
243
fun <T > same (value : T ): T = Mockito .same(value) ? : value
244
244
245
245
inline 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 ) }!!
246
248
fun <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 ) }!!
247
251
248
252
fun timeout (millis : Long ): VerificationWithTimeout = Mockito .timeout(millis)!!
249
253
fun times (numInvocations : Int ): VerificationMode = Mockito .times(numInvocations)!!
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class SpyTest : TestBase() {
71
71
fun doNothingWithSpy () {
72
72
val date = spy(Date (0 ))
73
73
doNothing().whenever(date).time = 5L
74
- date.time = 5L ;
74
+ date.time = 5L
75
75
expect(date.time).toBe(0L )
76
76
}
77
77
@@ -90,6 +90,28 @@ class SpyTest : TestBase() {
90
90
expect(date.time).toBe(0L )
91
91
}
92
92
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
+
93
115
private interface MyInterface
94
116
private open class MyClass : MyInterface
95
117
private class ClosedClass
You can’t perform that action at this time.
0 commit comments