View Javadoc

1   /*
2    * $Id: ShortCircuitingExpressionTest.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.NoSuchPropertyException;
23  import org.apache.commons.ognl.OgnlException;
24  import org.junit.runner.RunWith;
25  import org.junit.runners.Parameterized;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  import java.util.ArrayList;
29  import java.util.Collection;
30  
31  @RunWith(value = Parameterized.class)
32  public class ShortCircuitingExpressionTest
33      extends OgnlTestCase
34  {
35      private static Object[][] TESTS = { { "#root ? someProperty : 99", new Integer( 99 ) },
36          { "#root ? 99 : someProperty", OgnlException.class },
37          { "(#x=99)? #x.someProperty : #x", NoSuchPropertyException.class },
38          { "#xyzzy.doubleValue()", NullPointerException.class }, { "#xyzzy && #xyzzy.doubleValue()", null },
39          { "(#x=99) && #x.doubleValue()", new Double( 99 ) }, { "#xyzzy || 101", new Integer( 101 ) },
40          { "99 || 101", new Integer( 99 ) }, };
41  
42      /*
43       * =================================================================== Public static methods
44       * ===================================================================
45       */
46      @Parameters
47      public static Collection<Object[]> data()
48      {
49          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
50          for ( int i = 0; i < TESTS.length; i++ )
51          {
52              Object[] tmp = new Object[6];
53              tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
54              tmp[1] = null;
55              tmp[2] = TESTS[i][0];
56              tmp[3] = TESTS[i][1];
57  
58              data.add( tmp );
59          }
60          return data;
61      }
62  
63      /*
64       * =================================================================== Constructors
65       * ===================================================================
66       */
67      public ShortCircuitingExpressionTest( String name, Object root, String expressionString, Object expectedResult,
68                                            Object setValue, Object expectedAfterSetResult )
69      {
70          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
71      }
72  }