Open
Description
When there is a suspending method that return some built-in type (Boolean
, Int
) NPE "Cannot invoke "java.lang.Boolean.booleanValue()"
" was thrown when storing verify
method call result in variable, on calling verify
inside if or when. There is no exception when verify
used as last expression of Unit
-returning method, or when mocked method is not suspending.
Here code to reproduce this bug:
interface TestContract {
suspend fun getSuspend(): Boolean
fun getSynchronous(): Boolean
}
class MockitoReproducer {
private val contractMock = mock<TestContract>()
@Test
fun `should not fail with synchronous method`() = runTest {
// Save result to variable. result is false
val result = verify(contractMock, never()).getSynchronous()
// Not save result to variable
verify(contractMock, never()).getSynchronous()
}
@Test
fun `should not fail with suspending method when not save result to variable`() = runTest {
verify(contractMock, never()).getSuspend()
}
@Test
fun `should fail with suspending method when save result to variable`() = runTest {
val result = verify(contractMock, never()).getSuspend()
}
@Test
fun `should fail with suspending method when use if as expression`() = runTest {
if (true) {
verify(contractMock, never()).getSuspend()
} else {
verify(contractMock, never()).getSuspend()
}
Unit // To explicitly specify that I not use if as result of lambda
}
@Test
fun `should fail with suspending method when use when as expression`() = runTest {
when {
true -> verify(contractMock, never()).getSuspend()
else -> verify(contractMock, never()).getSuspend()
}
Unit // To explicitly specify that I not use if as result of lambda
}
}
Last three tests not passing.
I also created issue in kotlin youtrack in case it is language, not library related bug: link.
Metadata
Metadata
Assignees
Labels
No labels