blob: a977c9a8db8b91d7a58d0a8743d8124feb0cc2de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}
}
|