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.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.Parameterized;
25 import org.junit.runners.Parameterized.Parameters;
26
27 import java.math.BigInteger;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31
32 @RunWith(value = Parameterized.class)
33 public class LambdaExpressionTest
34 extends OgnlTestCase
35 {
36
37 private static Object[][] TESTS = {
38
39 { null, "#a=:[33](20).longValue().{0}.toArray().length", new Integer( 33 ) },
40 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30)", new Integer( 1409286144 ) },
41 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30L)", new Long( -8764578968847253504L ) },
42 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30h)",
43 new BigInteger( "265252859812191058636308480000000" ) },
44 { null, "#bump = :[ #this.{ #this + 1 } ], (#bump)({ 1, 2, 3 })",
45 new ArrayList( Arrays.asList( new Integer[] { new Integer( 2 ), new Integer( 3 ), new Integer( 4 ) } ) ) },
46 { null, "#call = :[ \"calling \" + [0] + \" on \" + [1] ], (#call)({ \"x\", \"y\" })", "calling x on y" },
47
48 };
49
50
51
52
53
54 @Parameters
55 public static Collection<Object[]> data()
56 {
57 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
58 for ( int i = 0; i < TESTS.length; i++ )
59 {
60 Object[] tmp = new Object[6];
61 tmp[0] = TESTS[i][1];
62 tmp[1] = TESTS[i][0];
63 tmp[2] = TESTS[i][1];
64 tmp[3] = TESTS[i][2];
65
66 data.add( tmp );
67 }
68 return data;
69 }
70
71
72
73
74
75 public LambdaExpressionTest( String name, Object root, String expressionString, Object expectedResult,
76 Object setValue, Object expectedAfterSetResult )
77 {
78 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
79 }
80
81 @Test
82
83 @Override
84 public void runTest()
85 throws Exception
86 {
87 super.runTest();
88 }
89 }