Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 331
Avinash Agrawal Avatar asked Aug 04 '15 06:08

Avinash Agrawal


People also ask

What does << do in groovy?

In groovy, the bitwise operators can be overridden with the leftShift (<<) and rightShift (>>) methods defined on the class. It's idiomatic groovy to use the leftShift method for append actions on strings, buffers, streams, arrays, etc and thats what you're seeing here.

What is -> in groovy?

It is used to separate where you declare bindings for your closure from the actual code, eg: def myClosure = { x, y -> x + y } the part before -> declares that the closure has two arguments named x and y while the second part is the code of the closure.


1 Answers

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.

like image 137
Deigote Avatar answered Sep 24 '22 07:09

Deigote