简体   繁体   中英

Spock Mock Object to return an object passed into it

I'm trying to test a service implementation that handles conversion and persistence.

I have a repository mocked and and a conversion service wired in. Is it possible in Spock to have a Mock pass back the object that was returned to it?

The syntax I am trying to write would be as follows.

ie

// Have this method return the object that has been passed to it.
repository.save(_ as Entity) >> (Entity) _

有关更多详细信息,请参阅计算 Spock文档的返回值部分,但这样做可以实现您想要完成的任务。

repository.save(_ as Entity) >> { args -> args[0] }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM