EnvironmentScopeExtractor implements AttributeExtractor { @Override public void removeValue(String name) { request.setVariable(name, null); } EnvironmentScopeExtractor(Environment request); @Override void removeValue(String name); @SuppressWarnings("unchecked") @Override Enumeration<String> getKeys(); @Override Object getValue(String key); @Override void setValue(String key, Object value);  }
@Test public void testRemoveValue() throws TemplateModelException { Template template = createMock(Template.class); TemplateHashModel model = createMock(TemplateHashModel.class); TemplateModel valueModel = createMock(TemplateModel.class); Configuration configuration = createMock(Configuration.class); Writer writer = new StringWriter(); expect(template.getMacros()).andReturn(new HashMap<Object, Object>()); expect(model.get("key")).andReturn(null); expect(template.getConfiguration()).andReturn(configuration); expect(configuration.getSharedVariable("key")).andReturn(null); replay(template, model, valueModel, configuration); Environment env = new Environment(template, model, writer); env.setVariable("key", valueModel); EnvironmentScopeExtractor extractor = new EnvironmentScopeExtractor(env); extractor.removeValue("key"); assertNull(env.getVariable("key")); verify(template, model, valueModel, configuration); }