1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.plugin.junit.tags;
20
21 /***
22 * Performs an assertEquals on two variables. This tag, along with all JUnit tags
23 * can be used inside any other plug-in's session tag
24 *
25 * To compare two variables with a default JUnit error message on a failure:
26 *
27 * <pre><source>
28 * <testcase xmlns="jelly:jameleon">
29 * <ju-session application="someApp">
30 * <ju-assert-equals
31 * functionId="Check that var1 equals var2."
32 * expected="${var1}"
33 * actual="${var2}"/>
34 * </ju-session>
35 * </testcase>
36 * </source></pre>
37 *
38 * To compare two variables that gives "First Name" at the beginning of the failure message:
39 *
40 * <pre><source>
41 * <testcase xmlns="jelly:jameleon">
42 * <jiffie-session application="someApp">
43 * <ju-assert-equals
44 * functionId="Check that var1 equals var2."
45 * expected="${var1}"
46 * actual="${var2}"
47 * msg="First Name"/>
48 * </jiffie-session>
49 * </testcase>
50 * </source></pre>
51 *
52 * @jameleon.function name="ju-assert-equals" type="action"
53 * @jameleon.step Compare the expected value against the actual value.
54 */
55 public class AssertEqualsTag extends AbstractAssertTag{
56
57 /***
58 * The expected value
59 * @jameleon.attribute
60 */
61 protected Object expected;
62 /***
63 * The actual value
64 * @jameleon.attribute
65 */
66 protected Object actual;
67 /***
68 * Forces the values to be compared as Strings by calling the toString() method.
69 * @jameleon.attribute default="false"
70 */
71 protected boolean valuesAreStrings;
72
73 public void testBlock(){
74 if (valuesAreStrings ||
75 (expected != null && actual != null &&
76 !expected.getClass().isInstance(actual))) {
77 if (msg != null) {
78 assertEquals(msg, expected.toString(), actual.toString());
79 }else{
80 assertEquals(expected.toString(), actual.toString());
81 }
82 } else{
83 if (msg != null) {
84 assertEquals(msg, expected, actual);
85 }else{
86 assertEquals(expected, actual);
87 }
88 }
89 }
90
91 }