1 package org.sapia.clazzy; 2 3 import java.io.InputStream ; 4 import java.net.URL ; 5 6 import junit.framework.TestCase; 7 8 17 public class ClazzyURLStreamHandlerFactoryTest extends TestCase{ 18 19 public ClazzyURLStreamHandlerFactoryTest(String name){ 20 super(name); 21 } 22 23 public void testCreateURLStreamHandler() throws Exception { 24 ClazzyURLStreamHandlerFactory fac = new ClazzyURLStreamHandlerFactory(); 25 Handler handler = (Handler)fac.createURLStreamHandler("clazzy"); 26 } 27 28 public void testURLStreamHandlerFactoryBehavior() throws Exception { 29 System.setProperty("java.protocol.handler.pkgs", "org.sapia"); 30 URL resource = new URL ("clazzy:etc/test/lib/classes.jar?test/resource.txt"); 31 InputStream is = resource.openStream(); 32 is.close(); 33 34 ClazzyURLStreamHandlerFactory fac = new ClazzyURLStreamHandlerFactory(); 35 URL.setURLStreamHandlerFactory(fac); 36 resource = new URL ("clazzy:etc/test/lib/classes.jar?test/resource.txt"); 37 is = resource.openStream(); 38 is.close(); 39 40 CompositeClassLoader loader = CompositeClassLoaderBuilder.parseClassPath(null, new DefaultLoaderSelector(), "etc/test/lib/classes.jar"); 41 URL url = loader.getResource("test/resource.txt"); 42 super.assertTrue("Could not find resource", url != null); 43 } 44 45 } 46 | Popular Tags |