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.ExpressionSyntaxException;
23 import org.apache.commons.ognl.test.objects.Entry;
24 import org.apache.commons.ognl.test.objects.Root;
25 import org.apache.commons.ognl.test.objects.Simple;
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 ArrayCreationTest
35 extends OgnlTestCase
36 {
37
38 private static Root ROOT = new Root();
39
40 private static Object[][] TESTS =
41 {
42
43 { ROOT, "new String[] { \"one\", \"two\" }", new String[] { "one", "two" } },
44 { ROOT, "new String[] { 1, 2 }", new String[] { "1", "2" } },
45 { ROOT, "new Integer[] { \"1\", 2, \"3\" }",
46 new Integer[] { 1, 2, 3 } },
47 { ROOT, "new String[10]", new String[10] },
48 { ROOT, "new Object[4] { #root, #this }", ExpressionSyntaxException.class },
49 { ROOT, "new Object[4]", new Object[4] },
50 { ROOT, "new Object[] { #root, #this }", new Object[] { ROOT, ROOT } },
51 {
52 ROOT,
53 "new org.apache.commons.ognl.test.objects.Simple[] { new org.apache.commons.ognl.test.objects.Simple(), new org.apache.commons.ognl.test.objects.Simple(\"foo\", 1.0f, 2) }",
54 new Simple[] { new Simple(), new Simple( "foo", 1.0f, 2 ) } },
55 { ROOT, "new org.apache.commons.ognl.test.objects.Simple[5]", new Simple[5] },
56 { ROOT, "new org.apache.commons.ognl.test.objects.Simple(new Object[5])", new Simple( new Object[5] ) },
57 { ROOT, "new org.apache.commons.ognl.test.objects.Simple(new String[5])", new Simple( new String[5] ) },
58 {
59 ROOT,
60 "objectIndex ? new org.apache.commons.ognl.test.objects.Entry[] { new org.apache.commons.ognl.test.objects.Entry(), new org.apache.commons.ognl.test.objects.Entry()} "
61 + ": new org.apache.commons.ognl.test.objects.Entry[] { new org.apache.commons.ognl.test.objects.Entry(), new org.apache.commons.ognl.test.objects.Entry()} ",
62 new Entry[] { new Entry(), new Entry() } } };
63
64
65
66
67
68 @Parameters
69 public static Collection<Object[]> data()
70 {
71 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
72 for ( Object[] TEST : TESTS )
73 {
74 Object[] tmp = new Object[6];
75 tmp[0] = TEST[1];
76 tmp[1] = TEST[0];
77 tmp[2] = TEST[1];
78
79 switch ( TEST.length )
80 {
81 case 3:
82 tmp[3] = TEST[2];
83 break;
84
85 case 4:
86 tmp[3] = TEST[2];
87 tmp[4] = TEST[3];
88 break;
89
90 case 5:
91 tmp[3] = TEST[2];
92 tmp[4] = TEST[3];
93 tmp[5] = TEST[4];
94 break;
95
96 default:
97 throw new RuntimeException( "don't understand TEST format with length" );
98 }
99
100 data.add( tmp );
101 }
102 return data;
103 }
104
105
106
107
108
109 public ArrayCreationTest( String name, Object root, String expressionString, Object expectedResult,
110 Object setValue, Object expectedAfterSetResult )
111 {
112 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
113 }
114 }