From: aclement Date: Wed, 20 Feb 2008 19:58:49 +0000 (+0000) Subject: 216311: testcode X-Git-Tag: V1_6_0M2~51 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c75c9f9937291849957802ec14c5c565a776c859;p=aspectj.git 216311: testcode --- diff --git a/tests/bugs160/pr216311/IPersistable.java b/tests/bugs160/pr216311/IPersistable.java new file mode 100644 index 000000000..82bc63304 --- /dev/null +++ b/tests/bugs160/pr216311/IPersistable.java @@ -0,0 +1,9 @@ +import java.io.Serializable; + +public interface IPersistable extends Serializable { + + int getId(); + + void setId(int id); + +} diff --git a/tests/bugs160/pr216311/Persistability.java b/tests/bugs160/pr216311/Persistability.java new file mode 100644 index 000000000..4bd76aeca --- /dev/null +++ b/tests/bugs160/pr216311/Persistability.java @@ -0,0 +1,44 @@ + + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.DeclareParents; +import org.aspectj.lang.annotation.Pointcut; + + +@Aspect +public class Persistability { + + static class Persistable implements IPersistable { + + private static final long serialVersionUID = 7120491865883787353L; + + private int id; + + public Persistable() { + super(); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + } + + @DeclareParents(value = "PersistabilityTest", defaultImpl = Persistable.class) + private IPersistable observable; + + @Pointcut("initialization(IPersistable.new(..)) && this(bean) && !this(Persistable)") + void init(IPersistable bean) { + } + + @Before("init(bean)") + public void beforeInit(IPersistable bean) { + bean.setId(System.identityHashCode(bean)); + } + +} diff --git a/tests/bugs160/pr216311/PersistabilityTest.java b/tests/bugs160/pr216311/PersistabilityTest.java new file mode 100644 index 000000000..a977c9a8d --- /dev/null +++ b/tests/bugs160/pr216311/PersistabilityTest.java @@ -0,0 +1,29 @@ + + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class PersistabilityTest { + + public static void main(String []argv) throws Exception { + + PersistabilityTest persistabilityTest1 = new PersistabilityTest(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + + oos.writeObject(persistabilityTest1); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + + PersistabilityTest persistabilityTest2 = (PersistabilityTest) ois.readObject(); + + if (!(persistabilityTest1 instanceof IPersistable)) throw new RuntimeException("pTest1 not IPersistable"); + if (!(persistabilityTest2 instanceof IPersistable)) throw new RuntimeException("pTest2 not IPersistable"); + int o = ((IPersistable)persistabilityTest1).getId(); + int o2 = ((IPersistable)persistabilityTest2).getId(); + if (o!=o2) throw new RuntimeException(o+" != "+o2); + } +}