任何数量的args的Groovy模拟方法?

时间:2014-05-15 17:17:05

标签: groovy mocking

Groovy中有一种方法可以模拟一个方法来接受任何数量和类型的args吗?

所以我的用例是我有12个参数的方法,我必须按如下方式编写,

testController.testService = [ testMethod: { a, b, c, d, e, f, g, h, i, j, k, m -> null } ]

似乎应该有更好的方法来做到这一点。

1 个答案:

答案 0 :(得分:1)

testController.testService = [ testMethod: { Object... args -> null } ]

上面的内容适用于varargs,但要与服务类的签名匹配,您可以将该地图推断为该类:

testController.testService = [ testMethod: { Object... args -> null } ] as TestService

如果所有args的类型相同,您也可以提供实际类型。

相关问题