Spock: mock a method with varargs

无人久伴 提交于 2019-12-01 21:05:48
charles

You can avoid having to explain the varargs by using Mock() instead of GroovyMock().

In general, when writing Spock specifications you should prefer Spock's Mock object over Groovy's GroovyMock unless you intend to use some of the unique functionality from GroovyMock. Reference

Swapping out Mock for GroovyMock allows you to avoid the verbose Object params:

        setup:
            def consoleM = Mock(IConsole)
            1 * consoleM.readline(_) >> "hey"

        when:
            def result = consoleM.readline("prompt")

        then:
            result == "hey"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!