added test code for serialization / deserialization


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137093 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java b/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
index fbc3417..2db6f18 100644
--- a/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
+++ b/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
@@ -55,8 +55,12 @@
  */
 
 import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
 
 import junit.framework.*;
 import junit.textui.TestRunner;
@@ -64,7 +68,7 @@
  * Tests the org.apache.commons.lang.exception.NestableException class.
  *
  * @author <a href="mailto:steven@caswell.name">Steven Caswell</a>
- * @version $Id: NestableExceptionTestCase.java,v 1.5 2002/09/11 19:00:52 stevencaswell Exp $
+ * @version $Id: NestableExceptionTestCase.java,v 1.6 2002/10/09 05:28:53 sullis Exp $
  */
 public class NestableExceptionTestCase extends AbstractNestableTestCase
 {
@@ -242,6 +246,67 @@
         return Exception.class;
     }
     
+    public void testSerialization()
+    {
+    	RuntimeException nestedEx = new RuntimeException("nested exception message");
+    	NestableExceptionTester1 ex = new NestableExceptionTester1("serialization test", nestedEx);
+
+		assertTrue( "implements java.io.Serializable", nestedEx instanceof java.io.Serializable);
+		
+		assertTrue( "implements java.io.Serializable", ex instanceof java.io.Serializable);
+		
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ByteArrayInputStream bais = null;
+		ObjectOutputStream oos = null;
+		ObjectInputStream ois = null;
+		
+		try
+		{
+			oos = new ObjectOutputStream(baos);
+			oos.writeObject(ex);
+			oos.flush();
+			bais = new ByteArrayInputStream(baos.toByteArray());
+			ois = new ObjectInputStream(bais);
+			NestableExceptionTester1 deserializedEx = (NestableExceptionTester1) ois.readObject();
+			assertEquals( 
+					"getThrowableCount() return value",
+						ex.getThrowableCount(),
+						deserializedEx.getThrowableCount());
+			
+			for (int i = 0; i < ex.getThrowableCount(); i++)
+			{
+				Throwable t = ex.getThrowable(i);
+				Throwable deserializedThrowable = deserializedEx.getThrowable(i);
+				
+				assertEquals( t.getClass(),
+						deserializedThrowable.getClass());
+						
+				assertEquals(
+					t.getMessage(),
+					deserializedThrowable.getMessage());
+			}
+		}
+		catch (Exception caughtEx)
+		{
+			fail("an unexpected exception occurred: "
+					+ caughtEx.toString());
+		}
+		finally
+		{
+			if (null != oos)
+			{
+				try
+				{
+					oos.close();
+				}
+				catch (Exception ignored)
+				{
+					// intentionally empty
+				}
+			}
+		}
+		
+    }
 }
 
 /**