View Javadoc

1   /*
2    * $Id: MethodTest.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.*;
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 MethodTest
32      extends OgnlTestCase
33  {
34  
35      private static Simple ROOT = new Simple();
36  
37      private static ListSource LIST = new ListSourceImpl();
38  
39      private static BaseGeneric<GameGenericObject, Long> GENERIC = new GameGeneric();
40  
41      private static Object[][] TESTS = { { "hashCode()", new Integer( ROOT.hashCode() ) },
42          { "getBooleanValue() ? \"here\" : \"\"", "" }, { "getValueIsTrue(!false) ? \"\" : \"here\" ", "" },
43          { "messages.format('ShowAllCount', one)", "foo" },
44          { "getTestValue(@org.apache.commons.ognl.test.objects.SimpleEnum@ONE.value)", new Integer( 2 ) },
45          { "@org.apache.commons.ognl.test.MethodTest@getA().isProperty()", Boolean.FALSE },
46          { "isDisabled()", Boolean.TRUE }, { "isEditorDisabled()", Boolean.FALSE },
47          { LIST, "addValue(name)", Boolean.TRUE }, { "getDisplayValue(methodsTest.allowDisplay)", "test" },
48          { "isThisVarArgsWorking(three, rootValue)", Boolean.TRUE },
49          { GENERIC, "service.getFullMessageFor(value, null)", "Halo 3" } };
50  
51      public static class A
52      {
53          public boolean isProperty()
54          {
55              return false;
56          }
57      }
58  
59      public static A getA()
60      {
61          return new A();
62      }
63  
64      /*
65       * =================================================================== Public static methods
66       * ===================================================================
67       */
68      @Parameters
69      public static Collection<Object[]> data()
70      {
71          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
72          for ( int i = 0; i < TESTS.length; i++ )
73          {
74              Object[] tmp = new Object[6];
75  
76              if ( TESTS[i].length == 3 )
77              {
78                  tmp[0] = TESTS[i][1] + " (" + TESTS[i][2] + ")";
79                  tmp[1] = TESTS[i][0];
80                  tmp[2] = TESTS[i][1];
81                  tmp[3] = TESTS[i][2];
82              }
83              else
84              {
85                  tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
86                  tmp[1] = ROOT;
87                  tmp[2] = TESTS[i][0];
88                  tmp[3] = TESTS[i][1];
89              }
90  
91              data.add( tmp );
92          }
93          return data;
94      }
95  
96      /*
97       * =================================================================== Constructors
98       * ===================================================================
99       */
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 }