001 /* 002 * $Id: LambdaExpressionTest.java 1188000 2011-10-23 23:10:24Z mcucchiara $ 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 package org.apache.commons.ognl.test; 021 022 import org.junit.Test; 023 import org.junit.runner.RunWith; 024 import org.junit.runners.Parameterized; 025 import org.junit.runners.Parameterized.Parameters; 026 027 import java.math.BigInteger; 028 import java.util.ArrayList; 029 import java.util.Arrays; 030 import java.util.Collection; 031 032 @RunWith(value = Parameterized.class) 033 public class LambdaExpressionTest 034 extends OgnlTestCase 035 { 036 037 private static Object[][] TESTS = { 038 // Lambda expressions 039 { null, "#a=:[33](20).longValue().{0}.toArray().length", new Integer( 33 ) }, 040 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30)", new Integer( 1409286144 ) }, 041 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30L)", new Long( -8764578968847253504L ) }, 042 { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30h)", 043 new BigInteger( "265252859812191058636308480000000" ) }, 044 { null, "#bump = :[ #this.{ #this + 1 } ], (#bump)({ 1, 2, 3 })", 045 new ArrayList( Arrays.asList( new Integer[] { new Integer( 2 ), new Integer( 3 ), new Integer( 4 ) } ) ) }, 046 { null, "#call = :[ \"calling \" + [0] + \" on \" + [1] ], (#call)({ \"x\", \"y\" })", "calling x on y" }, 047 048 }; 049 050 /* 051 * =================================================================== Public static methods 052 * =================================================================== 053 */ 054 @Parameters 055 public static Collection<Object[]> data() 056 { 057 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 058 for ( int i = 0; i < TESTS.length; i++ ) 059 { 060 Object[] tmp = new Object[6]; 061 tmp[0] = TESTS[i][1]; 062 tmp[1] = TESTS[i][0]; 063 tmp[2] = TESTS[i][1]; 064 tmp[3] = TESTS[i][2]; 065 066 data.add( tmp ); 067 } 068 return data; 069 } 070 071 /* 072 * =================================================================== Constructors 073 * =================================================================== 074 */ 075 public LambdaExpressionTest( String name, Object root, String expressionString, Object expectedResult, 076 Object setValue, Object expectedAfterSetResult ) 077 { 078 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 079 } 080 081 @Test 082 083 @Override 084 public void runTest() 085 throws Exception 086 { 087 super.runTest(); 088 } 089 }