diff --git a/mockito-kotlin/src/main/kotlin/org/mockito/kotlin/LenientStubber.kt b/mockito-kotlin/src/main/kotlin/org/mockito/kotlin/LenientStubber.kt index 1a9236bd..a9d9a340 100644 --- a/mockito-kotlin/src/main/kotlin/org/mockito/kotlin/LenientStubber.kt +++ b/mockito-kotlin/src/main/kotlin/org/mockito/kotlin/LenientStubber.kt @@ -28,11 +28,11 @@ package org.mockito.kotlin import org.mockito.stubbing.LenientStubber import org.mockito.stubbing.OngoingStubbing -inline fun LenientStubber.whenever(methodCall: T): OngoingStubbing { +inline fun LenientStubber.whenever(methodCall: T): OngoingStubbing { return `when`(methodCall) } -inline fun LenientStubber.whenever(methodCall: () -> T): OngoingStubbing { +inline fun LenientStubber.whenever(methodCall: () -> T): OngoingStubbing { return whenever(methodCall()) } diff --git a/tests/src/test/kotlin/test/LenientStubberTest.kt b/tests/src/test/kotlin/test/LenientStubberTest.kt index d3e67fe3..f7dddd57 100644 --- a/tests/src/test/kotlin/test/LenientStubberTest.kt +++ b/tests/src/test/kotlin/test/LenientStubberTest.kt @@ -34,4 +34,18 @@ open class LenientStubberTest { Assert.assertEquals("List should contain hello", "hello", mock[1]) } + + @Test + fun unused_and_lenient_stubbings_with_nullable() { + val mock = mock() + lenient().whenever(mock.returnsNullableString()).doReturn(null) + whenever(mock.returnsNonNullableString()).doReturn("hello") + + Assert.assertEquals("Should return hello", "hello", mock.returnsNonNullableString()) + } + + private class NullableToString { + fun returnsNullableString(): String? = "" + fun returnsNonNullableString(): String = "" + } }