我正在尝试模拟一个具有多个参数的函数的对象。
我只是试着为它设定期望。也就是说,某种形式:
(item.addMetadata( , , , , , )).expects("","","","","","","")
我只是不知道怎么写。该示例,通常处理一个参数函数: (item.addMetadata _).expects("")
如何处理多个参数?
编辑1
我更改为只是为了编译:
(item.addMetadata _) expects (where {
(schema: String, element: String, qualifier: String, lang: String, value: String) => true
})
现在问题显然是方法重载了?
我收到以下错误:
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 { ^
作为一个方面,我还应该补充一个事实,即我在模拟一个类而不是一个接口。这是不受我控制的类,有一个私有构造函数,只有一个静态创建方法。所以我也收到以下错误:
Error:(18, 24) constructor Item in class Item cannot be accessed in <$anon: org.dspace.content.Item> val item = mock[Item] ^