Open Mahoney opened 5 years ago
Had a crack at this, but I'm not sure it's possible because mockito can't distinguish between calls to the mock passed to given
or when
, when the default null
return is necessary, and calls to the mock in actual test execution.
I'm not sure it's possible because mockito can't distinguish between calls to the mock passed to given or when, when the default null return is necessary, and calls to the mock in actual test execution.
@Mahoney Exactly
This is an interesting case and I'm willing to leave it open to see if there's a solution to be found, although I'm afraid earlier observations may have shown this impossible.
Mockito returns null for any invocation where no expectation was set up.
If the method return type is non-nullable in Kotlin you get an NPE at a point it shouldn't really be possible given the type system's guarantees.
It would be good if you got a meaningful exception (
"Unexpected invocation of method < signature > which has a non-nullable return type with arguments < args > on mock < mock >"
) at the line the method was called.