### Question:
ClassLoaderUtils { public static ClassLoader getCustomClassLoader(String modulePath, ClassLoader parentClassLoader, FilenameFilter filenameFilter) throws MalformedURLException { URL[] classpaths = getURLsForClasspath(modulePath, filenameFilter, false); return createModuleClassLoader(classpaths, parentClassLoader); }  static ClassLoader getCustomClassLoader(String modulePath, ClassLoader parentClassLoader, FilenameFilter filenameFilter); static URL[] getURLsForClasspath(String modulePath, FilenameFilter filenameFilter, boolean suppressExceptions); static URL[] getURLsForClasspath(Set<String> modulePaths, FilenameFilter filenameFilter, boolean suppressExceptions);  }### Answer:
@Test public void testGetCustomClassLoader() throws MalformedURLException,ClassNotFoundException{ final String jarFilePath = "src/test/resources/TestClassLoaderUtils"; ClassLoader customClassLoader = ClassLoaderUtils.getCustomClassLoader(jarFilePath ,this.getClass().getClassLoader(), getJarFilenameFilter()); assertTrue(customClassLoader != null); assertTrue(customClassLoader.loadClass("TestSuccess") != null); }
@Test public void testGetCustomClassLoaderNoPathSpecified() throws MalformedURLException{ final ClassLoader originalClassLoader = this.getClass().getClassLoader(); ClassLoader customClassLoader = ClassLoaderUtils.getCustomClassLoader(null,originalClassLoader, getJarFilenameFilter()); assertTrue(customClassLoader != null); try{ customClassLoader.loadClass("TestSuccess"); }catch (ClassNotFoundException cex){ assertTrue(cex.getLocalizedMessage().equals("TestSuccess")); return; } fail("exception did not occur, class should not be found"); }
@Test public void testGetCustomClassLoaderWithInvalidPath() { final String jarFilePath = "src/test/resources/FakeTestClassLoaderUtils/TestSuccess.jar"; try { ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter()); }catch(MalformedURLException mex){ assertTrue(mex.getLocalizedMessage().equals("Path specified does not exist")); return; } fail("exception did not occur, path should not exist"); }
@Test public void testGetCustomClassLoaderWithMultipleLocations() throws Exception { final String jarFilePath = " src/test/resources/TestClassLoaderUtils/TestSuccess.jar, http: assertNotNull(ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter())); }
@Test public void testGetCustomClassLoaderWithEmptyLocations() throws Exception { String jarFilePath = ""; assertNotNull(ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter())); jarFilePath = ","; assertNotNull(ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter())); jarFilePath = ",src/test/resources/TestClassLoaderUtils/TestSuccess.jar, "; assertNotNull(ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter())); }