1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jexl.junit;
17
18 import junit.framework.AssertionFailedError;
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22 import junit.textui.TestRunner;
23
24 import org.apache.commons.jexl.Foo;
25
26 /***
27 * Simple testcases
28 *
29 * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
30 * @version $Id: AsserterTest.java,v 1.3 2004/02/28 13:45:22 yoavs Exp $
31 */
32 public class AsserterTest extends TestCase {
33
34 public static Test suite() {
35 return new TestSuite(AsserterTest.class);
36 }
37
38 public static void main(String[] args) {
39 TestRunner.run(suite());
40 }
41
42 public AsserterTest(String testName) {
43 super(testName);
44 }
45
46 public void testThis() throws Exception {
47 Asserter asserter = new Asserter(new Foo());
48
49 asserter.assertExpression("this.get('abc')", "Repeat : abc");
50
51 try {
52 asserter.assertExpression("this.count", "Wrong Value");
53 fail("This method should have thrown an assertion exception");
54 }
55 catch (AssertionFailedError e) {
56
57 }
58 }
59
60 public void testVariable() throws Exception {
61 Asserter asserter = new Asserter();
62 asserter.setVariable("foo", new Foo());
63 asserter.setVariable("person", "James");
64
65 asserter.assertExpression("person", "James");
66 asserter.assertExpression("size(person)", new Integer(5));
67
68 asserter.assertExpression("foo.getCount()", new Integer(5));
69 asserter.assertExpression("foo.count", new Integer(5));
70
71 try {
72 asserter.assertExpression("bar.count", new Integer(5));
73 fail("This method should have thrown an assertion exception");
74 }
75 catch (AssertionFailedError e) {
76
77 }
78 }
79 }