aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornickl- <github@jigsoft.co.za>2017-11-10 19:13:01 +0200
committernickl- <github@jigsoft.co.za>2017-11-12 23:54:32 +0200
commitf4ce4aa16c768acebdafb288aeb097c22eee7bb7 (patch)
tree0f9b85d7a5593fe6c209d9393d5b9c07e0da0e1d
parente1f0bba5de4dc03a9debfab333683f07cfbcb594 (diff)
downloadjavassist-f4ce4aa16c768acebdafb288aeb097c22eee7bb7.tar.gz
javassist-f4ce4aa16c768acebdafb288aeb097c22eee7bb7.zip
Unit Test: CtField.make referencing 'this'.
As per question raised in #161 passing 'this' reference for CtField value new object instance. Also added assert for testing referncing 'this' for newly added field.
-rw-r--r--src/test/javassist/JvstTest.java8
-rw-r--r--src/test/test1/FieldInit.java7
2 files changed, 15 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java
index c6825fd0..d28c0654 100644
--- a/src/test/javassist/JvstTest.java
+++ b/src/test/javassist/JvstTest.java
@@ -103,6 +103,10 @@ public class JvstTest extends JvstTestRoot {
cc.addField(f2);
CtField f3 = CtField.make("public int f3;", cc);
cc.addField(f3);
+ CtField f4 = CtField.make("public int f4 = this.f2 + 3;", cc);
+ cc.addField(f4);
+ CtField fi = CtField.make("public test1.FieldInit.FI fi = new test1.FieldInit.FI(this);", cc);
+ cc.addField(fi);
testFieldInitHash = f1.hashCode();
cc.writeFile();
Object obj = make(cc.getName());
@@ -112,6 +116,10 @@ public class JvstTest extends JvstTestRoot {
assertEquals(3, value2);
int value3 = obj.getClass().getField("f3").getInt(obj);
assertEquals(0, value3);
+ int value4 = obj.getClass().getField("f4").getInt(obj);
+ assertEquals(6, value4);
+ Object obfi = obj.getClass().getField("fi").get(obj);
+ assertTrue(obfi.getClass().getField("fi").get(obfi) == obj);
}
/* test CodeIterator.insertExGap().
diff --git a/src/test/test1/FieldInit.java b/src/test/test1/FieldInit.java
index 87f5a3bc..ee483149 100644
--- a/src/test/test1/FieldInit.java
+++ b/src/test/test1/FieldInit.java
@@ -14,4 +14,11 @@ public class FieldInit {
--loop;
} while (loop > 0);
}
+
+ public static class FI {
+ public FieldInit fi;
+ public FI(FieldInit fi) {
+ this.fi = fi;
+ }
+ }
}