@SuppressWarnings("unchecked")
@Test(expected = FreemarkerRequestException.class)
public void testGetKeysException() throws TemplateModelException {

    Template template = createMock(Template.class);
    TemplateHashModelEx model = createMock(TemplateHashModelEx.class);
    TemplateModel valueModel = createMock(TemplateModel.class);
    Configuration configuration = createMock(Configuration.class);
    Set<String> names = createMock(Set.class);
    Iterator<String> namesIt = createMock(Iterator.class);
    Writer writer = new StringWriter();
    expect(template.getMacros()).andReturn(new HashMap<Object, Object>());
    expect(model.keys()).andThrow(new TemplateModelException());
    expect(template.getConfiguration()).andReturn(configuration);
    expect(configuration.getSharedVariableNames()).andReturn(names);
    replay(template, model, valueModel, configuration, names, namesIt);
    try {
        Environment env = new Environment(template, model, writer);
        EnvironmentScopeExtractor extractor = new EnvironmentScopeExtractor(env);
        extractor.getKeys();
    } finally {
        verify(template, model, valueModel, configuration, names, namesIt);
    }
}