KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > testcase > CascadingAssertionFailedError


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.testcase;
9
10 import junit.framework.AssertionFailedError;
11
12 import org.apache.avalon.framework.ExceptionUtil;
13 import org.apache.avalon.framework.CascadingThrowable;
14
15 import java.io.PrintStream JavaDoc;
16 import java.io.PrintWriter JavaDoc;
17
18 /**
19  * This is an extention to the testing framework so that we can get detailed
20  * messages from JUnit (The AssertionFailedError hides the underlying cause)
21  *
22  * @author <a HREF="mailto:giacomo@apache.org">Giacomo Pati</a>
23  * @version $Id: CascadingAssertionFailedError.java,v 1.3 2001/12/11 09:53:32 jefft Exp $
24  */

25 public class CascadingAssertionFailedError extends AssertionFailedError implements CascadingThrowable {
26     private final Throwable JavaDoc m_throwable;
27
28     /**
29      * Constructor with no message
30      */

31     public CascadingAssertionFailedError()
32     {
33         this( null, null );
34     }
35
36     /**
37      * Constructor with a message
38      */

39     public CascadingAssertionFailedError(String JavaDoc message)
40     {
41         this( message, null );
42     }
43
44     /**
45      * Constructor with a message and a parent exception
46      */

47     public CascadingAssertionFailedError(String JavaDoc message, Throwable JavaDoc parentThrowable)
48     {
49         super( message );
50         m_throwable = parentThrowable;
51     }
52
53     /**
54      * Return the parent exception
55      */

56     public final Throwable JavaDoc getCause()
57     {
58         return m_throwable;
59     }
60
61     public final void printStackTrace()
62     {
63         super.printStackTrace();
64         System.out.print( ExceptionUtil.printStackTrace( m_throwable, 8, true ) );
65     }
66
67     public final void printStackTrace( PrintStream JavaDoc stream )
68     {
69         super.printStackTrace( stream );
70         stream.print( ExceptionUtil.printStackTrace( m_throwable, 8, true ) );
71     }
72
73     public final void printStackTrace( PrintWriter JavaDoc writer )
74     {
75         super.printStackTrace( writer );
76         writer.print( ExceptionUtil.printStackTrace( m_throwable, 8, true ) );
77     }
78 }
79
Popular Tags