blob: 5c1cc05841b6d42c982389b005c7e4f3d936a82c [file] [log] [blame]
package groovy
/**
* @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
* @version $Revision$
*/
class ClosureMethodCallTest extends GroovyTestCase {
void testCallingClosureWithMultipleArguments() {
def foo
def closure = { a, b -> foo = "hello ${a} and ${b}".toString() }
closure("james", "bob")
assert foo == "hello james and bob"
closure.call("sam", "james")
assert foo == "hello sam and james"
}
void testClosureAsLocalVar() {
def local = { Map params -> params.x * params.y }
assert local(x : 2, y : 3) == 6
}
void testClosureDirectly() {
assert { Map params -> params.x * params.y }(x : 2, y : 3) == 6
}
def attribute
void testClosureAsAttribute() {
attribute = { Map params -> params.x * params.y }
assert attribute(x : 2, y : 3) == 6
}
void testSystemOutPrintlnAsAClosure() {
def closure = System.out.&println
closure("Hello world")
}
}