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
+ /*
2
4
* The MIT License
3
5
*
4
6
* Copyright (c) 2016 Niek Haarman
@@ -93,7 +95,7 @@ class SpyTest : TestBase() {
93
95
@Test
94
96
fun doReturnWithDefaultInstanceSpyStubbing () {
95
97
val timeVal = 12L
96
-
98
+
97
99
val dateSpy = spy<Date > {
98
100
on { time } doReturn timeVal
99
101
}
@@ -104,16 +106,36 @@ class SpyTest : TestBase() {
104
106
@Test
105
107
fun doReturnWithSpyStubbing () {
106
108
val timeVal = 15L
107
-
109
+
108
110
val dateSpy = spy(Date (0 )) {
109
111
on { time } doReturn timeVal
110
112
}
111
113
112
114
expect(dateSpy.time).toBe(timeVal)
113
115
}
114
116
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
+
117
139
private class ClosedClass
118
140
}
119
141
You can’t perform that action at this time.
0 commit comments