### Question:
ScraperContext implements DynamicScopeContext { @Override public <R> R executeWithinNewContext(Callable<R> callable) throws InterruptedException { try { variablesNamesStack.push(new HashSet<String>()); return callable.call(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } finally { for (String varName : variablesNamesStack.pop()) { removeVarFromCRT(varName); } } } ScraperContext(); @PostConstruct void initContext(); void setLocalVar(String name, Object value); @Override void setLocalVar(String name, Variable variable); @Override @SuppressWarnings({"ConstantConditions"}) Variable replaceExistingVar(String name, Variable variable); @Override Variable getVar(String name); @Override boolean containsVar(String name); @Override @SuppressWarnings({"unchecked"}) Iterator<KeyValuePair<Variable>> iterator(); @Override R executeWithinNewContext(Callable<R> callable); @Override // TODO Add unit test void setLocalVar(final Map<String, Object> map); @Override @Deprecated FunctionDef getFunctionDef(final String name); @Override @Deprecated void addFunctionDef(final FunctionDef funcDef); @Override @Deprecated ScriptingLanguage getScriptingLanguage(); @Override @Deprecated void setScriptingLanguage(final ScriptingLanguage language); @Override String getCharset(); @Override void setCharset(final String charset); @Override Config getConfig(); @Override @Deprecated void setConfig(final Config config);  }### Answer:
@Test public void testExecuteWithinNewContext() throws Exception { context.setLocalVar("x", "a"); context.setLocalVar("y", 1); context.executeWithinNewContext(new Callable<Object>() { @Override public Object call() throws InterruptedException { context.setLocalVar("y", 2); context.executeWithinNewContext(new Callable<Object>() { @Override public Object call() throws InterruptedException { context.setLocalVar("z", "zzz"); context.executeWithinNewContext(new Callable<Object>() { @Override public Object call() { context.setLocalVar("x", "b"); assertReflectionEquals(new NodeVariable("b"), context.getVar("x")); assertReflectionEquals(new NodeVariable(2), context.getVar("y")); assertReflectionEquals(new NodeVariable("zzz"), context.getVar("z")); assertReflectionEquals(Arrays.asList( new KeyValuePair<Variable>("x", new NodeVariable("b")), new KeyValuePair<Variable>("y", new NodeVariable(2)), new KeyValuePair<Variable>("z", new NodeVariable("zzz")) ), IteratorUtils.toList(context.iterator()), ReflectionComparatorMode.LENIENT_ORDER); return null; } }); assertReflectionEquals(new NodeVariable("a"), context.getVar("x")); assertReflectionEquals(new NodeVariable(2), context.getVar("y")); assertReflectionEquals(new NodeVariable("zzz"), context.getVar("z")); assertReflectionEquals(Arrays.asList( new KeyValuePair<Variable>("x", new NodeVariable("a")), new KeyValuePair<Variable>("y", new NodeVariable(2)), new KeyValuePair<Variable>("z", new NodeVariable("zzz")) ), IteratorUtils.toList(context.iterator()), ReflectionComparatorMode.LENIENT_ORDER); return null; } }); assertReflectionEquals(new NodeVariable("a"), context.getVar("x")); assertReflectionEquals(new NodeVariable(2), context.getVar("y")); assertNull(context.getVar("z")); assertReflectionEquals(Arrays.asList( new KeyValuePair<Variable>("x", new NodeVariable("a")), new KeyValuePair<Variable>("y", new NodeVariable(2)) ), IteratorUtils.toList(context.iterator()), ReflectionComparatorMode.LENIENT_ORDER); return null; } }); assertReflectionEquals(new NodeVariable("a"), context.getVar("x")); assertReflectionEquals(new NodeVariable(1), context.getVar("y")); assertNull(context.getVar("z")); assertReflectionEquals(Arrays.asList( new KeyValuePair<Variable>("x", new NodeVariable("a")), new KeyValuePair<Variable>("y", new NodeVariable(1)) ), IteratorUtils.toList(context.iterator()), ReflectionComparatorMode.LENIENT_ORDER); }