Skip to content

Commit f6f142a

Browse files
committed
add spy stubbing tests
1 parent 334d471 commit f6f142a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

mockito-kotlin/src/test/kotlin/SpyTest.kt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
*/
2525

2626
import com.nhaarman.expect.expect
27-
import com.nhaarman.mockito_kotlin.spy
27+
import com.nhaarman.mockito_kotlin.*
2828
import org.junit.After
2929
import org.junit.Test
3030
import org.mockito.Mockito
3131
import org.mockito.exceptions.base.MockitoException
32+
import java.util.*
3233

3334
class SpyTest {
3435

@@ -66,6 +67,36 @@ class SpyTest {
6667
spy(closedClassInstance)
6768
}
6869

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+
69100
private interface MyInterface
70101
private open class MyClass : MyInterface
71102
private class ClosedClass

0 commit comments

Comments
 (0)