ScriptEngineCache { public static ScriptEngine get(final String engineName) { return CACHED_ENGINES.compute(engineName, (key, engine) -> { if (null == engine) { engine = SCRIPT_ENGINE_MANAGER.getEngineByName(engineName); if (null == engine) { throw new IllegalArgumentException("There is no script engine with provided name: " + engineName); } } return engine; }); } private  ScriptEngineCache(); static ScriptEngine get(final String engineName); final static String DEFAULT_SCRIPT_ENGINE; }
@Test public void shouldGetEngineFromCache() { assertSame(ScriptEngineCache.get("nashorn"), ScriptEngineCache.get("nashorn")); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowWhenScripEngineDoesNotExist() { ScriptEngineCache.get("junk-that-no-one-would-ever-call-a-script-engine-83939473298432"); }