KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > harness > T_Fail


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.harness.T_Fail
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.unitTests.harness;
23
24 /**
25     Exception used to throw for errors in a unit test.
26 */

27 public class T_Fail extends Exception JavaDoc {
28
29     private Throwable JavaDoc nested;
30
31     /**
32       Create a T_Fail exception which carries a message.
33
34       @param messageId An Id for an error message for this exception.
35       */

36     private T_Fail(String JavaDoc message) {
37         super(message);
38     }
39
40     /**
41         return a T_Fail exception to indicate the configuration does
42         not specify the module to test.
43
44         @return The exception.
45     */

46     public static T_Fail moduleToTestIdNotFound()
47     {
48         return new T_Fail("Test failed because the configuration does not include the MODULE_TO_TEST_IDENT attribute.");
49     }
50
51     /**
52         return a T_Fail exception to indicate the configuration does
53         not contain the module to test.
54
55         @return The exception.
56     */

57     public static T_Fail moduleToTestNotFound(String JavaDoc moduleToTest)
58     {
59         return new T_Fail("Test failed due to failure loading " + moduleToTest);
60     }
61
62     /**
63       return a T_Fail exception to indicate the test failed due
64       to an exception.
65
66       <P>Note: Since the Test Service catches all exceptions this
67       seems to be of limited value.
68
69       @return The exception.
70     */

71     public static T_Fail exceptionFail(Throwable JavaDoc e)
72     {
73         T_Fail tf = new T_Fail("The test failed with an exception: " + e.toString());
74         tf.nested = e;
75         return tf;
76     }
77
78     /**
79       return a T_Fail exception to indicate the test failed.
80
81       @return the exception.
82       */

83     public static T_Fail testFail()
84     {
85         return new T_Fail("The test failed");
86     }
87
88     /**
89       return a T_Fail exception which includes a user message indicating
90       why a test failed.
91
92       @return The exception.
93     */

94     public static T_Fail testFailMsg(String JavaDoc message)
95     {
96         return new T_Fail("Test failed - " + message);
97     }
98
99     /**
100       Check a test condition. If it is false, throw a T_Fail exception.
101
102       @param mustBeTrue The condition.
103       @exception T_Fail A test failure exception
104       */

105     public static final void T_ASSERT(boolean mustBeTrue)
106          throws T_Fail
107     {
108         if (!mustBeTrue)
109             throw testFail();
110     }
111
112     /**
113       Check a test condition. If it is false, throw a T_Fail exception which
114       includes a message.
115
116       @param mustBeTrue The condition.
117       @param msg A message describing the failue.
118       @exception T_Fail A test failure exception
119       */

120     public static final void T_ASSERT(boolean mustBeTrue,String JavaDoc msg)
121          throws T_Fail
122     {
123         if (!mustBeTrue)
124             throw testFailMsg(msg);
125     }
126 }
127
Popular Tags