Groovy notes

Groovy

  • no do-while

Truth

Object

  • identity comparison

    • a.is(b)
  • value comparison

    • a.equals(b)

Class

  • @Immutable: Define immutable class
  • @Sortable: Make class Comparable, implementing compareTo method based on the order of property definition, as well as corresponding Comparator helper methods.
  • @TupleConstructor: Create constructors with different combinations of properies as arguments

Collection

List

  • Use list to replace array, in the case of array literal, use list literal instead, it will get converted automatically.

Map

  • Map keys are strings by default: [a:1] is equivalent to ['a':1]
  • To use value of object a as the key, escape the key by adding parenthesis: [(a): 43] equals to ['Bob': 43]

Groovy Reference

Spock

Comparison to JUnit

SpockJUnit
SpecificationTest class
setup()@Before
cleanup()@After
setupSpec()@BeforeClass
cleanupSpec()@AfterClass
FeatureTest
Feature methodTest method
Data-driven featureTheory
ConditionAssertion
Exception condition@Test(expected=…​)
InteractionMock expectation (e.g. in Mockito)

Spock Reference

Geb

Notes

  • property: .@id
  • text node: .text()

Questions

  • How to access iframe contents