ChainedDelegateRenderer implements Renderer { @Override public void render(String value, Request request) throws IOException { if (value == null) { throw new NullPointerException("The attribute value is null"); } for (Renderer renderer : renderers) { if (renderer.isRenderable(value, request)) { renderer.render(value, request); return; } } throw new CannotRenderException("Cannot renderer value '" + value + "'"); } ChainedDelegateRenderer(); void addAttributeRenderer(Renderer renderer); @Override void render(String value, Request request); boolean isRenderable(String value, Request request);  }
@Test(expected = NullPointerException.class) public void testWriteNull() throws IOException { StringWriter writer = new StringWriter(); Request requestContext = EasyMock .createMock(Request.class); replay(requestContext, stringRenderer, templateRenderer, definitionRenderer); try { renderer.render(null, requestContext); } finally { writer.close(); verify(requestContext, stringRenderer, templateRenderer, definitionRenderer); } }