View Javadoc

1   /*
2    * $Id: LambdaExpressionTest.java 1188000 2011-10-23 23:10:24Z mcucchiara $
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
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          // Lambda expressions
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       * =================================================================== Public static methods
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       * =================================================================== Constructors
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  }