### Question:
ManagedResourceHandler implements ResourceHandler { protected boolean writeFilesToDisk( Bundle bundle, String bundleSource, File to ) { InputStream in = null; OutputStream out = null; try { Enumeration<URL> fileUrls = bundle.findEntries( bundleSource, null, true ); if ( fileUrls == null || !fileUrls.hasMoreElements() ) { return false; } while ( fileUrls.hasMoreElements() ) { URL url = fileUrls.nextElement(); Path outPath = Paths .get( to.getPath(), url.getFile().replace( BUNDLE_MANAGED_RESOURCES_DIR, "" ) ); File outFile = outPath.toFile(); String fileName = outPath.getFileName().toString(); if ( !outFile.exists() ) { if ( fileName.matches( ".+\\..+" ) ) { copyStream( url, outFile.getAbsolutePath() ); } else { outFile.mkdir(); } } } } catch ( FileNotFoundException e ) { logger.error( e.getMessage() ); return false; } catch ( IOException e ) { logger.error( e.getMessage() ); return false; } finally { try { if ( in != null ) { in.close(); } } catch ( IOException e ) { logger.error( e.getMessage() ); } try { if ( out != null ) { out.close(); } } catch ( IOException e ) { logger.error( e.getMessage() ); } } return true; }  void setManagedResourceProvider( ResourceProvider resourceProvider ); @Override boolean hasManagedResources( Bundle bundle ); @Override void handleManagedResources( Bundle blueprintBundle ); static String BUNDLE_MANAGED_RESOURCES_DIR; }### Answer:
@Test public void writeFilesToDiskTest() throws Exception { doNothing().when( resourceHandler ).copyStream( any( URL.class ), anyString() ); doReturn( true ).when( mockToFile ).mkdirs(); Enumeration<URL> mockFileUrls = mock( Enumeration.class ); doReturn( mockFileUrls ).when( bundle ).findEntries( source, null, true ); doReturn( false ).when( mockFileUrls ).hasMoreElements(); boolean result = resourceHandler.writeFilesToDisk( bundle, source, to ); assertFalse( result ); URL rootJarUrl = resourceHandler.getClass().getResource( "" ); Set<URL> urls = new HashSet<>(); urls.add( rootJarUrl ); urls.add( Paths.get( bundleSource, "test.abc" ).toUri().toURL() ); Iterator<URL> urlIterator = urls.iterator(); doAnswer( invocationOnMock -> urlIterator.hasNext() ).when( mockFileUrls ).hasMoreElements(); doAnswer( invocationOnMock -> urlIterator.next() ).when( mockFileUrls ).nextElement(); result = resourceHandler.writeFilesToDisk( bundle, source, to ); assertTrue( result ); verify( resourceHandler, times( 1 ) ).copyStream( any( URL.class ), any( String.class ) ); urls.clear(); urls.add( new URL( "file", "", fileUrl ) ); Iterator<URL> urlIterator1 = urls.iterator(); doAnswer( invocationOnMock -> urlIterator1.hasNext() ).when( mockFileUrls ).hasMoreElements(); doAnswer( invocationOnMock -> urlIterator1.next() ).when( mockFileUrls ).nextElement(); result = resourceHandler.writeFilesToDisk( bundle, source, to ); assertTrue( result ); verify( resourceHandler, times( 1 ) ).copyStream( any( URL.class ), any( String.class ) ); }