我试图模拟具有多个参数功能的对象。
我只是尝试设定期望值。也就是说,形式如下:
(item.addMetadata( ,,,,,))。预计( “”, “”, “”, “”, “”, “”, “”)
我只是不知道怎么写。该示例通常处理一个参数函数:(item.addMetadata _)。expects(“”)
如何处理多重论点?
编辑1
为了进行编译,我将其更改为Just:
(item.addMetadata _) expects (where {
(schema: String, element: String, qualifier: String, lang: String, value: String) => true
})
Run Code Online (Sandbox Code Playgroud)
现在的问题显然是该方法重载了吗?
我收到以下错误:
Run Code Online (Sandbox Code Playgroud)Error:(21, 15) ambiguous reference to overloaded definition, both method addMetadata in class Item of type (x$1: String, x$2: String, x$3: String, x$4: String, x$5: String, x$6: String, x$7: Int)Unit and method addMetadata in class Item of type (x$1: String, x$2: String, x$3: String, x$4: String, x$5: String)Unit match expected type ? (item.addMetadata _) expects (where { ^
从侧面讲,我还应该补充一个事实,我在嘲笑一个类而不是一个接口。这是不受我控制的类,具有私有构造函数和仅静态创建方法。所以我也得到以下错误:
Run Code Online (Sandbox Code Playgroud)Error:(18, 24) constructor Item in class Item cannot be accessed in <$anon: org.dspace.content.Item> val item = mock[Item] ^
我需要的是处理对象的重载方法。最初我没有弄清楚。
因此解决方案是编写:
(item.addMetadata(_: String, _:String, _:String, _:String, _:String)) expects ("hi", "he", "hey", "test", "holla")
Run Code Online (Sandbox Code Playgroud)
但是,如果不是重载方法,那是我最初的问题的一部分,但不确定该怎么做。