File tree 2 files changed +16
-2
lines changed
mockito-kotlin/src/main/kotlin/org/mockito/kotlin
tests/src/test/kotlin/test
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -28,11 +28,11 @@ package org.mockito.kotlin
28
28
import org.mockito.stubbing.LenientStubber
29
29
import org.mockito.stubbing.OngoingStubbing
30
30
31
- inline fun <reified T : Any > LenientStubber.whenever (methodCall : T ): OngoingStubbing <T > {
31
+ inline fun <reified T > LenientStubber.whenever (methodCall : T ): OngoingStubbing <T > {
32
32
return `when `(methodCall)
33
33
}
34
34
35
- inline fun <reified T : Any > LenientStubber.whenever (methodCall : () -> T ): OngoingStubbing <T > {
35
+ inline fun <reified T > LenientStubber.whenever (methodCall : () -> T ): OngoingStubbing <T > {
36
36
return whenever(methodCall())
37
37
}
38
38
Original file line number Diff line number Diff line change @@ -34,4 +34,18 @@ open class LenientStubberTest {
34
34
35
35
Assert .assertEquals(" List should contain hello" , " hello" , mock[1 ])
36
36
}
37
+
38
+ @Test
39
+ fun unused_and_lenient_stubbings_with_nullable () {
40
+ val mock = mock<NullableToString >()
41
+ lenient().whenever(mock.returnsNullableString()).doReturn(null )
42
+ whenever(mock.returnsNonNullableString()).doReturn(" hello" )
43
+
44
+ Assert .assertEquals(" Should return hello" , " hello" , mock.returnsNonNullableString())
45
+ }
46
+
47
+ private class NullableToString {
48
+ fun returnsNullableString (): String? = " "
49
+ fun returnsNonNullableString (): String = " "
50
+ }
37
51
}
You can’t perform that action at this time.
0 commit comments