001 /* 002 * $Id: MethodWithConversionTest.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.apache.commons.ognl.test.objects.Simple; 023 import org.junit.Test; 024 import org.junit.runner.RunWith; 025 import org.junit.runners.Parameterized; 026 import org.junit.runners.Parameterized.Parameters; 027 028 import java.util.ArrayList; 029 import java.util.Collection; 030 031 @RunWith(value = Parameterized.class) 032 public class MethodWithConversionTest 033 extends OgnlTestCase 034 { 035 036 private static Simple SIMPLE = new Simple(); 037 038 private static Object[][] TESTS = { 039 // Method call with conversion 040 { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null }, { SIMPLE, "stringValue", "10" }, 041 { SIMPLE, "stringValue", "10", new Character( 'x' ), "x" }, 042 { SIMPLE, "setStringValue('x')", null }, // set by calling setStringValue() directly 043 { SIMPLE, "floatValue", new Float( 10.56 ) }, { SIMPLE, "getValueIsTrue(rootValue)", Boolean.TRUE }, 044 { SIMPLE, "messages.format('Testing', one, two, three)", "blah" } }; 045 046 /* 047 * =================================================================== Public static methods 048 * =================================================================== 049 */ 050 @Parameters 051 public static Collection<Object[]> data() 052 { 053 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 054 for ( int i = 0; i < TESTS.length; i++ ) 055 { 056 Object[] tmp = new Object[6]; 057 tmp[0] = TESTS[i][1]; 058 tmp[1] = TESTS[i][0]; 059 tmp[2] = TESTS[i][1]; 060 061 switch ( TESTS[i].length ) 062 { 063 case 3: 064 tmp[3] = TESTS[i][2]; 065 break; 066 067 case 4: 068 tmp[3] = TESTS[i][2]; 069 tmp[4] = TESTS[i][3]; 070 break; 071 072 case 5: 073 tmp[3] = TESTS[i][2]; 074 tmp[4] = TESTS[i][3]; 075 tmp[5] = TESTS[i][4]; 076 break; 077 078 default: 079 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length ); 080 } 081 082 data.add( tmp ); 083 } 084 return data; 085 } 086 087 /* 088 * =================================================================== Constructors 089 * =================================================================== 090 */ 091 public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult, 092 Object setValue, Object expectedAfterSetResult ) 093 { 094 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 095 } 096 097 @Test 098 099 @Override 100 public void runTest() 101 throws Exception 102 { 103 super.runTest(); 104 } 105 }