1 26 27 package net.sourceforge.groboutils.util.classes.v1; 28 29 import net.sourceforge.groboutils.junit.v1.iftc.*; 30 import junit.framework.Test; 31 import junit.framework.TestCase; 32 import junit.framework.TestSuite; 33 34 import java.net.URL ; 35 36 37 44 public class IUrlClassLoaderUTestI extends InterfaceTestCase 45 { 46 private static final Class THIS_CLASS = IUrlClassLoaderUTestI.class; 47 48 public IUrlClassLoaderUTestI( String name, ImplFactory f ) 49 { 50 super( name, IUrlClassLoader.class, f ); 51 } 52 53 54 public IUrlClassLoader createLoader() 55 { 56 return (IUrlClassLoader)createImplObject(); 57 } 58 59 60 public static InterfaceTestSuite suite() 61 { 62 InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS ); 63 64 return suite; 65 } 66 67 69 protected void setUp() throws Exception 70 { 71 super.setUp(); 72 73 } 75 76 77 protected void tearDown() throws Exception 78 { 79 81 super.tearDown(); 82 } 83 84 85 public void testInstantiate() 86 { 87 assertNotNull( "Creation should not return null.", 88 createLoader() ); 89 } 90 91 92 93 94 public static class MyInner 95 { 96 } 98 public static final String MY_INNER_RES = 99 "IUrlClassLoaderUTestI$MyInner.class"; 100 public static final String MY_INNER_CLASS = MyInner.class.getName(); 101 public static final String MY_INNER_FULL_RES = 102 '/' + MY_INNER_CLASS.replace( '.', '/' ) + ".class"; 103 104 public static class InnerClass 105 { 106 public InnerClass() 107 { 108 } 110 } 111 112 113 public static final String BELIEF_CLASS = "BeliefOfTheDay"; 114 115 116 public void testGetClass1() 117 { 118 IUrlClassLoader loader = createLoader(); 119 120 Class c = loader.loadClass( MY_INNER_CLASS, null ); 121 assertNotNull( "loadClass( "+MY_INNER_CLASS+ 122 " ) returned null.", 123 c ); 124 assertEquals( "Did not load the class from the default classloader.", 125 MyInner.class, c ); 126 } 127 128 129 public void testGetClass2() 130 { 131 IUrlClassLoader loader = createLoader(); 132 133 Class c = loader.loadClass( BELIEF_CLASS, null ); 134 assertEquals( 135 "getClass( Belief ) was found in the default classloader.", 136 null, c ); 137 } 138 139 140 public void testGetClass3() 141 { 142 IUrlClassLoader loader = createLoader(); 143 144 URL url = this.getClass().getResource( MY_INNER_RES ); 145 assertNotNull( "Did not find resource for inner class "+ 146 MY_INNER_RES, url ); 147 System.out.println("Found class in URL "+url); 148 String urlStr = url.toString(); 149 if (urlStr.endsWith( MY_INNER_FULL_RES )) 150 { 151 urlStr = urlStr.substring( 0, urlStr.length() - 152 MY_INNER_FULL_RES.length() ); 153 } 154 155 Class c = loader.loadClass( MY_INNER_CLASS, urlStr ); 156 assertNotNull( "getClass( "+MY_INNER_CLASS+" ) returned null.", c ); 157 assertEquals( "getClass( "+MY_INNER_CLASS+" ) returned the wrong class.", 158 MY_INNER_CLASS, c.getName() ); 159 } 160 161 162 public void testFlush1() 163 { 164 IUrlClassLoader loader = createLoader(); 165 166 Class c = loader.loadClass( this.getClass().getName(), null ); 167 loader.flush(); 168 169 } 172 173 } 174 | Popular Tags |