001: /*
002:
003: Derby - Class org.apache.derbyTesting.unitTests.harness.T_Fail
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.unitTests.harness;
023:
024: /**
025: Exception used to throw for errors in a unit test.
026: */
027: public class T_Fail extends Exception {
028:
029: private Throwable nested;
030:
031: /**
032: Create a T_Fail exception which carries a message.
033:
034: @param messageId An Id for an error message for this exception.
035: */
036: private T_Fail(String message) {
037: super (message);
038: }
039:
040: /**
041: return a T_Fail exception to indicate the configuration does
042: not specify the module to test.
043:
044: @return The exception.
045: */
046: public static T_Fail moduleToTestIdNotFound() {
047: return new T_Fail(
048: "Test failed because the configuration does not include the MODULE_TO_TEST_IDENT attribute.");
049: }
050:
051: /**
052: return a T_Fail exception to indicate the configuration does
053: not contain the module to test.
054:
055: @return The exception.
056: */
057: public static T_Fail moduleToTestNotFound(String moduleToTest) {
058: return new T_Fail("Test failed due to failure loading "
059: + moduleToTest);
060: }
061:
062: /**
063: return a T_Fail exception to indicate the test failed due
064: to an exception.
065:
066: <P>Note: Since the Test Service catches all exceptions this
067: seems to be of limited value.
068:
069: @return The exception.
070: */
071: public static T_Fail exceptionFail(Throwable e) {
072: T_Fail tf = new T_Fail("The test failed with an exception: "
073: + e.toString());
074: tf.nested = e;
075: return tf;
076: }
077:
078: /**
079: return a T_Fail exception to indicate the test failed.
080:
081: @return the exception.
082: */
083: public static T_Fail testFail() {
084: return new T_Fail("The test failed");
085: }
086:
087: /**
088: return a T_Fail exception which includes a user message indicating
089: why a test failed.
090:
091: @return The exception.
092: */
093: public static T_Fail testFailMsg(String message) {
094: return new T_Fail("Test failed - " + message);
095: }
096:
097: /**
098: Check a test condition. If it is false, throw a T_Fail exception.
099:
100: @param mustBeTrue The condition.
101: @exception T_Fail A test failure exception
102: */
103: public static final void T_ASSERT(boolean mustBeTrue) throws T_Fail {
104: if (!mustBeTrue)
105: throw testFail();
106: }
107:
108: /**
109: Check a test condition. If it is false, throw a T_Fail exception which
110: includes a message.
111:
112: @param mustBeTrue The condition.
113: @param msg A message describing the failue.
114: @exception T_Fail A test failure exception
115: */
116: public static final void T_ASSERT(boolean mustBeTrue, String msg)
117: throws T_Fail {
118: if (!mustBeTrue)
119: throw testFailMsg(msg);
120: }
121: }
|