sullis 2002/10/08 22:28:53
Modified: lang/src/test/org/apache/commons/lang/exception
NestableExceptionTestCase.java
Log:
added test code for serialization / deserialization
Revision Changes Path
1.6 +66 -1
jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java
Index: NestableExceptionTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/exception/NestableExceptionTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NestableExceptionTestCase.java 11 Sep 2002 19:00:52 -0000 1.5
+++ NestableExceptionTestCase.java 9 Oct 2002 05:28:53 -0000 1.6
@@ -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;
@@ -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
+ }
+ }
+ }
+
+ }
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>