1 26 27 package net.sourceforge.groboutils.util.classes.v1.jdk0; 28 29 import net.sourceforge.groboutils.util.classes.v1.*; 30 import net.sourceforge.groboutils.junit.v1.iftc.*; 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 35 36 47 public class UrlClassLoaderOnlineUTest extends TestCase 48 { 49 private static final Class THIS_CLASS = UrlClassLoaderOnlineUTest.class; 50 51 public static final String BELIEF_CLASS = 52 IUrlClassLoaderOnlineUTestI.BELIEF_CLASS; 53 public static final String BELIEF_JAR = 54 IUrlClassLoaderOnlineUTestI.BELIEF_JAR; 55 56 public UrlClassLoaderOnlineUTest( String name ) 57 { 58 super( name ); 59 } 60 61 public static Test suite() 62 { 63 InterfaceTestSuite suite = IUrlClassLoaderOnlineUTestI.suite(); 64 suite.addTestSuite( THIS_CLASS ); 65 suite.addFactory( new CxFactory( "A" ) { 66 public Object createImplObject() { 67 return createLoader(); 68 } 69 } ); 70 71 return suite; 72 } 73 74 public static void main( String [] args ) 75 { 76 String [] name = { THIS_CLASS.getName() }; 77 78 81 junit.textui.TestRunner.main( name ); 82 } 83 84 protected void setUp() throws Exception 85 { 86 super.setUp(); 87 88 } 90 91 92 protected void tearDown() throws Exception 93 { 94 96 super.tearDown(); 97 } 98 99 100 protected static UrlClassLoader createLoader() 101 { 102 return new UrlClassLoader(); 103 } 104 105 106 public void testFlush1() 107 { 108 111 UrlClassLoader loader = createLoader(); 112 113 Class c = loader.loadClass( BELIEF_CLASS, BELIEF_JAR ); 115 assertNotNull( "loadClass( "+BELIEF_CLASS+ 116 " ) returned null.", c ); 117 assertEquals( "loadClass( "+BELIEF_CLASS+ 118 " ) returned the wrong class.", 119 BELIEF_CLASS, c.getName() ); 120 121 byte b[] = loader.getBytecode( BELIEF_CLASS ); 124 assertNotNull( "getBytecode( "+BELIEF_CLASS+" ) returned null.", b ); 125 assertTrue( "getBytecode( "+BELIEF_CLASS+" ) returned no data.", 126 b.length > 0 ); 127 128 loader.flush(); 129 130 b = loader.getBytecode( BELIEF_CLASS ); 132 assertEquals( "getBytecode( "+BELIEF_CLASS+" ) did not return null.", 133 null, b ); 134 } 135 136 public void testGetBytecode1() 137 { 138 UrlClassLoader loader = (UrlClassLoader)createLoader(); 139 140 Class c = null; 142 for (int i = 0; i < 3 && c == null; ++i) 144 { 145 c = loader.loadClass( BELIEF_CLASS, BELIEF_JAR ); 146 } 147 assertNotNull( "loadClass( "+BELIEF_CLASS+ 148 " ) returned null 3 times.", c ); 149 assertEquals( "loadClass( "+BELIEF_CLASS+ 150 " ) returned the wrong class.", 151 BELIEF_CLASS, c.getName() ); 152 153 byte b[] = loader.getBytecode( BELIEF_CLASS ); 156 assertNotNull( "getBytecode( "+BELIEF_CLASS+" ) returned null.", b ); 157 assertTrue( "getBytecode( "+BELIEF_CLASS+" ) returned no data.", 158 b.length > 0 ); 159 } 160 } 161 | Popular Tags |