1
2 package net.sf.cglib.transform.impl;
3
4 import net.sf.cglib.transform.*;
5 import junit.framework.*;
6 import org.objectweb.asm.*;
7
8 /***
9 *
10 * @author baliuka
11 */
12 public class TestInterceptFields extends AbstractTransformTest implements InterceptFieldCallback{
13
14 static Object TEST_VALUE = "test1";
15
16 String field;
17
18 /*** Creates a new instance of TestInterceptFields */
19 public TestInterceptFields() {
20 }
21
22 /*** Creates a new instance of TestInterceptFields */
23 public TestInterceptFields(String name) {
24 super(name);
25 }
26
27
28 public void test(){
29
30
31 InterceptFieldEnabled e = (InterceptFieldEnabled)this;
32 e.setInterceptFieldCallback( this );
33 field = "test";
34 assertEquals(TEST_VALUE,field);
35
36 }
37
38 protected ClassTransformerFactory getTransformer() throws Exception {
39
40 return new ClassTransformerFactory(){
41
42 public ClassTransformer newInstance(){
43
44 return new InterceptFieldTransformer(
45
46 new InterceptFieldFilter(){
47
48 public boolean acceptRead(Type owner, String name){
49 return true;
50 }
51 public boolean acceptWrite(Type owner, String name){
52 return true;
53 }
54
55 }
56
57 );
58
59 }
60
61 };
62
63
64
65 }
66
67
68
69
70
71 public boolean readBoolean(Object _this, String name, boolean oldValue) {
72
73 return oldValue;
74 }
75
76 public byte readByte(Object _this, String name, byte oldValue) {
77
78 return oldValue;
79 }
80
81 public char readChar(Object _this, String name, char oldValue) {
82
83 return oldValue;
84 }
85
86 public double readDouble(Object _this, String name, double oldValue) {
87
88 return oldValue;
89 }
90
91 public float readFloat(Object _this, String name, float oldValue) {
92
93 return oldValue;
94 }
95
96 public int readInt(Object _this, String name, int oldValue) {
97
98 return oldValue;
99 }
100
101 public long readLong(Object _this, String name, long oldValue) {
102
103 return oldValue;
104 }
105
106 public Object readObject(Object _this, String name, Object oldValue) {
107
108 return TEST_VALUE;
109 }
110
111 public short readShort(Object _this, String name, short oldValue) {
112
113 return oldValue;
114 }
115
116 public boolean writeBoolean(Object _this, String name, boolean oldValue, boolean newValue) {
117
118 return newValue;
119 }
120
121 public byte writeByte(Object _this, String name, byte oldValue, byte newValue) {
122
123 return newValue;
124 }
125
126 public char writeChar(Object _this, String name, char oldValue, char newValue) {
127
128 return newValue;
129 }
130
131 public double writeDouble(Object _this, String name, double oldValue, double newValue) {
132
133 return newValue;
134 }
135
136 public float writeFloat(Object _this, String name, float oldValue, float newValue) {
137
138 return newValue;
139 }
140
141 public int writeInt(Object _this, String name, int oldValue, int newValue) {
142
143 return newValue;
144 }
145
146 public long writeLong(Object _this, String name, long oldValue, long newValue) {
147
148 return newValue;
149 }
150
151 public Object writeObject(Object _this, String name, Object oldValue, Object newValue) {
152
153 return newValue;
154 }
155
156 public short writeShort(Object _this, String name, short oldValue, short newValue) {
157
158 return newValue;
159 }
160
161
162
163
164 public static void main(String[] args) throws Exception{
165 junit.textui.TestRunner.run(suite());
166 }
167
168 public static Test suite() throws Exception{
169 return new TestSuite( new TestInterceptFields( ).transform() );
170 }
171
172
173 }
This page was automatically generated by Maven