001 /*
002 * $Id: SetterWithConversionTest.java 1104080 2011-05-17 09:22:09Z 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.Root;
023 import org.junit.runner.RunWith;
024 import org.junit.runners.Parameterized;
025 import org.junit.runners.Parameterized.Parameters;
026
027 import java.util.ArrayList;
028 import java.util.Collection;
029
030 @RunWith(value = Parameterized.class)
031 public class SetterWithConversionTest
032 extends OgnlTestCase
033 {
034 private static Root ROOT = new Root();
035
036 private static Object[][] TESTS = {
037 // Property set with conversion
038 { ROOT, "intValue", new Integer( 0 ), new Double( 6.5 ), new Integer( 6 ) },
039 { ROOT, "intValue", new Integer( 6 ), new Double( 1025.87645 ), new Integer( 1025 ) },
040 { ROOT, "intValue", new Integer( 1025 ), "654", new Integer( 654 ) },
041 { ROOT, "stringValue", null, new Integer( 25 ), "25" },
042 { ROOT, "stringValue", "25", new Float( 100.25 ), "100.25" },
043 { ROOT, "anotherStringValue", "foo", new Integer( 0 ), "0" },
044 { ROOT, "anotherStringValue", "0", new Double( 0.5 ), "0.5" },
045 { ROOT, "anotherIntValue", new Integer( 123 ), "5", new Integer( 5 ) },
046 { ROOT, "anotherIntValue", new Integer( 5 ), new Double( 100.25 ), new Integer( 100 ) },
047 // { ROOT, "anotherIntValue", new Integer(100), new String[] { "55" }, new Integer(55)},
048 // { ROOT, "yetAnotherIntValue", new Integer(46), new String[] { "55" }, new Integer(55)},
049
050 };
051
052 /*
053 * =================================================================== Public static methods
054 * ===================================================================
055 */
056 @Parameters
057 public static Collection<Object[]> data()
058 {
059 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
060 for ( Object[] TEST : TESTS )
061 {
062 Object[] tmp = new Object[6];
063 tmp[0] = TEST[1];
064 tmp[1] = TEST[0];
065 tmp[2] = TEST[1];
066
067 switch (TEST.length) {
068 case 3:
069 tmp[3] = TEST[2];
070 break;
071
072 case 4:
073 tmp[3] = TEST[2];
074 tmp[4] = TEST[3];
075 break;
076
077 case 5:
078 tmp[3] = TEST[2];
079 tmp[4] = TEST[3];
080 tmp[5] = TEST[4];
081 break;
082
083 default:
084 throw new RuntimeException("don't understand TEST format with length " + TEST.length);
085 }
086
087 data.add(tmp);
088 }
089 return data;
090 }
091
092 /*
093 * =================================================================== Constructors
094 * ===================================================================
095 */
096 public SetterWithConversionTest( String name, Object root, String expressionString, Object expectedResult,
097 Object setValue, Object expectedAfterSetResult )
098 {
099 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
100 }
101 }