Scala测试-如何存根Curry方法

5

I have this method

  def addFriend(friendId:String)(userId:String)

我尝试这样进行存根:
 (repositoryMock.addFriend(_:String)(_:String)) when ("bar","foo") returns true

但是当然它不会工作。 并且不能做像(无法编译)这样的事情。
 (repositoryMock.addFriend(_:String)(_:String)) when ("bar")("foo") returns true

有什么想法吗?

你使用哪个模拟框架? - Ben
@ben Scalamock,使用MockFactory。 - igx
1
你能否提供使用 when ("bar","foo") 时出现的错误?我能够成功地使用以下模式:trait Foo { def bar(x: Int)(y: Int): Int }; val foo = stub[Foo]; (foo.bar(_: Int)(_: Int)) when(5, 6) returns 10 - Ben
1
嗨,有点尴尬,但你是对的,我的错!我错过了参数顺序。非常感谢你。你可以把它作为答案发布。 - igx
1个回答

3
解决方案就是你最初尝试的方法——将所有柯里化参数放在一个单独的列表中:
(repositoryMock.addFriend(_:String)(_:String)) when ("bar", "foo") returns true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接