I have been seeing the use of "when" and "then" keyword in Groovy in several Groovy articles. One of them is here. I searched for the Groovy Doc's but I couldn't find it. So whats the actual purposes of these keyword's? Similar to if/then?
Asked
Active
Viewed 8,440 times
3 Answers
1
Technically the then, when and a few other constructs in Spock are good old labels (aka goto), which developers rarely use these days. Spock uses them to allow developers to logically and visually separate different aspects of their tests - assumptions, constraints, statements or data. The Spock compile-time AST transformations than use the labels to understand the structure of the test and do its magic.

Vaclav Pech
- 1,431
- 8
- 6
-
A little confusing that the same label can be used multiple times in the same code block (at least... it is to me!) – Armand Nov 30 '11 at 14:53
-
Even in Java, the same label can be used multiple times in a row. There is no risk of ambiguity. – Peter Niederwieser Dec 03 '11 at 01:48