Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ package org.mockito.kotlin
import org.mockito.stubbing.LenientStubber
import org.mockito.stubbing.OngoingStubbing

inline fun <reified T : Any> LenientStubber.whenever(methodCall: T): OngoingStubbing<T> {
inline fun <reified T> LenientStubber.whenever(methodCall: T): OngoingStubbing<T> {
return `when`(methodCall)
}

inline fun <reified T : Any> LenientStubber.whenever(methodCall: () -> T): OngoingStubbing<T> {
inline fun <reified T> LenientStubber.whenever(methodCall: () -> T): OngoingStubbing<T> {
return whenever(methodCall())
}

14 changes: 14 additions & 0 deletions tests/src/test/kotlin/test/LenientStubberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<NullableToString>()
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 = ""
}
}