KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.asm.*;
22
23 /**
24  *
25  * @author baliuka
26  */

27 public class TestInterceptFields extends AbstractTransformTest implements InterceptFieldCallback{
28
29     static Object JavaDoc TEST_VALUE = "test1";
30     
31     String JavaDoc field;
32     
33     /** Creates a new instance of TestInterceptFields */
34     public TestInterceptFields() {
35     }
36     
37     /** Creates a new instance of TestInterceptFields */
38     public TestInterceptFields(String JavaDoc name) {
39         super(name);
40     }
41     
42     
43     public void test(){
44         
45         
46         InterceptFieldEnabled e = (InterceptFieldEnabled)this;
47         e.setInterceptFieldCallback( this );
48         field = "test";
49         assertEquals(TEST_VALUE,field);
50         
51     }
52     
53     protected ClassTransformerFactory getTransformer() throws Exception JavaDoc {
54         
55         return new ClassTransformerFactory(){
56             
57             public ClassTransformer newInstance(){
58                 
59                 return new InterceptFieldTransformer(
60                 
61                 new InterceptFieldFilter(){
62                     
63                     public boolean acceptRead(Type owner, String JavaDoc name){
64                         return true;
65                     }
66                     public boolean acceptWrite(Type owner, String JavaDoc name){
67                         return true;
68                     }
69                     
70                 }
71                 
72                 );
73                 
74             }
75             
76         };
77         
78         
79         
80     }
81     
82     
83     
84     
85     
86     public boolean readBoolean(Object JavaDoc _this, String JavaDoc name, boolean oldValue) {
87         
88         return oldValue;
89     }
90     
91     public byte readByte(Object JavaDoc _this, String JavaDoc name, byte oldValue) {
92         
93         return oldValue;
94     }
95     
96     public char readChar(Object JavaDoc _this, String JavaDoc name, char oldValue) {
97         
98         return oldValue;
99     }
100     
101     public double readDouble(Object JavaDoc _this, String JavaDoc name, double oldValue) {
102         
103         return oldValue;
104     }
105     
106     public float readFloat(Object JavaDoc _this, String JavaDoc name, float oldValue) {
107         
108         return oldValue;
109     }
110     
111     public int readInt(Object JavaDoc _this, String JavaDoc name, int oldValue) {
112         
113         return oldValue;
114     }
115     
116     public long readLong(Object JavaDoc _this, String JavaDoc name, long oldValue) {
117         
118         return oldValue;
119     }
120     
121     public Object JavaDoc readObject(Object JavaDoc _this, String JavaDoc name, Object JavaDoc oldValue) {
122         
123        return TEST_VALUE;
124     }
125     
126     public short readShort(Object JavaDoc _this, String JavaDoc name, short oldValue) {
127         
128         return oldValue;
129     }
130     
131     public boolean writeBoolean(Object JavaDoc _this, String JavaDoc name, boolean oldValue, boolean newValue) {
132         
133         return newValue;
134     }
135     
136     public byte writeByte(Object JavaDoc _this, String JavaDoc name, byte oldValue, byte newValue) {
137         
138         return newValue;
139     }
140     
141     public char writeChar(Object JavaDoc _this, String JavaDoc name, char oldValue, char newValue) {
142         
143         return newValue;
144     }
145     
146     public double writeDouble(Object JavaDoc _this, String JavaDoc name, double oldValue, double newValue) {
147         
148         return newValue;
149     }
150     
151     public float writeFloat(Object JavaDoc _this, String JavaDoc name, float oldValue, float newValue) {
152         
153         return newValue;
154     }
155     
156     public int writeInt(Object JavaDoc _this, String JavaDoc name, int oldValue, int newValue) {
157         
158         return newValue;
159     }
160     
161     public long writeLong(Object JavaDoc _this, String JavaDoc name, long oldValue, long newValue) {
162         
163         return newValue;
164     }
165     
166     public Object JavaDoc writeObject(Object JavaDoc _this, String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue) {
167         
168         return newValue;
169     }
170     
171     public short writeShort(Object JavaDoc _this, String JavaDoc name, short oldValue, short newValue) {
172         
173         return newValue;
174     }
175     
176     
177     
178     
179     public static void main(String JavaDoc[] args) throws Exception JavaDoc{
180         junit.textui.TestRunner.run(suite());
181     }
182     
183     public static Test suite() throws Exception JavaDoc{
184         return new TestSuite( new TestInterceptFields( ).transform() );
185     }
186     
187     
188 }
189
Popular Tags