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   *  @since 1.0
30   *  @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
31   *  @version $Id: AsserterTest.java 209171 2005-07-05 01:24:57Z dion $
32   */
33  public class AsserterTest extends TestCase {
34      
35      public static Test suite() {
36          return new TestSuite(AsserterTest.class);
37      }
38  
39      public static void main(String[] args) {
40          TestRunner.run(suite());
41      }
42  
43      public AsserterTest(String testName) {
44          super(testName);
45      }
46  
47      public void testThis() throws Exception {
48          Asserter asserter = new Asserter(new Foo());
49          
50          asserter.assertExpression("this.get('abc')", "Repeat : abc");
51          
52          try {
53              asserter.assertExpression("this.count", "Wrong Value");
54              fail("This method should have thrown an assertion exception");
55          }
56          catch (AssertionFailedError e) {
57              
58          }
59      }
60  
61      public void testVariable() throws Exception {
62          Asserter asserter = new Asserter();
63          asserter.setVariable("foo", new Foo());
64          asserter.setVariable("person", "James");
65  
66          asserter.assertExpression("person", "James");
67          asserter.assertExpression("size(person)", new Integer(5));
68          
69          asserter.assertExpression("foo.getCount()", new Integer(5));
70          asserter.assertExpression("foo.count", new Integer(5));
71          
72          try {
73              asserter.assertExpression("bar.count", new Integer(5));
74              fail("This method should have thrown an assertion exception");
75          }
76          catch (AssertionFailedError e) {
77              
78          }
79      }
80  }