1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.junit;
18
19 import java.io.PrintStream;
20 import java.io.PrintWriter;
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 cause;
39
40 /*** the Jelly file which caused the problem */
41 private String fileName;
42
43 /*** the tag name which caused the problem */
44 private String 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 message) {
56 super(message);
57 }
58
59 public JellyAssertionFailedError(String message, Throwable cause) {
60 super(message);
61 this.cause = cause;
62 }
63
64 public JellyAssertionFailedError(Throwable cause) {
65 super(cause.getLocalizedMessage());
66 this.cause = cause;
67 }
68
69 public Throwable 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 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 /***
118 * @return the element name which caused the problem
119 */
120 public String getElementName() {
121 return elementName;
122 }
123
124 /***
125 * Sets the element name which caused the problem
126 */
127 public void setElementName(String elementName) {
128 this.elementName = elementName;
129 }
130
131
132 public String getMessage() {
133 return fileName + ":" + lineNumber + ":" + columnNumber + ": <" + elementName + "> " + super.getMessage();
134 }
135
136 public String getReason() {
137 return super.getMessage();
138 }
139
140
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 }