dlr 2003/01/20 15:04:19
Modified: lang/src/test/org/apache/commons/lang/exception
ExceptionUtilsTestCase.java
lang/src/java/org/apache/commons/lang/exception
ExceptionUtils.java
Log:
* src/test/org/apache/commons/lang/exception/ExceptionUtilsTestCase.java
testPrintThrowables(): Previously printing some stack traces to
stdout as part of its tests which at first glance looks like a test
failure (but in reality isn't). Here's a truncated example:
test.exception:
[echo] Running exception package tests ...
[java] .........................................
[java] ......org.apache.commons.lang.exception.ExceptionUtilsTestCase$Ex
[java] at org.apache.commons.lang.exception.ExceptionUtilsTestCase.c
[java] [wrapped] org.apache.commons.lang.exception.ExceptionUtilsTestCa
[java] at org.apache.commons.lang.exception.ExceptionUtilsTestCase.c
[java] [wrapped] org.apache.commons.lang.exception.ExceptionUtilsTestCa
[java] at org.apache.commons.lang.exception.ExceptionUtilsTestCase.c
[java] at org.apache.commons.lang.exception.ExceptionUtilsTestCase.t
* src/java/org/apache/commons/lang/exception/ExceptionUtils.java
WRAPPED_MARKER: New constant for the " [wrapped] " text used when
printing exception stack traces.
getRootCauseStackTrace(Throwable): Replaced inline " [wrapped] "
text with use of new WRAPPED_MARKER constant.
Revision Changes Path
1.6 +12 -2
jakarta-commons/lang/src/test/org/apache/commons/lang/exception/ExceptionUtilsTestCase.java
Index: ExceptionUtilsTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/exception/ExceptionUtilsTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -u -r1.5 -r1.6
--- ExceptionUtilsTestCase.java 16 Dec 2002 23:05:29 -0000 1.5
+++ ExceptionUtilsTestCase.java 20 Jan 2003 23:04:19 -0000 1.6
@@ -55,6 +55,7 @@
*/
import java.io.PrintWriter;
+import java.io.StringWriter;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -132,12 +133,21 @@
}
public void testPrintThrowables()
+ throws Exception
{
+ StringWriter writer = new StringWriter(1024);
Throwable withCause = createExceptionWithCause();
ExceptionUtils.printRootCauseStackTrace(withCause,
- new PrintWriter(System.out));
+ new PrintWriter(writer));
+ String stackTrace = writer.toString();
+ assertTrue("printRootCauseStackTrace(Throwable, PrintWriter) failed",
+ stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) != -1);
+ writer = new StringWriter(1024);
ExceptionUtils.printRootCauseStackTrace(withoutCause,
- System.out);
+ new PrintWriter(writer));
+ stackTrace = writer.toString();
+ assertTrue("printRootCauseStackTrace(Throwable, PrintWriter) failed",
+ stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) == -1);
}
/**
1.20 +9 -2
jakarta-commons/lang/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Index: ExceptionUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/exception/ExceptionUtils.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -u -r1.19 -r1.20
--- ExceptionUtils.java 23 Dec 2002 00:03:47 -0000 1.19
+++ ExceptionUtils.java 20 Jan 2003 23:04:19 -0000 1.20
@@ -81,6 +81,13 @@
*/
public class ExceptionUtils {
/**
+ * Used when printing stack frames to denote the start of a
+ * wrapped exception. Package private for accessibility by test
+ * suite.
+ */
+ static final String WRAPPED_MARKER = " [wrapped] ";
+
+ /**
* The names of methods commonly used to access a wrapped
* exception.
*/
@@ -401,7 +408,7 @@
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
- frames.add(" [wrapped] " + throwables[i].toString());
+ frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>