Skip to content

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

@DenisNovac

Description

@DenisNovac

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions