alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (ClosureInStaticMethodTest.groovy)

This example Groovy source code file (ClosureInStaticMethodTest.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

closureinstaticmethodtest, closureinstaticmethodtest, groovytestcase, groovytestcase

The Groovy ClosureInStaticMethodTest.groovy source code

package groovy

/** 
 * @author <a href="mailto:james@coredevelopers.net">James Strachan
 * @version $Revision: 4996 $
 */
class ClosureInStaticMethodTest extends GroovyTestCase {

    void testClosureInStaticMethod() {
        def closure = closureInStaticMethod()
        assertClosure(closure)    
    }

    void testMethodClosureInStaticMethod() {
        def closure = methodClosureInStaticMethod()
        assertClosure(closure)    
    }
    
    static def closureInStaticMethod() {
        return { println(it) }
    }

    static def methodClosureInStaticMethod() {
        System.out.&println
    }
    
    static def assertClosure(Closure block) {
        assert block != null
        block.call("hello!")
    }
    
    void testClosureInStaticMethodCallingStaticMethod() {
       assert doThing(1) == 10
       assert this.doThing(1) == 10
       assert ClosureInStaticMethodTest.doThing(1) == 10
    }
    
    
    static doThing(count) {
      def ret = count
      if (count > 2) return ret
      count.times {
        ret += doThing(count+it+1)
      }
      return ret
    }
}

Other Groovy examples (source code examples)

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

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.