1 33 34 package edu.rice.cs.util.classloader; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 38 import java.net.URL ; 39 40 45 public class StrictURLClassLoaderTest extends DrJavaTestCase { 46 50 public void testWontLoadFromSystem() throws Throwable { 51 StrictURLClassLoader loader = new StrictURLClassLoader(new URL [0]); 52 String myName = getClass().getName(); 53 54 try { 55 loader.loadClass(myName); 56 fail("should not have loaded class"); 57 } 58 catch (ClassNotFoundException e) { 59 } 61 } 62 63 64 public void testWontLoadResourceFromBootClassPath() throws Throwable { 65 StrictURLClassLoader loader = new StrictURLClassLoader(new URL [0]); 66 String compiler = "com/sun/tools/javac/util/Log.class"; 67 68 URL resource = loader.getResource(compiler); 69 assertTrue("should not have found resource", resource == null); 70 } 71 72 73 public void testWillLoadClassFromGivenURLs() throws Throwable { 74 String logResource = "com/sun/tools/javac/Main.class"; 75 String compilerClass = "com.sun.tools.javac.Main"; 76 URL [] urls = ToolsJarClassLoader.getToolsJarURLs(); 77 78 if (urls.length > 0) { 79 StrictURLClassLoader loader = new StrictURLClassLoader(urls); 81 82 Class c = loader.loadClass(compilerClass); 83 assertEquals("loaded class", compilerClass, c.getName()); 84 85 86 URL resource = loader.getResource(logResource); 87 assertTrue("resource found", resource != null); 88 } 89 } 90 } 91 | Popular Tags |