]> source.dussan.org Git - aspectj.git/commitdiff
216311: testcode
authoraclement <aclement>
Wed, 20 Feb 2008 19:58:49 +0000 (19:58 +0000)
committeraclement <aclement>
Wed, 20 Feb 2008 19:58:49 +0000 (19:58 +0000)
tests/bugs160/pr216311/IPersistable.java [new file with mode: 0644]
tests/bugs160/pr216311/Persistability.java [new file with mode: 0644]
tests/bugs160/pr216311/PersistabilityTest.java [new file with mode: 0644]

diff --git a/tests/bugs160/pr216311/IPersistable.java b/tests/bugs160/pr216311/IPersistable.java
new file mode 100644 (file)
index 0000000..82bc633
--- /dev/null
@@ -0,0 +1,9 @@
+import java.io.Serializable;\r
+\r
+public interface IPersistable extends Serializable {\r
+\r
+    int getId();\r
+\r
+    void setId(int id);\r
+\r
+}\r
diff --git a/tests/bugs160/pr216311/Persistability.java b/tests/bugs160/pr216311/Persistability.java
new file mode 100644 (file)
index 0000000..4bd76ae
--- /dev/null
@@ -0,0 +1,44 @@
+\r
+\r
+import org.aspectj.lang.annotation.Aspect;\r
+import org.aspectj.lang.annotation.Before;\r
+import org.aspectj.lang.annotation.DeclareParents;\r
+import org.aspectj.lang.annotation.Pointcut;\r
+\r
+\r
+@Aspect\r
+public class Persistability {\r
+\r
+    static class Persistable implements IPersistable {\r
+\r
+        private static final long serialVersionUID = 7120491865883787353L;\r
+\r
+        private int id;\r
+\r
+        public Persistable() {\r
+            super();\r
+        }\r
+\r
+        public int getId() {\r
+            return id;\r
+        }\r
+\r
+        public void setId(int id) {\r
+            this.id = id;\r
+        }\r
+\r
+    }\r
+\r
+    @DeclareParents(value = "PersistabilityTest", defaultImpl = Persistable.class)\r
+    private IPersistable observable;\r
+\r
+    @Pointcut("initialization(IPersistable.new(..)) && this(bean) && !this(Persistable)")\r
+    void init(IPersistable bean) {\r
+    }\r
+\r
+    @Before("init(bean)")\r
+    public void beforeInit(IPersistable bean) {\r
+        bean.setId(System.identityHashCode(bean));\r
+    }\r
+\r
+}\r
diff --git a/tests/bugs160/pr216311/PersistabilityTest.java b/tests/bugs160/pr216311/PersistabilityTest.java
new file mode 100644 (file)
index 0000000..a977c9a
--- /dev/null
@@ -0,0 +1,29 @@
+\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.ObjectInputStream;\r
+import java.io.ObjectOutputStream;\r
+\r
+public class PersistabilityTest {\r
+\r
+  public static void main(String []argv) throws Exception {\r
+\r
+        PersistabilityTest persistabilityTest1 = new PersistabilityTest();\r
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+        ObjectOutputStream oos = new ObjectOutputStream(bos);\r
+\r
+        oos.writeObject(persistabilityTest1);\r
+\r
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());\r
+        ObjectInputStream ois = new ObjectInputStream(bis);\r
+\r
+        PersistabilityTest persistabilityTest2 = (PersistabilityTest) ois.readObject();\r
+\r
+        if (!(persistabilityTest1 instanceof IPersistable)) throw new RuntimeException("pTest1 not IPersistable");\r
+        if (!(persistabilityTest2 instanceof IPersistable)) throw new RuntimeException("pTest2 not IPersistable");\r
+        int o = ((IPersistable)persistabilityTest1).getId();\r
+        int o2 = ((IPersistable)persistabilityTest2).getId();\r
+        if (o!=o2) throw new RuntimeException(o+" != "+o2);\r
+    }\r
+}\r