1 16 17 package net.sf.cglib.transform.impl; 18 19 import net.sf.cglib.transform.*; 20 import junit.framework.*; 21 import java.util.*; 22 import net.sf.cglib.core.*; 23 24 28 public class TestAddClassInit extends AbstractTransformTest{ 29 30 static Class registred; 31 32 static int i = 0; 33 34 static { 35 36 i = 11; 37 38 } 39 40 public static void register(Class cls){ 41 42 registred = cls; 43 44 45 } 46 47 48 public TestAddClassInit(){ } 49 50 public void testInitTransform(){ 51 assertEquals(i,11); 52 } 53 54 public void testRegistred(){ 55 56 57 assertNotNull(registred); 58 59 60 } 61 62 public TestAddClassInit(String s){ 63 super(s); 64 } 65 66 protected ClassTransformerFactory getTransformer() throws Exception { 67 68 return new ClassTransformerFactory (){ 69 70 public ClassTransformer newInstance(){ 71 try{ 72 return new AddStaticInitTransformer( 73 TestAddClassInit.class. 74 getMethod("register",new Class []{Class .class}) 75 ); 76 }catch(Exception e){ 77 throw new CodeGenerationException(e); 78 } 79 } 80 }; 81 82 } 83 84 public static void main(String [] args) throws Exception { 85 junit.textui.TestRunner.run(suite()); 86 } 87 88 public static Test suite() throws Exception { 89 return new TestSuite( new TestAddClassInit( ).transform() ); 90 } 91 92 93 } 94 | Popular Tags |