001: /*
002: * Copyright 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.jelly.tags.junit;
018:
019: import java.io.PrintStream;
020: import java.io.PrintWriter;
021:
022: import junit.framework.AssertionFailedError;
023:
024: import org.apache.commons.jelly.LocationAware;
025:
026: /**
027: * <p><code>JellyAssertionFailedError</code> is
028: * a JUnit AssertionFailedError which is LocationAware so that it can include
029: * details of where in the JellyUnit test case that the failure occurred.</p>
030: *
031: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
032: * @version $Revision: 155420 $
033: */
034:
035: public class JellyAssertionFailedError extends AssertionFailedError
036: implements LocationAware {
037:
038: /** the underlying cause of the exception */
039: private Throwable cause;
040:
041: /** the Jelly file which caused the problem */
042: private String fileName;
043:
044: /** the tag name which caused the problem */
045: private String elementName;
046:
047: /** the line number in the script of the error */
048: private int lineNumber = -1;
049:
050: /** the column number in the script of the error */
051: private int columnNumber = -1;
052:
053: public JellyAssertionFailedError() {
054: }
055:
056: public JellyAssertionFailedError(String message) {
057: super (message);
058: }
059:
060: public JellyAssertionFailedError(String message, Throwable cause) {
061: super (message);
062: this .cause = cause;
063: }
064:
065: public JellyAssertionFailedError(Throwable cause) {
066: super (cause.getLocalizedMessage());
067: this .cause = cause;
068: }
069:
070: public Throwable getCause() {
071: return cause;
072: }
073:
074: /**
075: * @return the line number of the tag
076: */
077: public int getLineNumber() {
078: return lineNumber;
079: }
080:
081: /**
082: * Sets the line number of the tag
083: */
084: public void setLineNumber(int lineNumber) {
085: this .lineNumber = lineNumber;
086: }
087:
088: /**
089: * @return the column number of the tag
090: */
091: public int getColumnNumber() {
092: return columnNumber;
093: }
094:
095: /**
096: * Sets the column number of the tag
097: */
098: public void setColumnNumber(int columnNumber) {
099: this .columnNumber = columnNumber;
100: }
101:
102: /**
103: * @return the Jelly file which caused the problem
104: */
105: public String getFileName() {
106: return fileName;
107: }
108:
109: /**
110: * Sets the Jelly file which caused the problem
111: */
112: public void setFileName(String fileName) {
113: this .fileName = fileName;
114: }
115:
116: /**
117: * @return the element name which caused the problem
118: */
119: public String getElementName() {
120: return elementName;
121: }
122:
123: /**
124: * Sets the element name which caused the problem
125: */
126: public void setElementName(String elementName) {
127: this .elementName = elementName;
128: }
129:
130: public String getMessage() {
131: return super .getMessage() + " File: " + fileName + " At tag <"
132: + elementName + ">: line: " + lineNumber + " column: "
133: + columnNumber;
134: }
135:
136: public String getReason() {
137: return super .getMessage();
138: }
139:
140: // #### overload the printStackTrace methods...
141: public void printStackTrace(PrintWriter s) {
142: synchronized (s) {
143: super .printStackTrace(s);
144: if (cause != null) {
145: s.println("Root cause");
146: cause.printStackTrace(s);
147: }
148: }
149: }
150:
151: public void printStackTrace(PrintStream s) {
152: synchronized (s) {
153: super .printStackTrace(s);
154: if (cause != null) {
155: s.println("Root cause");
156: cause.printStackTrace(s);
157: }
158: }
159: }
160:
161: public void printStackTrace() {
162: super .printStackTrace();
163: if (cause != null) {
164: System.out.println("Root cause");
165: cause.printStackTrace();
166: }
167: }
168: }
|