File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
mockito-kotlin/src/test/kotlin Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change 24
24
*/
25
25
26
26
import com.nhaarman.expect.expect
27
- import com.nhaarman.mockito_kotlin.spy
27
+ import com.nhaarman.mockito_kotlin.*
28
28
import org.junit.After
29
29
import org.junit.Test
30
30
import org.mockito.Mockito
31
31
import org.mockito.exceptions.base.MockitoException
32
+ import java.util.*
32
33
33
34
class SpyTest {
34
35
@@ -66,6 +67,36 @@ class SpyTest {
66
67
spy(closedClassInstance)
67
68
}
68
69
70
+ @Test
71
+ fun doReturnWithSpy () {
72
+ val date = spy(Date ())
73
+ doReturn(123L ).whenever(date).time
74
+ expect(date.time).toBe(123L )
75
+ }
76
+
77
+ @Test
78
+ fun doNothingWithSpy () {
79
+ val date = spy(Date (0 ))
80
+ doNothing().whenever(date).time = 5L
81
+ date.time = 5L ;
82
+ expect(date.time).toBe(0L )
83
+ }
84
+
85
+ @Test(expected = IllegalArgumentException ::class )
86
+ fun doThrowWithSpy () {
87
+ val date = spy(Date (0 ))
88
+ doThrow(IllegalArgumentException ()).whenever(date).time
89
+ date.time
90
+ }
91
+
92
+ @Test
93
+ fun doCallRealMethodWithSpy () {
94
+ val date = spy(Date (0 ))
95
+ doReturn(123L ).whenever(date).time
96
+ doCallRealMethod().whenever(date).time
97
+ expect(date.time).toBe(0L )
98
+ }
99
+
69
100
private interface MyInterface
70
101
private open class MyClass : MyInterface
71
102
private class ClosedClass
You can’t perform that action at this time.
0 commit comments