KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > common > ObjectSerializerTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * ObjectSerializerTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.common;
25
26 import com.rift.coad.lib.common.*;
27 import junit.framework.*;
28 import java.io.ByteArrayInputStream JavaDoc;
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.io.ObjectInputStream JavaDoc;
31 import java.io.ObjectOutputStream JavaDoc;
32
33 /**
34  *
35  * @author mincemeat
36  */

37 public class ObjectSerializerTest extends TestCase {
38     
39     public static class TestObject implements java.io.Serializable JavaDoc {
40         public String JavaDoc key = null;
41         public String JavaDoc value = null;
42         
43         public TestObject() {
44             
45         }
46         
47         public TestObject(String JavaDoc key, String JavaDoc value) {
48             this.key = key;
49             this.value = value;
50         }
51     }
52     
53     public ObjectSerializerTest(String JavaDoc testName) {
54         super(testName);
55     }
56
57     protected void setUp() throws Exception JavaDoc {
58     }
59
60     protected void tearDown() throws Exception JavaDoc {
61     }
62
63     public static Test suite() {
64         TestSuite suite = new TestSuite(ObjectSerializerTest.class);
65         
66         return suite;
67     }
68
69     /**
70      * Test of serialize method, of class com.rift.coad.lib.common.ObjectSerializer.
71      */

72     public void testSerializer() throws Exception JavaDoc {
73         System.out.println("serializer");
74         
75         TestObject startObject = new TestObject("fred","freds value is here");
76         byte[] result = ObjectSerializer.serialize(startObject);
77         TestObject resultObject =
78                 (TestObject)ObjectSerializer.deserialize(result);
79         
80         if (!startObject.key.equals(resultObject.key) &&
81                 startObject.value.equals(resultObject.value)) {
82             fail ("The serialization and deserialization test failed");
83         }
84     }
85
86     
87     
88 }
89
Popular Tags