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.JellyTagException;
19: import org.apache.commons.jelly.XMLOutput;
20: import org.apache.commons.jelly.expression.Expression;
21:
22: /**
23: * Compares an actual object against an expected object and if they are different
24: * then the test will fail.
25: *
26: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
27: * @version $Revision: 155420 $
28: */
29: public class AssertEqualsTag extends AssertTagSupport {
30:
31: private Expression actual;
32: private Expression expected;
33:
34: // Tag interface
35: //-------------------------------------------------------------------------
36: public void doTag(XMLOutput output) throws JellyTagException {
37: String message = getBodyText();
38:
39: Object expectedValue = expected.evaluate(context);
40: Object actualValue = actual.evaluate(context);
41:
42: if (expectedValue == null && actualValue == null) {
43: return;
44: }
45: if (actualValue != null && expectedValue.equals(actualValue)) {
46: return;
47: }
48:
49: String expressions = "\nExpected expression: "
50: + expected.getExpressionText()
51: + "\nActual expression: " + actual.getExpressionText();
52:
53: failNotEquals(message, expectedValue, actualValue, expressions);
54: }
55:
56: // Properties
57: //-------------------------------------------------------------------------
58:
59: /**
60: * Sets the actual value which will be compared against the
61: * expected value.
62: */
63: public void setActual(Expression actual) {
64: this .actual = actual;
65: }
66:
67: /**
68: * Sets the expected value to be tested against
69: */
70: public void setExpected(Expression expected) {
71: this.expected = expected;
72: }
73: }
|