01: package com.mockrunner.test.web;
02:
03: import javax.servlet.jsp.el.ELException;
04: import javax.servlet.jsp.el.Expression;
05:
06: import junit.framework.TestCase;
07:
08: import com.mockrunner.mock.web.MockExpressionEvaluator;
09: import com.mockrunner.mock.web.MockFunctionMapper;
10: import com.mockrunner.mock.web.MockVariableResolver;
11:
12: public class MockExpressionEvaluatorTest extends TestCase {
13: private MockExpressionEvaluator evaluator;
14:
15: protected void setUp() throws Exception {
16: super .setUp();
17: evaluator = new MockExpressionEvaluator();
18: }
19:
20: public void testEvaluateFailure() throws Exception {
21: try {
22: evaluator.evaluate("myexp", String.class,
23: new MockVariableResolver(),
24: new MockFunctionMapper());
25: fail();
26: } catch (ELException exc) {
27: //should throw exception
28: }
29: evaluator.addObject("myexp", new Integer(3));
30: try {
31: evaluator.evaluate("myexp", String.class,
32: new MockVariableResolver(),
33: new MockFunctionMapper());
34: fail();
35: } catch (ELException exc) {
36: //should throw exception
37: }
38: }
39:
40: public void testEvaluateOk() throws Exception {
41: evaluator.addObject("myexp", new Integer(3));
42: assertEquals(new Integer(3), evaluator.evaluate("myexp",
43: Integer.class, null, null));
44: Object object = new Object();
45: evaluator.addObject("myexp", object);
46: assertEquals(object, evaluator.evaluate("myexp", Object.class,
47: null, null));
48: }
49:
50: public void testExpression() throws Exception {
51: Expression expression = evaluator.parseExpression("myexp",
52: String.class, null);
53: try {
54: expression.evaluate(null);
55: fail();
56: } catch (ELException exc) {
57: //should throw exception
58: }
59: evaluator.addObject("myexp", "abc");
60: assertEquals("abc", expression.evaluate(null));
61: evaluator.addObject("myexp", new Character('a'));
62: try {
63: expression.evaluate(new MockVariableResolver());
64: fail();
65: } catch (ELException exc) {
66: //should throw exception
67: }
68: }
69:
70: public void testDummy() {
71: }
72: }
|