mardi 16 mars 2021

How to call a curried function on a mock?

I have a generic function that looks like so

  def getFromCacheOrCallService[T: ClassTag](cacheKey: String, duration: Duration = cacheDefaultDuration)(
      callServiceToFetchValue: => Try[T]
  ): Try[T]

and Im trying to figure out how to mock this function in a way that will always call callServiceToFetchValue and use it instead. I have this so far

doAnswer(invocation => {
  invocation.getArgumentAt(1, classOf[() => Try[PARISMarketplace]])()
}).when(marketplaceCache).cacheable(any(), any())(any())(any())

Which if I understand what Im doing correctly should call the function passed, but whenever I try to run I get this error

Invalid use of argument matchers!
4 matchers expected, 3 recorded:

Why is it saying it expects 4 matchers? I have 4 matchers, I dont understand what the problem is.

Aucun commentaire:

Enregistrer un commentaire