1

I have a scenario like

fun someMethod() {
   try {
       val response = callApi.method()
       val output = processResponse(response)
   } catch (throwable: Throwable) {
   }
}

Now I'm testing for the scenario when callApi.method() throws an exception and the method processResponse() is not invoked. It is working as expected but mockk is failing

verify(exactly = 0) { processResponse(any()) }
verify { processResponse(any()) wasNot Called }

with this error:

java.lang.NullPointerException: Parameter specified as non-null is null

My question is that why mockk is trying to execute the processResponse() method with a null response from any() when I'm just verifying that the method is not invoked? Are there any other ways to avoid this error? Thanks

Karsten Gabriel
  • 3,115
  • 6
  • 19
AndroidDev
  • 5,193
  • 5
  • 37
  • 68
  • I think you are not mocking your class under test properly. Please share more of your code – AndrewL Jan 10 '23 at 14:23
  • Are you sure that `wasNot Called` is what you want to use here? Maybe this answer can help you: https://stackoverflow.com/a/75028370/15375588 – Karsten Gabriel Jan 11 '23 at 11:33

0 Answers0