psteitz 2004/07/10 15:23:14
Modified: math/src/test/org/apache/commons/math MathExceptionTest.java
Log:
Added tests for printStackTrace(), serialization.
Revision Changes Path
1.8 +54 -1
jakarta-commons/math/src/test/org/apache/commons/math/MathExceptionTest.java
Index: MathExceptionTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/MathExceptionTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MathExceptionTest.java 21 Feb 2004 21:35:16 -0000 1.7
+++ MathExceptionTest.java 10 Jul 2004 22:23:14 -0000 1.8
@@ -18,6 +18,10 @@
import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
/**
* @version $Revision$ $Date$
*/
@@ -61,5 +65,54 @@
Exception cause = new Exception(inMsg);
MathException ex = new MathException(cause);
assertEquals(cause, ex.getCause());
+ }
+
+ /**
+ * Tests the printStackTrace() operation.
+ */
+ public void testPrintStackTrace() {
+ String outMsg = "outer message";
+ String inMsg = "inner message";
+ MathException cause = new MathConfigurationException(inMsg);
+ MathException ex = new MathException(outMsg, cause);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ ex.printStackTrace(ps);
+ String stack = baos.toString();
+ String outerMsg = "org.apache.commons.math.MathException: outer message";
+ String innerMsg = "Caused by: " +
+ "org.apache.commons.math.MathConfigurationException: inner message";
+ assertTrue(stack.startsWith(outerMsg));
+ assertTrue(stack.indexOf(innerMsg) > 0);
+
+ PrintWriter pw = new PrintWriter(ps, true);
+ ex.printStackTrace(pw);
+ stack = baos.toString();
+ assertTrue(stack.startsWith(outerMsg));
+ assertTrue(stack.indexOf(innerMsg) > 0);
+ }
+
+ /**
+ * Test serialization
+ */
+ public void testSerialization() {
+ String outMsg = "outer message";
+ String inMsg = "inner message";
+ MathException cause = new MathConfigurationException(inMsg);
+ MathException ex = new MathException(outMsg, cause);
+ MathException image = (MathException) TestUtils.serializeAndRecover(ex);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ PrintWriter pw = new PrintWriter(ps, true);
+ ex.printStackTrace(ps);
+ String stack = baos.toString();
+
+ ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+ PrintStream ps2 = new PrintStream(baos2);
+ PrintWriter pw2 = new PrintWriter(ps2, true);
+ image.printStackTrace(ps2);
+ String stack2 = baos2.toString();
+ assertEquals(stack, stack2);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]