Search in sources :

Example 1 with JavaDynamicClassLoader

use of alice.util.JavaDynamicClassLoader in project narchy by automenta.

the class JavaDynamicClassLoaderTestCase method InvalidPathTest.

@Test
public void InvalidPathTest() throws ClassNotFoundException, IOException {
    assertThrows(ClassNotFoundException.class, () -> {
        JavaDynamicClassLoader loader = null;
        URL url = new File(".").toURI().toURL();
        loader = new JavaDynamicClassLoader(new URL[] { url }, this.getClass().getClassLoader());
        loader.loadClass("Counter");
    });
}
Also used : File(java.io.File) URL(java.net.URL) JavaDynamicClassLoader(alice.util.JavaDynamicClassLoader) Test(org.junit.jupiter.api.Test)

Example 2 with JavaDynamicClassLoader

use of alice.util.JavaDynamicClassLoader in project narchy by automenta.

the class JavaDynamicClassLoaderTestCase method ConstructorTest.

@Test
public void ConstructorTest() throws IOException, ClassNotFoundException {
    JavaDynamicClassLoader loader = new JavaDynamicClassLoader();
    assertNotNull(loader);
    setPath(true);
    URL[] urls = getURLsFromStringArray(paths);
    loader = new JavaDynamicClassLoader(urls, this.getClass().getClassLoader());
    assertEquals(2, loader.getURLs().length);
}
Also used : URL(java.net.URL) JavaDynamicClassLoader(alice.util.JavaDynamicClassLoader) Test(org.junit.jupiter.api.Test)

Example 3 with JavaDynamicClassLoader

use of alice.util.JavaDynamicClassLoader in project narchy by automenta.

the class JavaDynamicClassLoaderTestCase method LoadClassTest.

@Disabled
@Test
public void LoadClassTest() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
    JavaDynamicClassLoader loader = null;
    setPath(true);
    URL[] urls = getURLsFromStringArray(paths);
    loader = new JavaDynamicClassLoader(urls, this.getClass().getClassLoader());
    assertEquals(2, loader.getURLs().length);
    Class<?> cl = loader.loadClass("Counter");
    assertNotNull(cl);
    Method m = cl.getMethod("inc");
    m.setAccessible(true);
    Object obj = cl.newInstance();
    m.invoke(obj);
    Method m1 = cl.getMethod("getValue");
    m1.setAccessible(true);
    Object res_obj = m1.invoke(obj);
    int res = new Integer(res_obj.toString());
    assertEquals(1, res);
}
Also used : Method(java.lang.reflect.Method) URL(java.net.URL) JavaDynamicClassLoader(alice.util.JavaDynamicClassLoader) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with JavaDynamicClassLoader

use of alice.util.JavaDynamicClassLoader in project narchy by automenta.

the class JavaDynamicClassLoaderTestCase method LoadClassNotFoundTest.

@Test
public void LoadClassNotFoundTest() throws ClassNotFoundException, IOException {
    assertThrows(ClassNotFoundException.class, () -> {
        JavaDynamicClassLoader loader = null;
        setPath(true);
        URL[] urls = getURLsFromStringArray(paths);
        loader = new JavaDynamicClassLoader(urls, this.getClass().getClassLoader());
        loader.loadClass("ClassNotFound");
    });
}
Also used : URL(java.net.URL) JavaDynamicClassLoader(alice.util.JavaDynamicClassLoader) Test(org.junit.jupiter.api.Test)

Example 5 with JavaDynamicClassLoader

use of alice.util.JavaDynamicClassLoader in project narchy by automenta.

the class JavaDynamicClassLoaderTestCase method URLHandling.

@Disabled
@Test
public void URLHandling() throws ClassNotFoundException, IOException {
    JavaDynamicClassLoader loader = null;
    URL url = new File(".").toURI().toURL();
    loader = new JavaDynamicClassLoader(new URL[] { url }, this.getClass().getClassLoader());
    assertEquals(1, loader.getURLs().length);
    loader.removeURL(url);
    assertEquals(0, loader.getURLs().length);
    setPath(true);
    loader.addURLs(getURLsFromStringArray(paths));
    assertEquals(2, loader.getURLs().length);
    loader.loadClass("Counter");
    assertEquals(1, loader.getLoadedClasses().length);
}
Also used : File(java.io.File) URL(java.net.URL) JavaDynamicClassLoader(alice.util.JavaDynamicClassLoader) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

JavaDynamicClassLoader (alice.util.JavaDynamicClassLoader)6 URL (java.net.URL)6 Test (org.junit.jupiter.api.Test)6 File (java.io.File)3 Disabled (org.junit.jupiter.api.Disabled)2 Method (java.lang.reflect.Method)1