最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mockito - Mocking method with Given parameter with Scala 3 - Stack Overflow

programmeradmin6浏览0评论

I've got following problem. Ive got method

def foo(i: Int)(using String): IO[Unit] = ???

when try this it compiles:

when(myClass.foo(any[Int]())).thenReturn(IO.unit)

but it fails at runtime with the message:

2 matchers expected, 1 recorded

When I add explicit matcher:

when(myClass.foo(any[Int]())(any[String]())).thenReturn(IO.unit)

I've got following compilation error:

method foo in class MyClass does not take more parameters

Has anyone had similar issue and solved it?

I've got following problem. Ive got method

def foo(i: Int)(using String): IO[Unit] = ???

when try this it compiles:

when(myClass.foo(any[Int]())).thenReturn(IO.unit)

but it fails at runtime with the message:

2 matchers expected, 1 recorded

When I add explicit matcher:

when(myClass.foo(any[Int]())(any[String]())).thenReturn(IO.unit)

I've got following compilation error:

method foo in class MyClass does not take more parameters

Has anyone had similar issue and solved it?

Share Improve this question edited Mar 20 at 9:27 fr3ak asked Mar 20 at 9:15 fr3akfr3ak 5133 silver badges17 bronze badges 1
  • 1 Which version of Scala and which libraries to integrate Mockito in Scala are you using? – Gaël J Commented Mar 20 at 18:11
Add a comment  | 

1 Answer 1

Reset to default 3

With Scala 3.6.4 and ScalaTest+Mockito 3.2.19.0, the following works:

when(myClass.foo(any[Int]())(using any[String]())).thenReturn(IO.unit)
发布评论

评论列表(0)

  1. 暂无评论