1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.ognl.test;
21
22 import static junit.framework.Assert.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26
27 import org.apache.commons.ognl.Ognl;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30 import org.junit.runners.Parameterized.Parameters;
31
32 @RunWith(value = Parameterized.class)
33 public class ConstantTreeTest
34 extends OgnlTestCase
35 {
36
37 public static int nonFinalStaticVariable = 15;
38
39 private static Object[][] TESTS = { { "true", Boolean.TRUE }, { "55", Boolean.TRUE },
40 { "@java.awt.Color@black", Boolean.TRUE },
41 { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable", Boolean.FALSE },
42 { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable + 10", Boolean.FALSE },
43 { "55 + 24 + @java.awt.Event@ALT_MASK", Boolean.TRUE }, { "name", Boolean.FALSE },
44 { "name[i]", Boolean.FALSE }, { "name[i].property", Boolean.FALSE }, { "name.{? foo }", Boolean.FALSE },
45 { "name.{ foo }", Boolean.FALSE }, { "name.{ 25 }", Boolean.FALSE }
46
47 };
48
49
50
51
52
53 @Parameters
54 public static Collection<Object[]> data()
55 {
56 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
57 for ( int i = 0; i < TESTS.length; i++ )
58 {
59 Object[] tmp = new Object[6];
60 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
61 tmp[1] = null;
62 tmp[2] = TESTS[i][0];
63 tmp[3] = TESTS[i][1];
64 tmp[4] = null;
65 tmp[5] = null;
66
67 data.add( tmp );
68 }
69 return data;
70 }
71
72
73
74
75
76 @Override
77 public void runTest()
78 throws Exception
79 {
80 assertTrue( Ognl.isConstant( getExpression(), _context ) == ( (Boolean) getExpectedResult() ).booleanValue() );
81 }
82
83
84
85
86
87 public ConstantTreeTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
88 Object expectedAfterSetResult )
89 {
90 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
91 }
92 }