### Question:
PluginLibraryFileHandler implements PluginFileHandler { @Override public boolean handle( String relativePath, byte[] file, PluginMetadata pluginMetadata ) throws PluginHandlingException { try ( ByteArrayInputStream fin = new ByteArrayInputStream( file ); JarInputStream jarInputStream = new JarInputStream( fin ); ) { Object bundleSymbolicName = jarInputStream.getManifest().getMainAttributes().getValue( "Bundle-SymbolicName" ); if ( bundleSymbolicName != null ) { log.info( String.format( "Jar identified as an OSGi bundle [%s]; no auto-deploy. Assumed to be provided by the container.", bundleSymbolicName.toString() ) ); return false; } ZipEntry nextEntry; while ( ( nextEntry = jarInputStream.getNextEntry() ) != null ) { if ( nextEntry.isDirectory() ) { continue; } String name = nextEntry.getName(); try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( (int) Math.min( Integer.MAX_VALUE, Math.max( 0, nextEntry.getSize() ) ) ) ) { ByteStreams.copy( jarInputStream, byteArrayOutputStream ); if ( name.matches( ".+\\.xml" ) ) { String contents = byteArrayOutputStream.toString( "UTF-8" ); if ( contents.contains( "http: FileWriter fileWriter = pluginMetadata.getFileWriter( "META-INF/spring/" + name ); fileWriter.append( contents ); fileWriter.close(); } } else { OutputStream fileOut = pluginMetadata.getFileOutputStream( nextEntry.getName() ); fileOut.write( byteArrayOutputStream.toByteArray() ); fileOut.close(); } } } } catch ( IOException e ) { e.printStackTrace(); } return false; }  @Override boolean handles( String fileName ); @Override boolean handle( String relativePath, byte[] file, PluginMetadata pluginMetadata ); static final Pattern LIB_PATTERN; static final String JAR; static final String LIB; }### Answer:
@Test public void testHandle_shouldSkipProcessingOfOsgiBundleJar() throws Exception { File f = new File( testResources, "org/pentaho/osgi/platform/plugin/deployer/impl/handlers/test-dummy-bundle.jar" ); pluginLibraryFileHandler.handle( "", IOUtils.toByteArray( new FileInputStream( f ) ), pluginMetadata ); verify( pluginMetadata, never() ).getFileOutputStream( anyString() ); verify( pluginMetadata, never() ).getFileWriter( anyString() ); }
@Test public void testHandle() throws Exception { File f = new File( testResources, "org/pentaho/osgi/platform/plugin/deployer/impl/handlers/test-dummy.jar" ); when( pluginMetadata.getFileOutputStream( anyString() ) ).thenReturn( outputStream ); when( pluginMetadata.getFileWriter( anyString() ) ).thenReturn( fileWriter ); pluginLibraryFileHandler.handle( "", IOUtils.toByteArray( new FileInputStream( f ) ), pluginMetadata ); verify( pluginMetadata ).getFileOutputStream( "org/pentaho/App.class" ); verify( pluginMetadata ).getFileWriter( "META-INF/spring/beans.xml" ); verify( outputStream, times( 2 ) ).write( any() ); verify( outputStream, times( 2 ) ).close(); verify( fileWriter ).append( anyString() ); verify( fileWriter ).close(); }