1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
36
37 public void doTag(XMLOutput output) throws JellyTagException {
38 String message = getBodyText();
39
40 Object expectedValue = expected.evaluate(context);
41 Object actualValue = actual.evaluate(context);
42
43 if (expectedValue == null && actualValue == null) {
44 return;
45 }
46 if (actualValue != null && expectedValue.equals(actualValue)) {
47 return;
48 }
49
50 String expressions = "\nExpected expression: "
51 + expected.getExpressionText()
52 + "\nActual expression: "
53 + actual.getExpressionText();
54
55 failNotEquals(message, expectedValue, actualValue, expressions);
56 }
57
58
59
60
61 /***
62 * Sets the actual value which will be compared against the
63 * expected value.
64 */
65 public void setActual(Expression actual) {
66 this.actual = actual;
67 }
68
69 /***
70 * Sets the expected value to be tested against
71 */
72 public void setExpected(Expression expected) {
73 this.expected = expected;
74 }
75 }