View Javadoc

1   /*
2    * $Id: ClassMethodTest.java 1104080 2011-05-17 09:22:09Z 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.CorrectedObject;
23  import org.junit.Before;
24  import org.junit.runner.RunWith;
25  import org.junit.runners.Parameterized;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  import java.math.BigDecimal;
29  import java.util.ArrayList;
30  import java.util.Collection;
31  
32  @RunWith(value = Parameterized.class)
33  public class ClassMethodTest
34      extends OgnlTestCase
35  {
36  
37      private static CorrectedObject CORRECTED = new CorrectedObject();
38  
39      private static Object[][] TESTS = {
40          // Methods on Class
41          { CORRECTED, "getClass().getName()", CORRECTED.getClass().getName() },
42          { CORRECTED, "getClass().getInterfaces()", CORRECTED.getClass().getInterfaces() },
43          { CORRECTED, "getClass().getInterfaces().length", new Integer( CORRECTED.getClass().getInterfaces().length ) },
44          { null, "@System@class.getInterfaces()", System.class.getInterfaces() },
45          { null, "@Class@class.getName()", Class.class.getName() },
46          { null, "@java.awt.image.ImageObserver@class.getName()", java.awt.image.ImageObserver.class.getName() }, };
47  
48      /*
49       * =================================================================== Public static methods
50       * ===================================================================
51       */
52      @Parameters
53      public static Collection<Object[]> data()
54      {
55          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
56          for ( int i = 0; i < TESTS.length; i++ )
57          {
58              Object[] tmp = new Object[6];
59              tmp[0] = TESTS[i][1];
60              tmp[1] = TESTS[i][0];
61              tmp[2] = TESTS[i][1];
62              tmp[3] = TESTS[i][2];
63              tmp[4] = null;
64              tmp[5] = null;
65  
66              data.add( tmp );
67          }
68          return data;
69      }
70  
71      /*
72       * =================================================================== Constructors
73       * ===================================================================
74       */
75      public ClassMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
76                              Object expectedAfterSetResult )
77      {
78          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
79      }
80  
81      @Before
82      @Override
83      public void setUp()
84      {
85          super.setUp();
86          _context.put( "x", "1" );
87          _context.put( "y", new BigDecimal( 1 ) );
88      }
89  }