package groovy.lang

class ClassReloadingTest extends GroovyTestCase {

	public void testRealoding() {
		def file = File.createTempFile("TestReload",".groovy")
		file.deleteOnExit()
		def className = file.name-".groovy"

		def cl = new GroovyClassLoader(this.class.classLoader);
		def currentDir = file.parentFile.absolutePath
		cl.addClasspath(currentDir)
			
		
        try {
     		file.write """
    		  class $className {
    		    @Property hello = "hello"
    		  }
    		  """
    		def groovyClass = cl.loadClass(className,true,false)
    		def object = groovyClass.newInstance()
    		assert "hello"== object.hello
    					
    		// change class
    		file.write """
    		  class $className {
    		    @Property hello = "goodbye"
    		  }
    		  """
    		
    		// reload		
    		groovyClass = cl.loadClass(className,true,false)
    		object  = groovyClass.newInstance()
    		assert "goodbye" == object.hello
    	} finally {
		  file.delete()
		}
	}
}
package groovy.lang

class ClassReloadingTest extends GroovyTestCase {

	public void testRealoding() {
		def file = File.createTempFile("TestReload",".groovy", new File("target"))
		file.deleteOnExit()
		def className = file.name-".groovy"

		def cl = new GroovyClassLoader(this.class.classLoader);
		def currentDir = file.parentFile.absolutePath
		cl.addClasspath(currentDir)
			
		
        try {
     		file.write """
    		  class $className {
    		    @Property hello = "hello"
    		  }
    		  """
    		def groovyClass = cl.loadClass(className,true,false)
    		def object = groovyClass.newInstance()
    		assert "hello"== object.hello
    					
    		// change class
    		file.write """
    		  class $className {
    		    @Property hello = "goodbye"
    		  }
    		  """
    		
    		// reload		
    		groovyClass = cl.loadClass(className,true,false)
    		object  = groovyClass.newInstance()
    		assert "goodbye" == object.hello
    	} finally {
		  file.delete()
		}
	}
}
Make sure the temporary file is created in the target directory, because otherwise on JDK 1.5, the temp file is created in groovy-core, and the test won't run properly because the file (for some unknown reason yet) is not deleted upon exit.
Make sure the temporary file is created in the target directory, because otherwise on JDK 1.5, the temp file is created in groovy-core, and the test won't run properly because the file (for some unknown reason yet) is not deleted upon exit.


git-svn-id: aa43ce4553b005588bb3cc6c16966320b011facb@3543 a5544e8c-8a19-0410-ba12-f9af4593a198
