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

Groovy example source code file (CompileOrderTest.groovy)

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

compileordertest, compileordertest, file, file, groovytestcase, testorderconcrete, testorderconcrete, testorderinterface, testorderinterface

The Groovy CompileOrderTest.groovy source code

package groovy

class CompileOrderTest extends GroovyTestCase {
   public void testCompileOrder() {
      def interfaceFile = File.createTempFile("TestOrderInterface", ".groovy", new File("target"))
      def concreteFile = File.createTempFile("TestOrderConcrete", ".groovy", new File("target"))

      def cl = new GroovyClassLoader(this.class.classLoader);
      def currentDir = concreteFile.parentFile.absolutePath
      println currentDir
      cl.addClasspath(currentDir)
      cl.shouldRecompile = true

      try {
         // Create the interface
         println "a"
         interfaceFile.deleteOnExit()
         def interfaceName = interfaceFile.name - ".groovy"
         interfaceFile.write "interface $interfaceName { }\n"

         // Create a concrete class which implements the interface
         concreteFile.deleteOnExit()
         def concreteName = concreteFile.name - ".groovy"
         concreteFile.write "class $concreteName implements $interfaceName { }\n"

         // We're testing whether this fails:
         def groovyClass = cl.loadClass(concreteName,true,false)
         // Create an object, just for good measure.
         def object = groovyClass.newInstance()
      } finally {
         interfaceFile.delete()
         concreteFile.delete()
      }
   }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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