DefaultGroovyScriptService implements GroovyScriptService { @Override public Object validateScript(String script) throws ResultCodeException { Assert.notNull(script, "Script is required."); try { GroovyShell shell = new GroovyShell(); return shell.parse(script); } catch (MultipleCompilationErrorsException e) { Object error = e.getErrorCollector().getLastError(); if (error instanceof SyntaxErrorMessage) { SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)error; SyntaxException cause = syntaxErrorMessage.getCause(); throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_SYNTAX_VALIDATION, ImmutableMap.of("message", cause.getOriginalMessage(), "line", cause.getLine()), e); } throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_VALIDATION, e); } catch (CompilationFailedException ex) { throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_VALIDATION, ex); } }  @Override Object evaluate(String script, Map<String, Object> variables); @Override Object evaluate(String script, Map<String, Object> variables, List<Class<?>> extraAllowedClasses); @Override Object validateScript(String script); static final String CACHE_NAME; }
@Test(expected = ResultCodeException.class) public void testUnvalidScript() { String script = "if(true) return \"testOne\"}"; groovyScriptService.validateScript(script); }