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.test.objects.Root;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.Parameterized;
25 import org.junit.runners.Parameterized.Parameters;
26
27 import java.util.ArrayList;
28 import java.util.Collection;
29
30 @RunWith(value = Parameterized.class)
31 public class PrimitiveArrayTest
32 extends OgnlTestCase
33 {
34 private static Root ROOT = new Root();
35
36 private static Object[][] TESTS = {
37
38 { ROOT, "new boolean[5]", new boolean[5] },
39 { ROOT, "new boolean[] { true, false }", new boolean[] { true, false } },
40 { ROOT, "new boolean[] { 0, 1, 5.5 }", new boolean[] { false, true, true } },
41 { ROOT, "new char[] { 'a', 'b' }", new char[] { 'a', 'b' } },
42 { ROOT, "new char[] { 10, 11 }", new char[] { (char) 10, (char) 11 } },
43 { ROOT, "new byte[] { 1, 2 }", new byte[] { 1, 2 } }, { ROOT, "new short[] { 1, 2 }", new short[] { 1, 2 } },
44 { ROOT, "new int[six]", new int[ROOT.six] }, { ROOT, "new int[#root.six]", new int[ROOT.six] },
45 { ROOT, "new int[6]", new int[6] }, { ROOT, "new int[] { 1, 2 }", new int[] { 1, 2 } },
46 { ROOT, "new long[] { 1, 2 }", new long[] { 1, 2 } }, { ROOT, "new float[] { 1, 2 }", new float[] { 1, 2 } },
47 { ROOT, "new double[] { 1, 2 }", new double[] { 1, 2 } },
48
49 };
50
51
52
53
54
55 @Parameters
56 public static Collection<Object[]> data()
57 {
58 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
59 for ( Object[] TEST : TESTS )
60 {
61 Object[] tmp = new Object[6];
62 tmp[0] = TEST[1];
63 tmp[1] = TEST[0];
64 tmp[2] = TEST[1];
65
66 switch ( TEST.length )
67 {
68 case 3:
69 tmp[3] = TEST[2];
70 break;
71
72 case 4:
73 tmp[3] = TEST[2];
74 tmp[4] = TEST[3];
75 break;
76
77 case 5:
78 tmp[3] = TEST[2];
79 tmp[4] = TEST[3];
80 tmp[5] = TEST[4];
81 break;
82
83 default:
84 throw new RuntimeException( "don't understand TEST format with length " + TEST.length );
85 }
86
87 data.add( tmp );
88 }
89 return data;
90 }
91
92
93
94
95
96 public PrimitiveArrayTest( String name, Object root, String expressionString, Object expectedResult,
97 Object setValue, Object expectedAfterSetResult )
98 {
99 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
100 }
101 }