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.DefaultMemberAccess;
23 import org.apache.commons.ognl.test.objects.Root;
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 PrivateAccessorTest
35 extends OgnlTestCase
36 {
37
38 private static Root ROOT = new Root();
39
40 private static Object[][] TESTS = {
41
42 { ROOT, "getPrivateAccessorIntValue()", new Integer( 67 ) },
43 { ROOT, "privateAccessorIntValue", new Integer( 67 ) },
44 { ROOT, "privateAccessorIntValue", new Integer( 67 ), new Integer( 100 ) },
45 { ROOT, "privateAccessorIntValue2", new Integer( 67 ) },
46 { ROOT, "privateAccessorIntValue2", new Integer( 67 ), new Integer( 100 ) },
47 { ROOT, "privateAccessorIntValue3", new Integer( 67 ) },
48 { ROOT, "privateAccessorIntValue3", new Integer( 67 ), new Integer( 100 ) },
49 { ROOT, "privateAccessorBooleanValue", Boolean.TRUE },
50 { ROOT, "privateAccessorBooleanValue", Boolean.TRUE, Boolean.FALSE }, };
51
52
53
54
55
56 @Parameters
57 public static Collection<Object[]> data()
58 {
59 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
60 for ( int i = 0; i < TESTS.length; i++ )
61 {
62 Object[] tmp = new Object[6];
63 tmp[0] = TESTS[i][1];
64 tmp[1] = TESTS[i][0];
65 tmp[2] = TESTS[i][1];
66
67 switch ( TESTS[i].length )
68 {
69 case 3:
70 tmp[3] = TESTS[i][2];
71 break;
72
73 case 4:
74 tmp[3] = TESTS[i][2];
75 tmp[4] = TESTS[i][3];
76 break;
77
78 case 5:
79 tmp[3] = TESTS[i][2];
80 tmp[4] = TESTS[i][3];
81 tmp[5] = TESTS[i][4];
82 break;
83
84 default:
85 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
86 }
87
88 data.add( tmp );
89 }
90 return data;
91 }
92
93
94
95
96
97 public PrivateAccessorTest( String name, Object root, String expressionString, Object expectedResult,
98 Object setValue, Object expectedAfterSetResult )
99 {
100 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
101 }
102
103
104
105
106
107 @Before
108 @Override
109 public void setUp()
110 {
111 super.setUp();
112 _context.setMemberAccess( new DefaultMemberAccess( true ) );
113 _compileExpressions = false;
114 }
115
116 @Test
117
118 @Override
119 public void runTest()
120 throws Exception
121 {
122 super.runTest();
123 }
124 }