1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.web;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.ByteArrayOutputStream;
27 import java.io.ObjectInputStream;
28 import java.io.ObjectOutputStream;
29
30 import junit.framework.TestCase;
31
32
33
34
35
36
37
38 public class BusinessObjectTest extends TestCase {
39
40
41
42
43 protected void setUp() throws Exception {
44 super.setUp();
45 }
46
47
48
49
50 protected void tearDown() throws Exception {
51 super.tearDown();
52 }
53
54 public void testSerialization() throws Exception {
55 Mock mock = new Mock();
56 mock.setVersion(25);
57
58 super.assertNotNull(mock.logger);
59
60
61 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
62 ObjectOutputStream out = new ObjectOutputStream(buffer);
63 out.writeObject(mock);
64 out.close();
65
66
67 byte[] pickled = buffer.toByteArray();
68 ByteArrayInputStream read = new ByteArrayInputStream(pickled);
69 ObjectInputStream in = new ObjectInputStream(read);
70 Mock mockClone = (Mock)in.readObject();
71
72 super.assertNotNull(mockClone.logger);
73 }
74
75 private static class Mock extends BusinessObject {
76
77 private static final long serialVersionUID = 8275056178438855026L;
78
79 }
80 }