KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jexl > junit > AsserterTest


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.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 JavaDoc[] args) {
39         TestRunner.run(suite());
40     }
41
42     public AsserterTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     public void testThis() throws Exception JavaDoc {
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             // it worked!
57
}
58     }
59
60     public void testVariable() throws Exception JavaDoc {
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 JavaDoc(5));
67         
68         asserter.assertExpression("foo.getCount()", new Integer JavaDoc(5));
69         asserter.assertExpression("foo.count", new Integer JavaDoc(5));
70         
71         try {
72             asserter.assertExpression("bar.count", new Integer JavaDoc(5));
73             fail("This method should have thrown an assertion exception");
74         }
75         catch (AssertionFailedError e) {
76             // it worked!
77
}
78     }
79 }
80
Popular Tags