KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > acceptance > ReadResolveTest


1 package com.thoughtworks.acceptance;
2
3 import com.thoughtworks.acceptance.objects.StatusEnum;
4
5 import java.io.*;
6
7 /**
8  * @author Chris Kelly
9  * @author Joe Walnes
10  */

11 public class ReadResolveTest extends AbstractAcceptanceTest {
12
13     public void testReadResolveWithDefaultSerialization() throws IOException, ClassNotFoundException JavaDoc {
14         StatusEnum status = StatusEnum.STARTED;
15
16         ByteArrayOutputStream bout = new ByteArrayOutputStream();
17         ObjectOutputStream os = new ObjectOutputStream(bout);
18         os.writeObject(status);
19
20         byte[] bArray = bout.toByteArray();
21         StatusEnum rStatus = null;
22         ObjectInputStream in = null;
23
24         ByteArrayInputStream bin = new ByteArrayInputStream(bArray);
25         in = new ObjectInputStream(bin);
26         rStatus = (StatusEnum) in.readObject();
27         assertNotNull(rStatus);
28
29         assertSame(status, rStatus);
30     }
31
32     public void testReadResolveWithXStream() {
33         StatusEnum status = StatusEnum.STARTED;
34
35         String JavaDoc xml = xstream.toXML(status);
36         StatusEnum rStatus = (StatusEnum) xstream.fromXML(xml);
37
38         assertSame(status, rStatus);
39     }
40 }
41
Popular Tags