View Javadoc

1   /*
2    * $Id: PrimitiveArrayTest.java 1167340 2011-09-09 19:50: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.apache.commons.ognl.test.objects.Root;
23  import org.junit.runner.RunWith;
24  import org.junit.runners.Parameterized;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import java.util.ArrayList;
28  import java.util.Collection;
29  
30  @RunWith(value = Parameterized.class)
31  public class PrimitiveArrayTest
32      extends OgnlTestCase
33  {
34      private static Root ROOT = new Root();
35  
36      private static Object[][] TESTS = {
37          // Primitive array creation
38          { ROOT, "new boolean[5]", new boolean[5] },
39          { ROOT, "new boolean[] { true, false }", new boolean[] { true, false } },
40          { ROOT, "new boolean[] { 0, 1, 5.5 }", new boolean[] { false, true, true } },
41          { ROOT, "new char[] { 'a', 'b' }", new char[] { 'a', 'b' } },
42          { ROOT, "new char[] { 10, 11 }", new char[] { (char) 10, (char) 11 } },
43          { ROOT, "new byte[] { 1, 2 }", new byte[] { 1, 2 } }, { ROOT, "new short[] { 1, 2 }", new short[] { 1, 2 } },
44          { ROOT, "new int[six]", new int[ROOT.six] }, { ROOT, "new int[#root.six]", new int[ROOT.six] },
45          { ROOT, "new int[6]", new int[6] }, { ROOT, "new int[] { 1, 2 }", new int[] { 1, 2 } },
46          { ROOT, "new long[] { 1, 2 }", new long[] { 1, 2 } }, { ROOT, "new float[] { 1, 2 }", new float[] { 1, 2 } },
47          { ROOT, "new double[] { 1, 2 }", new double[] { 1, 2 } },
48  
49      };
50  
51      /*
52       * =================================================================== Public static methods
53       * ===================================================================
54       */
55      @Parameters
56      public static Collection<Object[]> data()
57      {
58          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
59          for ( Object[] TEST : TESTS )
60          {
61              Object[] tmp = new Object[6];
62              tmp[0] = TEST[1];
63              tmp[1] = TEST[0];
64              tmp[2] = TEST[1];
65  
66              switch ( TEST.length )
67              {
68                  case 3:
69                      tmp[3] = TEST[2];
70                      break;
71  
72                  case 4:
73                      tmp[3] = TEST[2];
74                      tmp[4] = TEST[3];
75                      break;
76  
77                  case 5:
78                      tmp[3] = TEST[2];
79                      tmp[4] = TEST[3];
80                      tmp[5] = TEST[4];
81                      break;
82  
83                  default:
84                      throw new RuntimeException( "don't understand TEST format with length " + TEST.length );
85              }
86  
87              data.add( tmp );
88          }
89          return data;
90      }
91  
92      /*
93       * =================================================================== Constructors
94       * ===================================================================
95       */
96      public PrimitiveArrayTest( String name, Object root, String expressionString, Object expectedResult,
97                                 Object setValue, Object expectedAfterSetResult )
98      {
99          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
100     }
101 }