1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jexl;
17
18 import junit.framework.TestCase;
19
20 import org.apache.commons.jexl.parser.ParseException;
21
22 /***
23 * Tests for malformed expressions and scripts.
24 * ({@link ExpressionFactory} and {@link ScriptFactory} should throw
25 * {@link ParseException}s).
26 *
27 * @since 1.1
28 */
29 public class ParseFailuresTest extends TestCase {
30
31 /***
32 * Create the test.
33 *
34 * @param testName name of the test
35 */
36 public ParseFailuresTest(String testName) {
37 super(testName);
38 }
39
40 public void testMalformedExpression1() throws Exception {
41
42 String badExpression = "eq";
43 try {
44 Expression e = ExpressionFactory.createExpression(badExpression);
45 fail("Parsing \"" + badExpression
46 + "\" should result in a ParseException");
47 } catch (ParseException pe) {
48
49 }
50 }
51
52 public void testMalformedExpression2() throws Exception {
53
54 String badExpression = "?";
55 try {
56 Expression e = ExpressionFactory.createExpression(badExpression);
57 fail("Parsing \"" + badExpression
58 + "\" should result in a ParseException");
59 } catch (ParseException pe) {
60
61 }
62 }
63
64 public void testMalformedScript1() throws Exception {
65
66 String badScript = "eq";
67 try {
68 Script s = ScriptFactory.createScript(badScript);
69 fail("Parsing \"" + badScript
70 + "\" should result in a ParseException");
71 } catch (ParseException pe) {
72
73 }
74 }
75
76
77 public void testMalformedScript2() throws Exception {
78
79 String badScript = "?";
80 try {
81 Script s = ScriptFactory.createScript(badScript);
82 fail("Parsing \"" + badScript
83 + "\" should result in a ParseException");
84 } catch (ParseException pe) {
85
86 }
87 }
88
89 public void testMalformedScript3() throws Exception {
90
91 String badScript = "foo=1;bar=2;a?b:c;";
92 try {
93 Script s = ScriptFactory.createScript(badScript);
94 fail("Parsing \"" + badScript
95 + "\" should result in a ParseException");
96 } catch (ParseException pe) {
97
98 }
99 }
100
101 }