KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > test > TestErrorConditionException


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

18 package org.apache.batik.test;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.io.StringWriter JavaDoc;
22
23 /**
24  * Exception which <tt>AbstractTest</tt> extensions can throw from the
25  * <tt>rumImpl</tt> method to report an error condition.
26  *
27  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
28  * @version $Id: TestErrorConditionException.java,v 1.4 2004/08/18 07:16:58 vhardy Exp $
29  */

30 public class TestErrorConditionException extends Exception JavaDoc {
31     /**
32      * Error code. May be null.
33      */

34     protected String JavaDoc errorCode;
35
36     /**
37      * Default constructor
38      */

39     protected TestErrorConditionException(){
40     }
41
42     /**
43      * @param errorCode describes the error condition
44      */

45     public TestErrorConditionException(String JavaDoc errorCode){
46         this.errorCode = errorCode;
47     }
48
49     /**
50      * Requests a report which describes the exception.
51      */

52     public TestReport getTestReport(Test test){
53         DefaultTestReport report = new DefaultTestReport(test);
54         if(errorCode != null){
55             report.setErrorCode(errorCode);
56         } else {
57             report.setErrorCode(TestReport.ERROR_TEST_FAILED);
58         }
59
60         report.setPassed(false);
61         addStackTraceDescription(report);
62         return report;
63     }
64
65     /**
66      * Convenience method: adds a description entry for the stack
67      * trace.
68      */

69     public void addStackTraceDescription(TestReport report){
70         StringWriter JavaDoc trace = new StringWriter JavaDoc();
71         printStackTrace(new PrintWriter JavaDoc(trace));
72         
73         report.addDescriptionEntry
74           (TestReport.ENTRY_KEY_ERROR_CONDITION_STACK_TRACE,
75            trace.toString());
76     }
77 }
78
Popular Tags