public void handlers_local() throws TemplateException, IOException {
getEngine("with_local_handlers", factory);
Iterator<?> i = velocityEngine.getConfiguration().getEventCartridge().getReferenceInsertionEventHandlers();
assertThat(i.next(), instanceOf(RenderableHandler.class));
ConditionalEscapeHandler h2 = (ConditionalEscapeHandler) i.next();
assertFalse(i.hasNext());
Context ctx = new VelocityContext();
// no escape
ctx.put("object", new MyRenderable());
String content = velocityEngine.mergeTemplate("test_renderable.vm", ctx, null);
assertThat(content, containsAll("from render()"));
assertThat(content, not(containsString("escaped")));
// escape
ctx.put("escape", "true");
content = velocityEngine.mergeTemplate("test_renderable.vm", ctx, null);
assertThat(content, containsAll("escaped from render()"));
// check handler
ConditionalEscapeHandler new_h2 = ConditionalEscapeHandler.handlerHolder.get();
ConditionalEscapeHandler.handlerHolder.remove();
assertNotNull(new_h2);
assertNotSame(h2, new_h2);
}