Is there any way to do mock argument capturing in Spock

こ雲淡風輕ζ 提交于 2019-12-03 04:20:42

You can capture an argument as follows:

// must be declared before when-block (or inside Specification.interaction {})
def captured

when:
...

then:
1 * mock.doNetworkCall(...) >> { record, recordClass -> 
    // save the argument
    captured = record
    ...
}
// use the saved argument
captured == ...

That said, often there is a simpler solution such as checking the expected record right in the argument constraint (e.g. ...doNetworkCall( { it == ... } )).

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