what does >> and 1* means in this groovy statement?

Avinash Agrawal picture Avinash Agrawal · Aug 4, 2015 · Viewed 8.9k times · Source

I am working on grails/groovy project and while reading their test documentation came across this line of code

1 * myService.prova() >> { true }

I am unable to understand what does 1 * means here also as >> is right shift operator what does it mean here ? I have searched so much but unable to get any proper explanation. Grails Test Documenation

Answer

Deigote picture Deigote · Aug 4, 2015

This is not groovy per se, but the testing framework called Spock (which is very popular among Groovy developers, for good reasons :-) - http://spockframework.github.io/spock/docs/1.0/index.html

This expression in particular is a way to instruct Spock that it should expect exactly one call to the method prova in myService, and that this call should be mocked to return true. See Interaction based testing , in particular the section called Combining Mocking and Stubbing.