### Question:
ClasspathHelper { static Set<String> fullClasspathFor( ClassLoader classLoader ) { Set<String> result = new LinkedHashSet<>(); result.addAll( javaClasspath() ); ClassLoader loader = classLoader; while ( loader != null ) { if ( loader instanceof URLClassLoader ) { for ( URL url : ((URLClassLoader) loader).getURLs() ) { result.add( canonicalPath( url ) ); } } loader = loader.getParent(); } return result; } private  ClasspathHelper();   }### Answer:
@Test public void shouldNotFailForNullClassLoader() { assertThat( fullClasspathFor( null ), not( empty() ) ); }
@Test public void shouldWorkForClassLoaderWithNoParent() throws Exception { ClassLoader loader = new URLClassLoader( urls( "file: Set<String> elements = fullClasspathFor( loader ); assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ) ) ); }
@Test public void shouldWorkForClassLoaderWithSingleParent() throws Exception { ClassLoader parent = new URLClassLoader( urls( "file: ClassLoader child = new URLClassLoader( urls( "file: Set<String> elements = fullClasspathFor( child ); assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ), pathTo( "file3" ) ) ); }
@Test public void shouldWorkForClassLoaderHierarchy() throws Exception { ClassLoader loader1 = new URLClassLoader( urls( "file: ClassLoader loader2 = new URLClassLoader( urls( "file: ClassLoader loader3 = new URLClassLoader( urls( "file: ClassLoader loader4 = new URLClassLoader( urls( "file: Set<String> elements = fullClasspathFor( loader4 ); assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ), pathTo( "file3" ), pathTo( "file4" ) ) ); }