Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke "cats.effect.IO.map(scala.Function1)" because "fa" is null #493

Open
DenisNovac opened this issue Apr 21, 2023 · 0 comments
Open

Comments

@DenisNovac
Copy link

Recently i stuck with this error message:

java.lang.NullPointerException: Cannot invoke "cats.effect.IO.map(scala.Function1)" because "fa" is null

As is turned out, it means the mock can't find configured return answer for incoming request. The same as here:

whenF(mock.method("a")).thenReturn(response)
mock.method("b") // b is not configured input

I believe it is pretty much the same error as this:

You have a NullPointerException here:
-> at org.scalatest.OptionValues$Valuable.value(OptionValues.scala:126)
because this method call was *not* stubbed correctly:
-> at scala.Option.orElse(Option.scala:477)
foo.returnsGenericOption(ValueClass(HOLA));

But for some reason effect test libraries (i tried this with pure Cats Effect and Weaver) don't show the correct message.

Most definitely (if you didn't just messed up the inputs and outputs) you need to use eqTo + some equality implicit. Example for MockitoCats trait:

 implicit val reqEq: Eq[Request] = (x: Request, y: Request) =>
    x.value == y.value // some complex object equality check

whenF(mock.method(eqTo(request))).thenReturn(response)

This is mostly for searching purposes of future users since i had troubles with debugging this thing. Guess it could be closed without any actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant