CloneableSimpleScriptContext extends SimpleScriptContext implements Cloneable { @Override public CloneableSimpleScriptContext clone() throws CloneNotSupportedException { CloneableSimpleScriptContext cloned = (CloneableSimpleScriptContext) super.clone(); cloned.engineScope = new SimpleBindings(new HashMap<>(this.engineScope)); if (this.globalScope != null) { cloned.globalScope = new SimpleBindings(new HashMap<>(this.globalScope)); } return cloned; }  @Override CloneableSimpleScriptContext clone();  }
@Test void testClone() throws CloneNotSupportedException { CloneableSimpleScriptContext context = new CloneableSimpleScriptContext(); context.setAttribute("engine1", "engine1", ScriptContext.ENGINE_SCOPE); CloneableSimpleScriptContext context2 = context.clone(); assertEquals(context.getAttribute("engine1"), context2.getAttribute("engine1")); context.setBindings(new SimpleBindings(), ScriptContext.GLOBAL_SCOPE); context.setAttribute("global1", "global1", ScriptContext.GLOBAL_SCOPE); context2 = context.clone(); assertEquals(context.getAttribute("engine1"), context2.getAttribute("engine1")); assertEquals(context.getAttribute("global1"), context2.getAttribute("global1")); context2.setAttribute("engine2", "engine2", ScriptContext.ENGINE_SCOPE); context2.setAttribute("global2", "global2", ScriptContext.GLOBAL_SCOPE); assertNull(context.getAttribute("engine2")); assertNull(context.getAttribute("global2")); }