Saturday, March 7, 2015

Groovy overloaded operator

Groovy overloaded operator (bit shift on objects)

This example come from "Groovy Goodness Notebook".

Clone repo:
git clone https://github.com/piotrpietrzak/gatchaman.git
Switch to branch:
git checkout origin/groovy/multiple_overloaded_operator_methods
Test in spock is quite interesting:
def "should add operation for user" () {
    setup:
    Priviledge priviledge = new Priviledge()
    User user = new User(name: 'Test name')
    Operation operation = new Operation(name: 'Test operation')

    when:
    priviledge << user << operation

    then:
    priviledge.users.contains user
    priviledge.operations.contains operation
}

No comments:

Post a Comment