001 /*
002 * $Id: ClassMethodTest.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.CorrectedObject;
023 import org.junit.Before;
024 import org.junit.runner.RunWith;
025 import org.junit.runners.Parameterized;
026 import org.junit.runners.Parameterized.Parameters;
027
028 import java.math.BigDecimal;
029 import java.util.ArrayList;
030 import java.util.Collection;
031
032 @RunWith(value = Parameterized.class)
033 public class ClassMethodTest
034 extends OgnlTestCase
035 {
036
037 private static CorrectedObject CORRECTED = new CorrectedObject();
038
039 private static Object[][] TESTS = {
040 // Methods on Class
041 { CORRECTED, "getClass().getName()", CORRECTED.getClass().getName() },
042 { CORRECTED, "getClass().getInterfaces()", CORRECTED.getClass().getInterfaces() },
043 { CORRECTED, "getClass().getInterfaces().length", new Integer( CORRECTED.getClass().getInterfaces().length ) },
044 { null, "@System@class.getInterfaces()", System.class.getInterfaces() },
045 { null, "@Class@class.getName()", Class.class.getName() },
046 { null, "@java.awt.image.ImageObserver@class.getName()", java.awt.image.ImageObserver.class.getName() }, };
047
048 /*
049 * =================================================================== Public static methods
050 * ===================================================================
051 */
052 @Parameters
053 public static Collection<Object[]> data()
054 {
055 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
056 for ( int i = 0; i < TESTS.length; i++ )
057 {
058 Object[] tmp = new Object[6];
059 tmp[0] = TESTS[i][1];
060 tmp[1] = TESTS[i][0];
061 tmp[2] = TESTS[i][1];
062 tmp[3] = TESTS[i][2];
063 tmp[4] = null;
064 tmp[5] = null;
065
066 data.add( tmp );
067 }
068 return data;
069 }
070
071 /*
072 * =================================================================== Constructors
073 * ===================================================================
074 */
075 public ClassMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
076 Object expectedAfterSetResult )
077 {
078 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
079 }
080
081 @Before
082 @Override
083 public void setUp()
084 {
085 super.setUp();
086 _context.put( "x", "1" );
087 _context.put( "y", new BigDecimal( 1 ) );
088 }
089 }