test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java

Print this page




 835             fail();
 836         } catch (NullPointerException x) {
 837             // expected
 838         }
 839 
 840         try {
 841             b.putAll(Collections.singletonMap((String)null, "null-value"));
 842             fail();
 843         } catch (NullPointerException x) {
 844             // expected
 845         }
 846 
 847         try {
 848             b.putAll(Collections.singletonMap("", "empty-value"));
 849             fail();
 850         } catch (IllegalArgumentException x) {
 851             // expected
 852         }
 853     }
 854 











 855     private static void checkProperty(final ScriptEngine e, final String name)
 856         throws ScriptException {
 857         final String value = System.getProperty(name);
 858         e.put("name", name);
 859         assertEquals(value, e.eval("java.lang.System.getProperty(name)"));
 860     }
 861 
 862     private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 863 
 864     // Returns String that would be the result of calling PrintWriter.println
 865     // of the given String. (This is to handle platform specific newline).
 866     private static String println(final String str) {
 867         return str + LINE_SEPARATOR;
 868     }
 869 }


 835             fail();
 836         } catch (NullPointerException x) {
 837             // expected
 838         }
 839 
 840         try {
 841             b.putAll(Collections.singletonMap((String)null, "null-value"));
 842             fail();
 843         } catch (NullPointerException x) {
 844             // expected
 845         }
 846 
 847         try {
 848             b.putAll(Collections.singletonMap("", "empty-value"));
 849             fail();
 850         } catch (IllegalArgumentException x) {
 851             // expected
 852         }
 853     }
 854 
 855     // @bug 8071989: NashornScriptEngine returns javax.script.ScriptContext instance
 856     // with insonsistent get/remove methods behavior for undefined attributes
 857     @Test
 858     public void testScriptContextGetRemoveUndefined() throws Exception {
 859         final ScriptEngineManager manager = new ScriptEngineManager();
 860         final ScriptEngine e = manager.getEngineByName("nashorn");
 861         final ScriptContext ctx = e.getContext();
 862         assertNull(ctx.getAttribute("undefinedname", ScriptContext.ENGINE_SCOPE));
 863         assertNull(ctx.removeAttribute("undefinedname", ScriptContext.ENGINE_SCOPE));
 864     }
 865 
 866     private static void checkProperty(final ScriptEngine e, final String name)
 867         throws ScriptException {
 868         final String value = System.getProperty(name);
 869         e.put("name", name);
 870         assertEquals(value, e.eval("java.lang.System.getProperty(name)"));
 871     }
 872 
 873     private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 874 
 875     // Returns String that would be the result of calling PrintWriter.println
 876     // of the given String. (This is to handle platform specific newline).
 877     private static String println(final String str) {
 878         return str + LINE_SEPARATOR;
 879     }
 880 }