KickJava   Java API By Example, From Geeks To Geeks.

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


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 package net.sf.cglib.transform.impl;
17
18 import net.sf.cglib.transform.*;
19 import junit.framework.*;
20 /**
21  *
22  * @author baliuka
23  */

24 public class TestAddDelegate extends AbstractTransformTest {
25     
26     /** Creates a new instance of TestAddDelegate */
27     public TestAddDelegate(String JavaDoc name) {
28         super(name);
29     }
30     
31     public interface Interface {
32     
33         Object JavaDoc getDelegte();
34         
35         Object JavaDoc getTarget();
36     
37     }
38     
39     public void test(){
40         
41      Interface i = (Interface)this;
42      assertEquals(i.getTarget(),this);
43      
44     }
45     
46     public static class ImplExclude implements Interface {
47     
48         private Object JavaDoc target;
49         
50         public ImplExclude(Object JavaDoc target){
51           this.target = target;
52         }
53         
54         public Object JavaDoc getDelegte() {
55           return this;
56         }
57     
58         public Object JavaDoc getTarget(){
59            return target;
60         }
61     }
62     
63     public TestAddDelegate() {
64         super(null);
65     }
66     
67     
68     protected ClassTransformerFactory getTransformer() throws Exception JavaDoc {
69
70         return new ClassTransformerFactory(){
71         
72                public ClassTransformer newInstance(){
73           
74                    return new AddDelegateTransformer(new Class JavaDoc[]{Interface.class} , ImplExclude.class );
75                    
76                }
77         
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         
90         return new TestSuite( new TestAddDelegate().transform() );
91         
92     }
93     
94 }
95
Popular Tags