01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.jelly.tags.junit;
17:
18: import org.apache.commons.jelly.xpath.XPathTagSupport;
19:
20: /**
21: * The abstract base class of any assertion tag which is
22: * useful for implementation inheritence.
23: *
24: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
25: * @version $Revision: 155420 $
26: */
27: public abstract class AssertTagSupport extends XPathTagSupport {
28:
29: public AssertTagSupport() {
30: }
31:
32: // Implementation methods
33: //-------------------------------------------------------------------------
34:
35: /**
36: * Produces a failure assertion with the given message
37: */
38: protected void fail(String message)
39: throws JellyAssertionFailedError {
40: throw new JellyAssertionFailedError(message);
41: }
42:
43: /**
44: * Produces a failure assertion with the given message and added detail.
45: */
46: protected void fail(String message, String detail)
47: throws JellyAssertionFailedError {
48: if (message == null || message.length() == 0) {
49: fail(detail);
50: } else {
51: fail(message + ". Assertion failed while " + detail);
52: }
53: }
54:
55: /**
56: * Produces a failure if the actual value was not equal to the expected value
57: */
58: protected void failNotEquals(String message, Object expected,
59: Object actual, String expressions)
60: throws JellyAssertionFailedError {
61: String formatted = "";
62: if (message != null) {
63: formatted = message + " ";
64: }
65: fail(formatted + "expected:[" + expected + "] but was:["
66: + actual + "]" + expressions);
67: }
68:
69: }
|