1 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 27 public class TestInterceptFields extends AbstractTransformTest implements InterceptFieldCallback{ 28 29 static Object TEST_VALUE = "test1"; 30 31 String field; 32 33 34 public TestInterceptFields() { 35 } 36 37 38 public TestInterceptFields(String 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 { 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 name){ 64 return true; 65 } 66 public boolean acceptWrite(Type owner, String 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 _this, String name, boolean oldValue) { 87 88 return oldValue; 89 } 90 91 public byte readByte(Object _this, String name, byte oldValue) { 92 93 return oldValue; 94 } 95 96 public char readChar(Object _this, String name, char oldValue) { 97 98 return oldValue; 99 } 100 101 public double readDouble(Object _this, String name, double oldValue) { 102 103 return oldValue; 104 } 105 106 public float readFloat(Object _this, String name, float oldValue) { 107 108 return oldValue; 109 } 110 111 public int readInt(Object _this, String name, int oldValue) { 112 113 return oldValue; 114 } 115 116 public long readLong(Object _this, String name, long oldValue) { 117 118 return oldValue; 119 } 120 121 public Object readObject(Object _this, String name, Object oldValue) { 122 123 return TEST_VALUE; 124 } 125 126 public short readShort(Object _this, String name, short oldValue) { 127 128 return oldValue; 129 } 130 131 public boolean writeBoolean(Object _this, String name, boolean oldValue, boolean newValue) { 132 133 return newValue; 134 } 135 136 public byte writeByte(Object _this, String name, byte oldValue, byte newValue) { 137 138 return newValue; 139 } 140 141 public char writeChar(Object _this, String name, char oldValue, char newValue) { 142 143 return newValue; 144 } 145 146 public double writeDouble(Object _this, String name, double oldValue, double newValue) { 147 148 return newValue; 149 } 150 151 public float writeFloat(Object _this, String name, float oldValue, float newValue) { 152 153 return newValue; 154 } 155 156 public int writeInt(Object _this, String name, int oldValue, int newValue) { 157 158 return newValue; 159 } 160 161 public long writeLong(Object _this, String name, long oldValue, long newValue) { 162 163 return newValue; 164 } 165 166 public Object writeObject(Object _this, String name, Object oldValue, Object newValue) { 167 168 return newValue; 169 } 170 171 public short writeShort(Object _this, String name, short oldValue, short newValue) { 172 173 return newValue; 174 } 175 176 177 178 179 public static void main(String [] args) throws Exception { 180 junit.textui.TestRunner.run(suite()); 181 } 182 183 public static Test suite() throws Exception { 184 return new TestSuite( new TestInterceptFields( ).transform() ); 185 } 186 187 188 } 189 | Popular Tags |