home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (ClosureSugarTest.groovy)

This example Groovy source code file (ClosureSugarTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

closure, closure, closuresugartest, closuresugartest, groovytestcase, groovytestcase

The Groovy ClosureSugarTest.groovy source code

package groovy

class ClosureSugarTest extends GroovyTestCase {

    def count;

    void testClosureSugar() {
        count = 11;

        sugar {
             count = 20;
        }

        assert count == 20;
    }

    void testMixedClosureSugar() {
        def count = 11;

        mixedSugar (5){a->
             count = count + a;
        }

        assert count == 16;

    }

    def mixedSugar(incrBy, Closure closure) {
        closure.call( incrBy ); 
    }

    def sugar(Closure closure) {
        closure.call();
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy ClosureSugarTest.groovy source code file:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.