File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed
tests/src/test/kotlin/test Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change 1- package test/*
1+ package test
2+
3+ /*
24 * The MIT License
35 *
46 * Copyright (c) 2016 Niek Haarman
@@ -93,7 +95,7 @@ class SpyTest : TestBase() {
9395 @Test
9496 fun doReturnWithDefaultInstanceSpyStubbing () {
9597 val timeVal = 12L
96-
98+
9799 val dateSpy = spy<Date > {
98100 on { time } doReturn timeVal
99101 }
@@ -104,16 +106,36 @@ class SpyTest : TestBase() {
104106 @Test
105107 fun doReturnWithSpyStubbing () {
106108 val timeVal = 15L
107-
109+
108110 val dateSpy = spy(Date (0 )) {
109111 on { time } doReturn timeVal
110112 }
111113
112114 expect(dateSpy.time).toBe(timeVal)
113115 }
114116
115- private interface MyInterface
116- private open class MyClass : MyInterface
117+ @Test
118+ fun passAnyStringToSpy () {
119+ /* Given */
120+ val my = spy(MyClass ())
121+
122+ /* When */
123+ doReturn(" mocked" ).whenever(my).foo(any())
124+
125+ /* Then */
126+ expect(my.foo(" hello" )).toBe(" mocked" )
127+ }
128+
129+ private interface MyInterface {
130+
131+ fun foo (value : String ): String
132+ }
133+
134+ private open class MyClass : MyInterface {
135+
136+ override fun foo (value : String ): String = value
137+ }
138+
117139 private class ClosedClass
118140}
119141
You can’t perform that action at this time.
0 commit comments