Skip to content

Commit 6a521ea

Browse files
committed
Make doReturn accept null values.
Fixes #34.
1 parent c3e6182 commit 6a521ea

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fun <T> doAnswer(answer: (InvocationOnMock) -> T?): Stubber = Mockito.doAnswer {
6262

6363
fun doCallRealMethod(): Stubber = Mockito.doCallRealMethod()!!
6464
fun doNothing(): Stubber = Mockito.doNothing()!!
65-
fun doReturn(value: Any): Stubber = Mockito.doReturn(value)!!
66-
fun doReturn(toBeReturned: Any, vararg toBeReturnedNext: Any): Stubber = Mockito.doReturn(toBeReturned, *toBeReturnedNext)!!
65+
fun doReturn(value: Any?): Stubber = Mockito.doReturn(value)!!
66+
fun doReturn(toBeReturned: Any?, vararg toBeReturnedNext: Any?): Stubber = Mockito.doReturn(toBeReturned, *toBeReturnedNext)!!
6767
fun doThrow(toBeThrown: KClass<out Throwable>): Stubber = Mockito.doThrow(toBeThrown.java)!!
6868
fun doThrow(vararg toBeThrown: Throwable): Stubber = Mockito.doThrow(*toBeThrown)!!
6969

mockito-kotlin/src/test/kotlin/MockitoTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ class MockitoTest {
230230
expect(mock.stringResult()).toBe("test")
231231
}
232232

233+
@Test
234+
fun testDoReturnNullValue() {
235+
val mock = mock<Methods>()
236+
237+
doReturn(null).whenever(mock).stringResult()
238+
239+
expect(mock.stringResult()).toBeNull()
240+
}
241+
242+
@Test
243+
fun testDoReturnNullValues() {
244+
val mock = mock<Methods>()
245+
246+
doReturn(null, null).whenever(mock).stringResult()
247+
248+
expect(mock.stringResult()).toBeNull()
249+
expect(mock.stringResult()).toBeNull()
250+
}
251+
233252
@Test
234253
fun testDoReturnValues() {
235254
val mock = mock<Methods>()

0 commit comments

Comments
 (0)