package tests; import java.io.ByteArrayInputStream; import org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler; import org.codehaus.groovy.eclipse.core.compiler.GroovyCompilerConfigurationBuilder; import org.codehaus.groovy.eclipse.core.compiler.IGroovyCompiler; import org.codehaus.groovy.eclipse.core.compiler.IGroovyCompilerConfiguration; import org.codehaus.groovy.eclipse.refactoring.core.utils.GroovyCompilationReporter; import junit.framework.TestCase; public class ASTBuilderTest extends TestCase{ private final static String GROOVY_CODE = "def a = new unknownClass()"; private void generateAST(IGroovyCompilerConfiguration config){ ByteArrayInputStream is = new ByteArrayInputStream(GROOVY_CODE.getBytes()); GroovyCompilationReporter reporter = new GroovyCompilationReporter(); IGroovyCompiler compiler = new GroovyCompiler(); compiler.compile("", is, config, reporter); } public void testRegularASTGeneration(){ IGroovyCompilerConfiguration config = new GroovyCompilerConfigurationBuilder().buildAST().done(); try { generateAST(config); fail("Generation is supposed to fail in this case"); } catch (IllegalStateException e) { } } public void testASTGenerationWithOutClassResolution(){ IGroovyCompilerConfiguration config = new GroovyCompilerConfigurationBuilder().buildAST().doNotResolveAST().done(); try { generateAST(config); } catch (IllegalStateException e) { fail("Generation is not supposed to fail in this case"); } } }