1 16 package org.apache.commons.logging.pathable; 17 18 import java.net.URL ; 19 import java.net.URLClassLoader ; 20 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 24 import org.apache.commons.logging.PathableClassLoader; 25 import org.apache.commons.logging.PathableTestSuite; 26 27 30 31 public class GeneralTestCase extends TestCase { 32 33 36 public static Test suite() throws Exception { 37 Class thisClass = GeneralTestCase.class; 38 ClassLoader thisClassLoader = thisClass.getClassLoader(); 39 40 PathableClassLoader loader = new PathableClassLoader(null); 41 loader.useExplicitLoader("junit.", thisClassLoader); 42 loader.addLogicalLib("testclasses"); 43 44 Class testClass = loader.loadClass(thisClass.getName()); 46 47 return new PathableTestSuite(testClass, loader); 49 } 50 51 54 private static void checkAndSetProperties() { 55 String prop = System.getProperty("no.such.property"); 56 assertNull("no.such.property is unexpectedly defined", prop); 57 System.setProperty("no.such.property", "dummy value"); 58 prop = System.getProperty("no.such.property"); 59 assertNotNull("no.such.property is unexpectedly undefined", prop); 60 } 61 62 73 public void testResetProps1() { 74 checkAndSetProperties(); 75 } 76 77 80 public void testResetProps2() { 81 checkAndSetProperties(); 82 } 83 84 88 private static void checkAndSetContext() { 89 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); 90 assertEquals("ContextLoader is of unexpected type", 91 contextLoader.getClass().getName(), 92 PathableClassLoader.class.getName()); 93 94 URL [] noUrls = new URL [0]; 95 Thread.currentThread().setContextClassLoader(new URLClassLoader (noUrls)); 96 } 97 98 109 public void testResetContext1() { 110 checkAndSetContext(); 111 } 112 113 116 public void testResetContext2() { 117 checkAndSetContext(); 118 } 119 } 120 | Popular Tags |