%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.junit.AssertEqualsTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
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: 1.5 $ |
|
28 | */ |
|
29 | 3 | public class AssertEqualsTag extends AssertTagSupport { |
30 | ||
31 | private Expression actual; |
|
32 | private Expression expected; |
|
33 | ||
34 | ||
35 | // Tag interface |
|
36 | //------------------------------------------------------------------------- |
|
37 | public void doTag(XMLOutput output) throws JellyTagException { |
|
38 | 3 | String message = getBodyText(); |
39 | ||
40 | 3 | Object expectedValue = expected.evaluate(context); |
41 | 3 | Object actualValue = actual.evaluate(context); |
42 | ||
43 | 3 | if (expectedValue == null && actualValue == class="keyword">null) { |
44 | 0 | return; |
45 | } |
|
46 | 3 | if (actualValue != null && expectedValue.equals(actualValue)) { |
47 | 2 | return; |
48 | } |
|
49 | ||
50 | 1 | String expressions = "\nExpected expression: " |
51 | + expected.getExpressionText() |
|
52 | + "\nActual expression: " |
|
53 | + actual.getExpressionText(); |
|
54 | ||
55 | 1 | failNotEquals(message, expectedValue, actualValue, expressions); |
56 | 0 | } |
57 | ||
58 | // Properties |
|
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 | 3 | this.actual = actual; |
67 | 3 | } |
68 | ||
69 | /** |
|
70 | * Sets the expected value to be tested against |
|
71 | */ |
|
72 | public void setExpected(Expression expected) { |
|
73 | 3 | this.expected = expected; |
74 | 3 | } |
75 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |