001 /*
002 * $Id: ShortCircuitingExpressionTest.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.NoSuchPropertyException;
023 import org.apache.commons.ognl.OgnlException;
024 import org.junit.runner.RunWith;
025 import org.junit.runners.Parameterized;
026 import org.junit.runners.Parameterized.Parameters;
027
028 import java.util.ArrayList;
029 import java.util.Collection;
030
031 @RunWith(value = Parameterized.class)
032 public class ShortCircuitingExpressionTest
033 extends OgnlTestCase
034 {
035 private static Object[][] TESTS = { { "#root ? someProperty : 99", new Integer( 99 ) },
036 { "#root ? 99 : someProperty", OgnlException.class },
037 { "(#x=99)? #x.someProperty : #x", NoSuchPropertyException.class },
038 { "#xyzzy.doubleValue()", NullPointerException.class }, { "#xyzzy && #xyzzy.doubleValue()", null },
039 { "(#x=99) && #x.doubleValue()", new Double( 99 ) }, { "#xyzzy || 101", new Integer( 101 ) },
040 { "99 || 101", new Integer( 99 ) }, };
041
042 /*
043 * =================================================================== Public static methods
044 * ===================================================================
045 */
046 @Parameters
047 public static Collection<Object[]> data()
048 {
049 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
050 for ( int i = 0; i < TESTS.length; i++ )
051 {
052 Object[] tmp = new Object[6];
053 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
054 tmp[1] = null;
055 tmp[2] = TESTS[i][0];
056 tmp[3] = TESTS[i][1];
057
058 data.add( tmp );
059 }
060 return data;
061 }
062
063 /*
064 * =================================================================== Constructors
065 * ===================================================================
066 */
067 public ShortCircuitingExpressionTest( String name, Object root, String expressionString, Object expectedResult,
068 Object setValue, Object expectedAfterSetResult )
069 {
070 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
071 }
072 }