changeset 772:62ee612afc3e

8037779: NoPersistenceCachingTest fails with ant test Reviewed-by: sundar, hannesw
author mnunez
date Wed, 19 Mar 2014 16:01:19 +0100
parents e2df2f9b4d70
children bc86e23d6ae4 21fe19543736
files test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java
diffstat 1 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java	Mon Mar 17 18:27:30 2014 +0100
+++ b/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java	Wed Mar 19 16:01:19 2014 +0100
@@ -37,6 +37,8 @@
 import javax.script.ScriptEngineManager;
 import javax.script.SimpleScriptContext;
 import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
 
 /**
  * @test
@@ -50,8 +52,8 @@
    private ScriptContext context1, context2, context3;
    private ByteArrayOutputStream stderr;
    private PrintStream prevStderr;
-   private final String script = "print('Hello')";
 
+   @BeforeTest
    public void setupTest() {
       stderr = new ByteArrayOutputStream();
       prevStderr = System.err;
@@ -69,33 +71,33 @@
       }
       String[] options = new String[]{"--log=compiler:finest"};
       engine = nashornFactory.getScriptEngine(options);
+      context1 = engine.getContext();
+      context2 = new SimpleScriptContext();
+      context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
+      context3 = new SimpleScriptContext();
+      context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
    }
 
+   @AfterTest
    public void setErrTest() {
       System.setErr(prevStderr);
    }
 
    public void runTest(int numberOfContext, String expectedOutputPattern,
                        int expectedPatternOccurrence) {
-      setupTest();
+
       try {
          switch (numberOfContext) {
          case 2:
-            context1 = engine.getContext();
-            context2 = new SimpleScriptContext();
-            context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            engine.eval(script, context1);
-            engine.eval(script, context2);
+            String scriptTwoContexts = "print('HelloTwoContexts')";
+            engine.eval(scriptTwoContexts, context1);
+            engine.eval(scriptTwoContexts, context2);
             break;
          case 3:
-            context1 = engine.getContext();
-            context2 = new SimpleScriptContext();
-            context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            context3 = new SimpleScriptContext();
-            context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
-            engine.eval(script, context1);
-            engine.eval(script, context2);
-            engine.eval(script, context3);
+            String scriptThreeContexts = "print('HelloThreeContexts')";
+            engine.eval(scriptThreeContexts, context1);
+            engine.eval(scriptThreeContexts, context2);
+            engine.eval(scriptThreeContexts, context3);
             break;
          }
       } catch (final Exception se) {
@@ -113,7 +115,7 @@
                     + expectedPatternOccurrence + " and found: " + matches + "\n"
               + stderr);
       }
-      setErrTest();
+      stderr.reset();
    }
 
    private static String getCodeCachePattern() {