Examples of SnippetFixture


Examples of ratpack.manual.snippets.fixture.SnippetFixture

    List<String> importsAndSnippet = extractImports(snippet.getSnippet());

    String imports = importsAndSnippet.get(0);
    String snippetMinusImports = importsAndSnippet.get(1);

    SnippetFixture fixture = snippet.getFixture();
    String fullSnippet = imports + fixture.pre() + snippetMinusImports + fixture.post();


    Script script;
    try {
      script = groovyShell.parse(fullSnippet, snippet.getClassName());
    } catch (MultipleCompilationErrorsException e) {
      Message error = e.getErrorCollector().getError(0);
      if (error instanceof SyntaxErrorMessage) {
        //noinspection ThrowableResultOfMethodCallIgnored
        throw new CompileException(e, ((SyntaxErrorMessage) error).getCause().getLine());
      } else {
        throw e;
      }
    }

    ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(groovyShell.getClassLoader());
      fixture.setup();
      try {
        script.run();
      } finally {
        fixture.cleanup();
      }
    } finally {
      Thread.currentThread().setContextClassLoader(previousContextClassLoader);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.