0

Now that Nashorn has been deprecated & removed in JDK 15 what is the best approach to validate that a String is valid Javascript in a JUnit test?

Previous Code:

    private void validateJavascript(final String js) throws ScriptException {
        final NashornScriptEngine scriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine();
        final CompiledScript compile = scriptEngine.compile(js);
    }
Patrick Bray
  • 552
  • 2
  • 7
  • 20

1 Answers1

1

Found the following similar thread Different Nashorn engine for Java < 15 and >= 15? which pointed me to standalone implementation which can be added as a test dependency:

testImplementation 'org.openjdk.nashorn:nashorn-core:15.2'

And then instantiated as follows:

final NashornScriptEngine scriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine();
Patrick Bray
  • 552
  • 2
  • 7
  • 20