### Question:
AbstractOutputStreamResource implements SAXVisitBefore, DOMVisitBefore, Consumer, VisitLifecycleCleanable, ExecutionLifecycleCleanable { public static Writer getOutputWriter(final String resourceName, final ExecutionContext executionContext) throws SmooksException { String resourceKey = OUTPUTSTREAM_CONTEXT_KEY_PREFIX + resourceName; Object resourceIOObj = executionContext.getAttribute( resourceKey ); if( resourceIOObj == null ) { AbstractOutputStreamResource resource = (AbstractOutputStreamResource) executionContext.getAttribute( RESOURCE_CONTEXT_KEY_PREFIX + resourceName ); OutputStream outputStream = openOutputStream(resource, resourceName, executionContext); Writer outputStreamWriter = new OutputStreamWriter(outputStream, resource.getWriterEncoding()); executionContext.setAttribute( resourceKey, outputStreamWriter ); return outputStreamWriter; } else { if(resourceIOObj instanceof Writer) { return (Writer) resourceIOObj; } else if(resourceIOObj instanceof OutputStream) { throw new SmooksException("An OutputStream to the '" + resourceName + "' resource is already open. Cannot open a Writer to this resource now!"); } else { throw new RuntimeException("Invalid runtime ExecutionContext state. Value stored under context key '" + resourceKey + "' must be either and OutputStream or Writer. Is '" + resourceIOObj.getClass().getName() + "'."); } } }  abstract OutputStream getOutputStream( final ExecutionContext executionContext ); String getResourceName(); boolean consumes(Object object); AbstractOutputStreamResource setResourceName(String resourceName); AbstractOutputStreamResource setWriterEncoding(Charset writerEncoding); Charset getWriterEncoding(); void visitBefore( final SAXElement element, final ExecutionContext executionContext ); void visitBefore( final Element element, final ExecutionContext executionContext ); void executeVisitLifecycleCleanup(Fragment fragment, ExecutionContext executionContext); void executeExecutionLifecycleCleanup( ExecutionContext executionContext ); static OutputStream getOutputStream(
    		final String resourceName,
            final ExecutionContext executionContext); static Writer getOutputWriter(final String resourceName, final ExecutionContext executionContext);  }### Answer:
@Test public void getOutputWriter () throws IOException { AbstractOutputStreamResource resource = new MockAbstractOutputStreamResource(); MockExecutionContext executionContext = new MockExecutionContext(); assertNull(getResource(resource, executionContext)); resource.visitBefore( (Element)null, executionContext ); assertNotNull(getResource(resource, executionContext)); Writer writer = AbstractOutputStreamResource.getOutputWriter(resource.getResourceName(), executionContext); assertNotNull( writer ); assertTrue( writer instanceof OutputStreamWriter); try { AbstractOutputStreamResource.getOutputStream( resource.getResourceName(), executionContext); fail("Expected SmooksException"); } catch(SmooksException e) { assertEquals("An Writer to the 'Mock' resource is already open. Cannot open an OutputStream to this resource now!", e.getMessage()); } resource.executeVisitLifecycleCleanup(new Fragment((Element)null), executionContext); assertNull(getResource(resource, executionContext)); assertTrue(MockAbstractOutputStreamResource.isClosed); }