001 /* 002 * $Id: PrimitiveArrayTest.java 1167340 2011-09-09 19:50: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.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 PrimitiveArrayTest 032 extends OgnlTestCase 033 { 034 private static Root ROOT = new Root(); 035 036 private static Object[][] TESTS = { 037 // Primitive array creation 038 { ROOT, "new boolean[5]", new boolean[5] }, 039 { ROOT, "new boolean[] { true, false }", new boolean[] { true, false } }, 040 { ROOT, "new boolean[] { 0, 1, 5.5 }", new boolean[] { false, true, true } }, 041 { ROOT, "new char[] { 'a', 'b' }", new char[] { 'a', 'b' } }, 042 { ROOT, "new char[] { 10, 11 }", new char[] { (char) 10, (char) 11 } }, 043 { ROOT, "new byte[] { 1, 2 }", new byte[] { 1, 2 } }, { ROOT, "new short[] { 1, 2 }", new short[] { 1, 2 } }, 044 { ROOT, "new int[six]", new int[ROOT.six] }, { ROOT, "new int[#root.six]", new int[ROOT.six] }, 045 { ROOT, "new int[6]", new int[6] }, { ROOT, "new int[] { 1, 2 }", new int[] { 1, 2 } }, 046 { ROOT, "new long[] { 1, 2 }", new long[] { 1, 2 } }, { ROOT, "new float[] { 1, 2 }", new float[] { 1, 2 } }, 047 { ROOT, "new double[] { 1, 2 }", new double[] { 1, 2 } }, 048 049 }; 050 051 /* 052 * =================================================================== Public static methods 053 * =================================================================== 054 */ 055 @Parameters 056 public static Collection<Object[]> data() 057 { 058 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 059 for ( Object[] TEST : TESTS ) 060 { 061 Object[] tmp = new Object[6]; 062 tmp[0] = TEST[1]; 063 tmp[1] = TEST[0]; 064 tmp[2] = TEST[1]; 065 066 switch ( TEST.length ) 067 { 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 PrimitiveArrayTest( String name, Object root, String expressionString, Object expectedResult, 097 Object setValue, Object expectedAfterSetResult ) 098 { 099 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 100 } 101 }