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 org.apache.commons.ognl.OgnlRuntime;
23 import org.apache.commons.ognl.test.objects.CorrectedObject;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.junit.runners.Parameterized.Parameters;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32
33 @RunWith(value = Parameterized.class)
34 public class NullHandlerTest
35 extends OgnlTestCase
36 {
37 private static CorrectedObject CORRECTED = new CorrectedObject();
38
39 private static Object[][] TESTS = {
40
41 { CORRECTED, "stringValue", "corrected" }, { CORRECTED, "getStringValue()", "corrected" },
42 { CORRECTED, "#root.stringValue", "corrected" }, { CORRECTED, "#root.getStringValue()", "corrected" }, };
43
44
45
46
47
48 @Parameters
49 public static Collection<Object[]> data()
50 {
51 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
52 for ( int i = 0; i < TESTS.length; i++ )
53 {
54 Object[] tmp = new Object[6];
55 tmp[0] = TESTS[i][1];
56 tmp[1] = TESTS[i][0];
57 tmp[2] = TESTS[i][1];
58
59 switch ( TESTS[i].length )
60 {
61 case 3:
62 tmp[3] = TESTS[i][2];
63 break;
64
65 case 4:
66 tmp[3] = TESTS[i][2];
67 tmp[4] = TESTS[i][3];
68 break;
69
70 case 5:
71 tmp[3] = TESTS[i][2];
72 tmp[4] = TESTS[i][3];
73 tmp[5] = TESTS[i][4];
74 break;
75
76 default:
77 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
78 }
79
80 data.add( tmp );
81 }
82 return data;
83 }
84
85
86
87
88
89 public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
90 Object expectedAfterSetResult )
91 {
92 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
93 }
94
95
96
97
98
99 @Override
100 @Before
101 public void setUp()
102 {
103 super.setUp();
104 _compileExpressions = false;
105 OgnlRuntime.setNullHandler( CorrectedObject.class, new CorrectedObjectNullHandler( "corrected" ) );
106 }
107
108 @Test
109
110 @Override
111 public void runTest()
112 throws Exception
113 {
114 super.runTest();
115 }
116 }