@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);
}