KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jelly > tags > junit > JellyAssertionFailedError


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.jelly.tags.junit;
18
19 import java.io.PrintStream JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21
22 import junit.framework.AssertionFailedError;
23
24 import org.apache.commons.jelly.LocationAware;
25
26 /**
27  * <p><code>JellyAssertionFailedError</code> is
28  * a JUnit AssertionFailedError which is LocationAware so that it can include
29  * details of where in the JellyUnit test case that the failure occurred.</p>
30  *
31  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
32  * @version $Revision: 155420 $
33  */

34
35 public class JellyAssertionFailedError extends AssertionFailedError implements LocationAware {
36
37     /** the underlying cause of the exception */
38     private Throwable JavaDoc cause;
39
40     /** the Jelly file which caused the problem */
41     private String JavaDoc fileName;
42
43     /** the tag name which caused the problem */
44     private String JavaDoc elementName;
45
46     /** the line number in the script of the error */
47     private int lineNumber = -1;
48
49     /** the column number in the script of the error */
50     private int columnNumber = -1;
51
52     public JellyAssertionFailedError() {
53     }
54
55     public JellyAssertionFailedError(String JavaDoc message) {
56         super(message);
57     }
58
59     public JellyAssertionFailedError(String JavaDoc message, Throwable JavaDoc cause) {
60         super(message);
61         this.cause = cause;
62     }
63
64     public JellyAssertionFailedError(Throwable JavaDoc cause) {
65         super(cause.getLocalizedMessage());
66         this.cause = cause;
67     }
68
69     public Throwable JavaDoc getCause() {
70         return cause;
71     }
72
73
74     /**
75      * @return the line number of the tag
76      */

77     public int getLineNumber() {
78         return lineNumber;
79     }
80
81     /**
82      * Sets the line number of the tag
83      */

84     public void setLineNumber(int lineNumber) {
85         this.lineNumber = lineNumber;
86     }
87
88     /**
89      * @return the column number of the tag
90      */

91     public int getColumnNumber() {
92         return columnNumber;
93     }
94
95     /**
96      * Sets the column number of the tag
97      */

98     public void setColumnNumber(int columnNumber) {
99         this.columnNumber = columnNumber;
100     }
101
102     /**
103      * @return the Jelly file which caused the problem
104      */

105     public String JavaDoc getFileName() {
106         return fileName;
107     }
108
109     /**
110      * Sets the Jelly file which caused the problem
111      */

112     public void setFileName(String JavaDoc fileName) {
113         this.fileName = fileName;
114     }
115
116
117     /**
118      * @return the element name which caused the problem
119      */

120     public String JavaDoc getElementName() {
121         return elementName;
122     }
123
124     /**
125      * Sets the element name which caused the problem
126      */

127     public void setElementName(String JavaDoc elementName) {
128         this.elementName = elementName;
129     }
130
131
132     public String JavaDoc getMessage() {
133         return super.getMessage() + " File: " + fileName + " At tag <" + elementName + ">: line: "
134             + lineNumber + " column: " + columnNumber;
135     }
136
137     public String JavaDoc getReason() {
138         return super.getMessage();
139     }
140
141     // #### overload the printStackTrace methods...
142
public void printStackTrace(PrintWriter JavaDoc s) {
143         synchronized (s) {
144             super.printStackTrace(s);
145             if (cause != null) {
146                 s.println("Root cause");
147                 cause.printStackTrace(s);
148             }
149         }
150     }
151
152     public void printStackTrace(PrintStream JavaDoc s) {
153         synchronized (s) {
154             super.printStackTrace(s);
155             if (cause != null) {
156                 s.println("Root cause");
157                 cause.printStackTrace(s);
158             }
159         }
160     }
161
162     public void printStackTrace() {
163         super.printStackTrace();
164         if (cause != null) {
165             System.out.println("Root cause");
166             cause.printStackTrace();
167         }
168     }
169 }
170
Popular Tags