View Javadoc

1   /*
2    * $Id: MethodWithConversionTest.java 1188000 2011-10-23 23:10: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.Simple;
23  import org.junit.Test;
24  import org.junit.runner.RunWith;
25  import org.junit.runners.Parameterized;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  import java.util.ArrayList;
29  import java.util.Collection;
30  
31  @RunWith(value = Parameterized.class)
32  public class MethodWithConversionTest
33      extends OgnlTestCase
34  {
35  
36      private static Simple SIMPLE = new Simple();
37  
38      private static Object[][] TESTS = {
39          // Method call with conversion
40          { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null }, { SIMPLE, "stringValue", "10" },
41          { SIMPLE, "stringValue", "10", new Character( 'x' ), "x" },
42          { SIMPLE, "setStringValue('x')", null }, // set by calling setStringValue() directly
43          { SIMPLE, "floatValue", new Float( 10.56 ) }, { SIMPLE, "getValueIsTrue(rootValue)", Boolean.TRUE },
44          { SIMPLE, "messages.format('Testing', one, two, three)", "blah" } };
45  
46      /*
47       * =================================================================== Public static methods
48       * ===================================================================
49       */
50      @Parameters
51      public static Collection<Object[]> data()
52      {
53          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
54          for ( int i = 0; i < TESTS.length; i++ )
55          {
56              Object[] tmp = new Object[6];
57              tmp[0] = TESTS[i][1];
58              tmp[1] = TESTS[i][0];
59              tmp[2] = TESTS[i][1];
60  
61              switch ( TESTS[i].length )
62              {
63                  case 3:
64                      tmp[3] = TESTS[i][2];
65                      break;
66  
67                  case 4:
68                      tmp[3] = TESTS[i][2];
69                      tmp[4] = TESTS[i][3];
70                      break;
71  
72                  case 5:
73                      tmp[3] = TESTS[i][2];
74                      tmp[4] = TESTS[i][3];
75                      tmp[5] = TESTS[i][4];
76                      break;
77  
78                  default:
79                      throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
80              }
81  
82              data.add( tmp );
83          }
84          return data;
85      }
86  
87      /*
88       * =================================================================== Constructors
89       * ===================================================================
90       */
91      public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult,
92                                       Object setValue, Object expectedAfterSetResult )
93      {
94          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
95      }
96  
97      @Test
98  
99      @Override
100     public void runTest()
101         throws Exception
102     {
103         super.runTest();
104     }
105 }