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()
		}
	}
}
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

                Thread.sleep(1000)
    					
    		// 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()
		}
	}
}

Add delay time before modifying the file so that the last Modified timestamps are different.
Add delay time before modifying the file so that the last Modified timestamps
are different.


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