### Question:
ScraperContext implements DynamicScopeContext { @Override @SuppressWarnings({"ConstantConditions"}) public Variable replaceExistingVar(String name, Variable variable) { new VariableName(name); final Stack<Variable> variableValueStack = centralReferenceTable.get(name); Assert.isFalse(variableValueStack == null || variableValueStack.isEmpty(), "Variable {0} does not exist", name); return variableValueStack.replaceTop((Variable) ObjectUtils.defaultIfNull(variable, EmptyVariable.INSTANCE)); } 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(expectedExceptions = IllegalArgumentException.class) public void testReplaceExistingVar_noSuchVariable() throws Exception { context.replaceExistingVar("notExisting", dummyVar); }
@Test public void testReplaceExistingVar() throws Exception { context.setLocalVar("x", new NodeVariable("old val")); context.replaceExistingVar("x", dummyVar); assertSame(context.getVar("x"), dummyVar); }