1 26 27 package net.sourceforge.groboutils.util.classes.v1.jdk0; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 34 45 public class ArrayClassLoaderUTest extends TestCase 46 { 47 private static final Class THIS_CLASS = ArrayClassLoaderUTest.class; 48 49 public ArrayClassLoaderUTest( String name ) 50 { 51 super( name ); 52 } 53 54 public static Test suite() 55 { 56 TestSuite suite = new TestSuite( THIS_CLASS ); 57 58 return suite; 59 } 60 61 public static void main( String [] args ) 62 { 63 String [] name = { THIS_CLASS.getName() }; 64 65 68 junit.textui.TestRunner.main( name ); 69 } 70 71 protected void setUp() throws Exception 72 { 73 super.setUp(); 74 75 } 77 78 79 protected void tearDown() throws Exception 80 { 81 83 super.tearDown(); 84 } 85 86 87 public void testInstantiate() 88 { 89 new ArrayClassLoader(); 90 } 91 92 private class NullBytecodeSource implements BytecodeSource 93 { 94 public byte[] getBytecode( String classname ) 95 { 96 return null; 97 } 98 } 99 100 101 public void testSetBytecodeSource() 102 { 103 ArrayClassLoader acl = new ArrayClassLoader(); 104 acl.setBytecodeSource( new NullBytecodeSource() ); 105 } 106 107 108 public void testSetBytecodeSourceNull() 109 { 110 ArrayClassLoader acl = new ArrayClassLoader(); 111 acl.setBytecodeSource( null ); } 113 114 115 public void testAddClassNull1() 116 { 117 ArrayClassLoader acl = new ArrayClassLoader(); 118 try 119 { 120 acl.addClass( null, null ); 121 } 122 catch (IllegalArgumentException iae) 123 { 124 return; 125 } 126 assertTrue( "Did not throw an IllegalArgumentException with null args.", 127 true ); 128 } 129 130 131 public void testAddClassNull2() 132 { 133 ArrayClassLoader acl = new ArrayClassLoader(); 134 try 135 { 136 acl.addClass( "SomeClass", null ); 137 } 138 catch (IllegalArgumentException iae) 139 { 140 return; 141 } 142 assertTrue( "Did not throw an IllegalArgumentException with null args.", 143 true ); 144 } 145 146 147 public void testAddClassNull3() 148 { 149 ArrayClassLoader acl = new ArrayClassLoader(); 150 try 151 { 152 acl.addClass( null, new byte[0] ); 153 } 154 catch (IllegalArgumentException iae) 155 { 156 return; 157 } 158 assertTrue( "Did not throw an IllegalArgumentException with null args.", 159 true ); 160 } 161 162 163 public void testLoadClassNull1() throws ClassNotFoundException 164 { 165 ArrayClassLoader acl = new ArrayClassLoader(); 166 try 167 { 168 acl.loadClass( null, true ); 169 fail( "Did not throw an IllegalArgumentException with null args." ); 170 } 171 catch (IllegalArgumentException iae) 172 { 173 return; 175 } 176 } 177 178 179 public void testLoadClassBad1() 180 { 181 ArrayClassLoader acl = setupLoader(); 182 try 183 { 184 acl.loadClass( BAD_CLASS, true ); 185 fail("Did not throw an Exception with a bad class."); 186 } 187 catch (ClassFormatError cfe) 188 { 189 } 191 catch (ClassNotFoundException cnfe) 192 { 193 } 195 } 196 197 198 protected static final String BAD_CLASS = "BadClass"; 199 200 protected ArrayClassLoader setupLoader() 201 { 202 ArrayClassLoader acl = new ArrayClassLoader(); 203 acl.addClass( BAD_CLASS, new byte[0] ); 204 205 return acl; 206 } 207 } 208 | Popular Tags |