AbstractDefaultToStringRenderable implements Renderable { @Override public String toString() { StringWriter writer = new StringWriter(); try { render(null, writer); } catch (MethodInvocationException e) { throw new TilesVelocityException("Cannot invoke method when rendering", e); } catch (ParseErrorException e) { throw new TilesVelocityException("Cannot parse when rendering", e); } catch (ResourceNotFoundException e) { throw new TilesVelocityException("Cannot find resource when rendering", e); } catch (IOException e) { throw new TilesVelocityException("I/O exception when rendering", e); } finally { try { writer.close(); } catch (IOException e) { log.error("Error when closing a StringWriter, the impossible happened!", e); } } return writer.toString(); } AbstractDefaultToStringRenderable(Context velocityContext,
            Map<String, Object> params, HttpServletResponse response,
            HttpServletRequest request); @Override String toString();  }
@Test public void testToString() { Context velociContext = createMock(Context.class); HttpServletRequest request = createMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); Map<String, Object> params = new HashMap<String, Object>(); params.put("one", "value1"); replay(velociContext, request, response); DefaultRenderable renderable = new DefaultRenderable(velociContext, params, response, request); assertEquals("Hello!", renderable.toString()); assertTrue(renderable.getWriter() instanceof StringWriter); assertNull(renderable.getInternalContextAdapter()); verify(velociContext, request, response); }