You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
interfaceTestContract {
suspendfungetSuspend(): BooleanfungetSynchronous(): Boolean
}
classMockitoReproducer {
privateval contractMock = mock<TestContract>()
@Test
fun`should not fail with synchronous method`() = runTest {
// Save result to variable. result is falseval 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.
The text was updated successfully, but these errors were encountered:
When there is a suspending method that return some built-in type (
Boolean
,Int
) NPE "Cannot invoke "java.lang.Boolean.booleanValue()"
" was thrown when storingverify
method call result in variable, on callingverify
inside if or when. There is no exception whenverify
used as last expression ofUnit
-returning method, or when mocked method is not suspending.Here code to reproduce this bug:
Last three tests not passing.
I also created issue in kotlin youtrack in case it is language, not library related bug: link.
The text was updated successfully, but these errors were encountered: