1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.apache.commons.jexl3;
18  
19  import static org.junit.jupiter.api.Assertions.assertThrows;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.junit.jupiter.api.Test;
24  
25  
26  
27  
28  
29  public class ParseFailuresTest extends JexlTestCase {
30  
31      static final Log LOGGER = LogFactory.getLog(ParseFailuresTest.class.getName());
32  
33      
34  
35  
36      public ParseFailuresTest() {
37          super("ParseFailuresTest");
38      }
39  
40      @Test
41      public void testMalformedExpression1() throws Exception {
42          
43          final String badExpression = "eq";
44          final JexlException pe = assertThrows(JexlException.class, () -> JEXL.createExpression(badExpression),
45                  () -> "Parsing \"" + badExpression + "\" should result in a JexlException");
46          LOGGER.debug(pe);
47      }
48  
49      @Test
50      public void testMalformedExpression2() throws Exception {
51          
52          final String badExpression = "?";
53          final JexlException pe = assertThrows(JexlException.class, () -> JEXL.createExpression(badExpression),
54                  () -> "Parsing \"" + badExpression + "\" should result in a JexlException");
55          LOGGER.debug(pe);
56      }
57  
58      @Test
59      public void testMalformedScript1() throws Exception {
60          
61          final String badScript = "eq";
62          final JexlException pe = assertThrows(JexlException.class, () -> JEXL.createExpression(badScript),
63                  () -> "Parsing \"" + badScript + "\" should result in a JexlException");
64          LOGGER.debug(pe);
65      }
66  
67      @Test
68      public void testMalformedScript2() throws Exception {
69          
70          final String badScript = "?";
71          final JexlException pe = assertThrows(JexlException.class, () -> JEXL.createExpression(badScript),
72                  () -> "Parsing \"" + badScript + "\" should result in a JexlException");
73          LOGGER.debug(pe);
74      }
75  
76      @Test
77      public void testMalformedScript3() throws Exception {
78          
79          final String badScript = "foo=1;bar=2;a?b:c:d;";
80          final JexlException pe = assertThrows(JexlException.class, () -> JEXL.createExpression(badScript),
81                  () -> "Parsing \"" + badScript + "\" should result in a JexlException");
82          LOGGER.debug(pe);
83      }
84  
85  }