### Question:
PluginMetadataImpl implements PluginMetadata { @Override public void writeBlueprint( String name, OutputStream outputStream ) throws IOException { if ( runAtEndables.size() > 0 ) { ExecutorService executorService = Executors.newSingleThreadExecutor(); runAtEndables.forEach( executorService::submit ); } Result output = new StreamResult( outputStream ); Document blueprint = getBlueprint(); Element bean = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "bean" ); bean.setAttribute( "class", "org.pentaho.platform.pdi.BundleClassloader" ); bean.setAttribute( "id", "classLoader" ); Element argument = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "argument" ); argument.setAttribute( "ref", "blueprintBundle" ); bean.appendChild( argument ); argument = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "argument" ); argument.setAttribute( "value", manifestUpdater.getBundleSymbolicName() ); bean.appendChild( argument ); blueprint.getDocumentElement().appendChild( bean ); Element service = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "service" ); service.setAttribute( "interface", "java.lang.ClassLoader" ); service.setAttribute( "ref", "classLoader" ); Element props = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "service-properties" ); Element entry = blueprint.createElementNS( BLUEPRINT_BEAN_NS, "entry" ); entry.setAttribute( "key", "plugin-id" ); entry.setAttribute( "value", manifestUpdater.getBundleSymbolicName() ); props.appendChild( entry ); service.appendChild( props ); blueprint.getDocumentElement().appendChild( service ); Source input = new DOMSource( blueprint ); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty( OutputKeys.INDENT, "yes" ); transformer.setOutputProperty( "{http: transformer.transform( input, output ); } catch ( TransformerException e ) { throw new IOException( e ); } } PluginMetadataImpl( File rootDirectory ); @Override ManifestUpdater getManifestUpdater(); @Override Document getBlueprint(); @Override void setBlueprint( Document blueprint ); @Override void writeBlueprint( String name, OutputStream outputStream ); @Override FileWriter getFileWriter( String path ); @Override OutputStream getFileOutputStream( String path ); @Override void addContentType( String contentType ); @Override List<String> getContentTypes(); @Override void executeAtEnd( Runnable runnable );  }### Answer:
@Test public void testWriteBluePrint() throws ParserConfigurationException, IOException { PluginMetadataImpl pluginMetadata = new PluginMetadataImpl( new File( "." ) ); Document blueprint = pluginMetadata.getBlueprint(); Node testNode = blueprint.createElementNS( "http: blueprint.getElementsByTagNameNS( PluginXmlStaticPathsHandler.BLUEPRINT_BEAN_NS, "blueprint" ).item( 0 ) .appendChild( testNode ); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); pluginMetadata.writeBlueprint( "test", byteArrayOutputStream ); assertTrue( byteArrayOutputStream.toString( "UTF-8" ).contains( "<test xmlns=\"http: }
@Test(expected = IOException.class) public void testWriteException() throws ParserConfigurationException, IOException { PluginMetadataImpl pluginMetadata = new PluginMetadataImpl( new File( "." ) ); OutputStream outputStream = mock( OutputStream.class ); doThrow( new IOException() ).when( outputStream ).write( any( byte[].class ) ); doThrow( new IOException() ).when( outputStream ).write( any( byte.class ) ); doThrow( new IOException() ).when( outputStream ).write( any( byte[].class ), anyInt(), anyInt() ); pluginMetadata.writeBlueprint( "test", outputStream ); }