You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PersistabilityTest.java 1.1KB

1234567891011121314151617181920212223242526272829
  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.ObjectInputStream;
  4. import java.io.ObjectOutputStream;
  5. public class PersistabilityTest {
  6. public static void main(String []argv) throws Exception {
  7. PersistabilityTest persistabilityTest1 = new PersistabilityTest();
  8. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  9. ObjectOutputStream oos = new ObjectOutputStream(bos);
  10. oos.writeObject(persistabilityTest1);
  11. ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
  12. ObjectInputStream ois = new ObjectInputStream(bis);
  13. PersistabilityTest persistabilityTest2 = (PersistabilityTest) ois.readObject();
  14. if (!(persistabilityTest1 instanceof IPersistable)) throw new RuntimeException("pTest1 not IPersistable");
  15. if (!(persistabilityTest2 instanceof IPersistable)) throw new RuntimeException("pTest2 not IPersistable");
  16. int o = ((IPersistable)persistabilityTest1).getId();
  17. int o2 = ((IPersistable)persistabilityTest2).getId();
  18. if (o!=o2) throw new RuntimeException(o+" != "+o2);
  19. }
  20. }