Merge pull request #3589 from raksha-rao/BAEL-1540-classloader

Bael 1540 classloader
This commit is contained in:
José Carlos Valero Sánchez
2018-02-24 13:50:01 +01:00
committed by GitHub
4 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package com.baeldung.classloader;
import org.junit.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class CustomClassLoaderTest {
@Test
public void customLoader() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
CustomClassLoader customClassLoader = new CustomClassLoader();
Class<?> c = customClassLoader.getClass(PrintClassLoader.class.getName());
Object ob = c.newInstance();
Method md = c.getMethod("printClassLoaders");
md.invoke(ob);
}
}

View File

@@ -0,0 +1,14 @@
package com.baeldung.classloader;
import org.junit.Test;
import static org.junit.Assert.*;
public class PrintClassLoaderTest {
@Test(expected = ClassNotFoundException.class)
public void givenAppClassLoader_whenParentClassLoader_thenClassNotFoundException() throws Exception {
PrintClassLoader sampleClassLoader = (PrintClassLoader) Class.forName(PrintClassLoader.class.getName()).newInstance();
sampleClassLoader.printClassLoaders();
Class.forName(PrintClassLoader.class.getName(), true, PrintClassLoader.class.getClassLoader().getParent());
}
}