001 /*
002 * $Id: MethodTest.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.*;
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 MethodTest
032 extends OgnlTestCase
033 {
034
035 private static Simple ROOT = new Simple();
036
037 private static ListSource LIST = new ListSourceImpl();
038
039 private static BaseGeneric<GameGenericObject, Long> GENERIC = new GameGeneric();
040
041 private static Object[][] TESTS = { { "hashCode()", new Integer( ROOT.hashCode() ) },
042 { "getBooleanValue() ? \"here\" : \"\"", "" }, { "getValueIsTrue(!false) ? \"\" : \"here\" ", "" },
043 { "messages.format('ShowAllCount', one)", "foo" },
044 { "getTestValue(@org.apache.commons.ognl.test.objects.SimpleEnum@ONE.value)", new Integer( 2 ) },
045 { "@org.apache.commons.ognl.test.MethodTest@getA().isProperty()", Boolean.FALSE },
046 { "isDisabled()", Boolean.TRUE }, { "isEditorDisabled()", Boolean.FALSE },
047 { LIST, "addValue(name)", Boolean.TRUE }, { "getDisplayValue(methodsTest.allowDisplay)", "test" },
048 { "isThisVarArgsWorking(three, rootValue)", Boolean.TRUE },
049 { GENERIC, "service.getFullMessageFor(value, null)", "Halo 3" } };
050
051 public static class A
052 {
053 public boolean isProperty()
054 {
055 return false;
056 }
057 }
058
059 public static A getA()
060 {
061 return new A();
062 }
063
064 /*
065 * =================================================================== Public static methods
066 * ===================================================================
067 */
068 @Parameters
069 public static Collection<Object[]> data()
070 {
071 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
072 for ( int i = 0; i < TESTS.length; i++ )
073 {
074 Object[] tmp = new Object[6];
075
076 if ( TESTS[i].length == 3 )
077 {
078 tmp[0] = TESTS[i][1] + " (" + TESTS[i][2] + ")";
079 tmp[1] = TESTS[i][0];
080 tmp[2] = TESTS[i][1];
081 tmp[3] = TESTS[i][2];
082 }
083 else
084 {
085 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
086 tmp[1] = ROOT;
087 tmp[2] = TESTS[i][0];
088 tmp[3] = TESTS[i][1];
089 }
090
091 data.add( tmp );
092 }
093 return data;
094 }
095
096 /*
097 * =================================================================== Constructors
098 * ===================================================================
099 */
100 public MethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
101 Object expectedAfterSetResult )
102 {
103 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
104 }
105 }