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.Arrays;
29 import java.util.Collection;
30
31 @RunWith(value = Parameterized.class)
32 public class CollectionDirectPropertyTest
33 extends OgnlTestCase
34 {
35
36 private static Root ROOT = new Root();
37
38 private static Object[][] TESTS = {
39
40 { Arrays.asList( "hello", "world" ), "size", 2 },
41 { Arrays.asList( "hello", "world" ), "isEmpty", Boolean.FALSE },
42 { Arrays.asList(), "isEmpty", Boolean.TRUE },
43 { Arrays.asList( "hello", "world" ), "iterator.next", "hello" },
44 { Arrays.asList( "hello", "world" ), "iterator.hasNext", Boolean.TRUE },
45 { Arrays.asList( "hello", "world" ), "#it = iterator, #it.next, #it.next, #it.hasNext", Boolean.FALSE },
46 { Arrays.asList( "hello", "world" ), "#it = iterator, #it.next, #it.next", "world" },
47 { Arrays.asList( "hello", "world" ), "size", 2 },
48 { ROOT, "map[\"test\"]", ROOT }, { ROOT, "map.size", ROOT.getMap().size() },
49 { ROOT, "map.keySet", ROOT.getMap().keySet() }, { ROOT, "map.values", ROOT.getMap().values() },
50 { ROOT, "map.keys.size", ROOT.getMap().keySet().size() },
51 { ROOT, "map[\"size\"]", ROOT.getMap().get( "size" ) },
52 { ROOT, "map.isEmpty", ROOT.getMap().isEmpty() ? Boolean.TRUE : Boolean.FALSE },
53 { ROOT, "map[\"isEmpty\"]", null }, };
54
55
56
57
58
59 @Parameters
60 public static Collection<Object[]> data()
61 {
62 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
63 for ( Object[] TEST : TESTS )
64 {
65 Object[] tmp = new Object[6];
66 tmp[0] = TEST[1];
67 tmp[1] = TEST[0];
68 tmp[2] = TEST[1];
69
70 switch ( TEST.length )
71 {
72 case 3:
73 tmp[3] = TEST[2];
74 break;
75
76 case 4:
77 tmp[3] = TEST[2];
78 tmp[4] = TEST[3];
79 break;
80
81 case 5:
82 tmp[3] = TEST[2];
83 tmp[4] = TEST[3];
84 tmp[5] = TEST[4];
85 break;
86
87 default:
88 throw new RuntimeException( "don't understand TEST format with length" );
89 }
90
91 data.add( tmp );
92 }
93 return data;
94 }
95
96
97
98
99
100 public CollectionDirectPropertyTest( String name, Object root, String expressionString, Object expectedResult,
101 Object setValue, Object expectedAfterSetResult )
102 {
103 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
104 }
105 }