View Javadoc

1   /*
2    * $Id: ConstantTreeTest.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 static junit.framework.Assert.assertTrue;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  
27  import org.apache.commons.ognl.Ognl;
28  import org.junit.runner.RunWith;
29  import org.junit.runners.Parameterized;
30  import org.junit.runners.Parameterized.Parameters;
31  
32  @RunWith(value = Parameterized.class)
33  public class ConstantTreeTest
34      extends OgnlTestCase
35  {
36  
37      public static int nonFinalStaticVariable = 15;
38  
39      private static Object[][] TESTS = { { "true", Boolean.TRUE }, { "55", Boolean.TRUE },
40          { "@java.awt.Color@black", Boolean.TRUE },
41          { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable", Boolean.FALSE },
42          { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable + 10", Boolean.FALSE },
43          { "55 + 24 + @java.awt.Event@ALT_MASK", Boolean.TRUE }, { "name", Boolean.FALSE },
44          { "name[i]", Boolean.FALSE }, { "name[i].property", Boolean.FALSE }, { "name.{? foo }", Boolean.FALSE },
45          { "name.{ foo }", Boolean.FALSE }, { "name.{ 25 }", Boolean.FALSE }
46  
47      };
48  
49      /*
50       * =================================================================== Public static methods
51       * ===================================================================
52       */
53      @Parameters
54      public static Collection<Object[]> data()
55      {
56          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
57          for ( int i = 0; i < TESTS.length; i++ )
58          {
59              Object[] tmp = new Object[6];
60              tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
61              tmp[1] = null;
62              tmp[2] = TESTS[i][0];
63              tmp[3] = TESTS[i][1];
64              tmp[4] = null;
65              tmp[5] = null;
66  
67              data.add( tmp );
68          }
69          return data;
70      }
71  
72      /*
73       * =================================================================== Overridden methods
74       * ===================================================================
75       */
76      @Override
77      public void runTest()
78          throws Exception
79      {
80          assertTrue( Ognl.isConstant( getExpression(), _context ) == ( (Boolean) getExpectedResult() ).booleanValue() );
81      }
82  
83      /*
84       * =================================================================== Constructors
85       * ===================================================================
86       */
87      public ConstantTreeTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
88                               Object expectedAfterSetResult )
89      {
90          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
91      }
92  }