KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > transform > impl > TestAddClassInit


1 /*
2  * Copyright 2003 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
25  *
26  * @author baliuka
27  */

28 public class TestAddClassInit extends AbstractTransformTest{
29     
30    static Class JavaDoc registred;
31    
32    static int i = 0;
33    
34    static {
35     
36        i = 11;
37    
38    }
39     
40    public static void register(Class JavaDoc 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 JavaDoc s){
63        super(s);
64     }
65     
66     protected ClassTransformerFactory getTransformer() throws Exception JavaDoc{
67         
68        return new ClassTransformerFactory (){
69         
70            public ClassTransformer newInstance(){
71              try{
72                return new AddStaticInitTransformer(
73                  TestAddClassInit.class.
74                         getMethod("register",new Class JavaDoc[]{Class JavaDoc.class})
75                );
76              }catch(Exception JavaDoc e){
77                throw new CodeGenerationException(e);
78              }
79         }
80        };
81         
82     }
83     
84     public static void main(String JavaDoc[] args) throws Exception JavaDoc{
85         junit.textui.TestRunner.run(suite());
86     }
87     
88     public static Test suite() throws Exception JavaDoc{
89         return new TestSuite( new TestAddClassInit( ).transform() );
90     }
91     
92     
93 }
94
Popular Tags