01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * @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: } catch (AssertionFailedError e) {
56: // it worked!
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: } catch (AssertionFailedError e) {
75: // it worked!
76: }
77: }
78: }
|