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

Groovy example source code file (LazyInitOnClassNodeTest.groovy)

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

arraylist, arraylist, classnodemethodslistgrowth, classnodemethodslistgrowth, groovytestcase, groovytestcase, lazyinitonclassnodetest, lazyinitonclassnodetest

The Groovy LazyInitOnClassNodeTest.groovy source code

import org.codehaus.groovy.ast.*

class LazyInitOnClassNodeTest extends GroovyTestCase {
    void testLazyInit() {
        def script = """
          class ClassNodeMethodsListGrowth {
            // Setting the type to ArrayList triggers a growth in methodsList
            ArrayList array1=new ArrayList()
        
            // ... using dynamic typing does not
            // def array2=new ArrayList()
            
            // Test method as a sanity check
            def get(o) { return "ok" }
          } 
        """
        def listType = ClassHelper.make(List.class)
        def last=0
        5.times {
          def loader = new GroovyClassLoader(this.class.classLoader)
          assert loader.parseClass(script).newInstance().get("default")=="ok"
          def size = listType.redirect().getMethods().size()
          if (last!=0) assert last==size 
          if (last==0) last = size
        }
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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