@Test public void renderWithException() throws Exception { Exception exception = new XWikiVelocityException("exception"); when(velocityManager.getVelocityEngine()).thenThrow(exception); IconException caughtException = null; try { mocker.getComponentUnderTest().render("myCode"); } catch(IconException e) { caughtException = e; } assertNotNull(caughtException); assertEquals("Failed to render the icon.", caughtException.getMessage()); assertEquals(exception, caughtException.getCause()); }
public String render(String code) throws IconException { String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); StringWriter output = new StringWriter(); VelocityEngine engine = null; try { engine = velocityManager.getVelocityEngine(); engine.startedUsingMacroNamespace(namespace); VelocityContext context = new XWikiVelocityContext(velocityManager.getVelocityContext()); if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { return output.toString(); } else { throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); } } catch (XWikiVelocityException e) { throw new IconException("Failed to render the icon.", e); } finally { if (engine != null) { engine.stoppedUsingMacroNamespace(namespace); } } }
VelocityRenderer { public String render(String code) throws IconException { String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); StringWriter output = new StringWriter(); VelocityEngine engine = null; try { engine = velocityManager.getVelocityEngine(); engine.startedUsingMacroNamespace(namespace); VelocityContext context = new XWikiVelocityContext(velocityManager.getVelocityContext()); if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { return output.toString(); } else { throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); } } catch (XWikiVelocityException e) { throw new IconException("Failed to render the icon.", e); } finally { if (engine != null) { engine.stoppedUsingMacroNamespace(namespace); } } } }
VelocityRenderer { public String render(String code) throws IconException { String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); StringWriter output = new StringWriter(); VelocityEngine engine = null; try { engine = velocityManager.getVelocityEngine(); engine.startedUsingMacroNamespace(namespace); VelocityContext context = new XWikiVelocityContext(velocityManager.getVelocityContext()); if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { return output.toString(); } else { throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); } } catch (XWikiVelocityException e) { throw new IconException("Failed to render the icon.", e); } finally { if (engine != null) { engine.stoppedUsingMacroNamespace(namespace); } } }  }
VelocityRenderer { public String render(String code) throws IconException { String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); StringWriter output = new StringWriter(); VelocityEngine engine = null; try { engine = velocityManager.getVelocityEngine(); engine.startedUsingMacroNamespace(namespace); VelocityContext context = new XWikiVelocityContext(velocityManager.getVelocityContext()); if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { return output.toString(); } else { throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); } } catch (XWikiVelocityException e) { throw new IconException("Failed to render the icon.", e); } finally { if (engine != null) { engine.stoppedUsingMacroNamespace(namespace); } } }  String render(String code); }
VelocityRenderer { public String render(String code) throws IconException { String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); StringWriter output = new StringWriter(); VelocityEngine engine = null; try { engine = velocityManager.getVelocityEngine(); engine.startedUsingMacroNamespace(namespace); VelocityContext context = new XWikiVelocityContext(velocityManager.getVelocityContext()); if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { return output.toString(); } else { throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); } } catch (XWikiVelocityException e) { throw new IconException("Failed to render the icon.", e); } finally { if (engine != null) { engine.stoppedUsingMacroNamespace(namespace); } } }  String render(String code);  }