001 /* 002 * $Id: ConstantTreeTest.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 static junit.framework.Assert.assertTrue; 023 024 import java.util.ArrayList; 025 import java.util.Collection; 026 027 import org.apache.commons.ognl.Ognl; 028 import org.junit.runner.RunWith; 029 import org.junit.runners.Parameterized; 030 import org.junit.runners.Parameterized.Parameters; 031 032 @RunWith(value = Parameterized.class) 033 public class ConstantTreeTest 034 extends OgnlTestCase 035 { 036 037 public static int nonFinalStaticVariable = 15; 038 039 private static Object[][] TESTS = { { "true", Boolean.TRUE }, { "55", Boolean.TRUE }, 040 { "@java.awt.Color@black", Boolean.TRUE }, 041 { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable", Boolean.FALSE }, 042 { "@org.apache.commons.ognl.test.ConstantTreeTest@nonFinalStaticVariable + 10", Boolean.FALSE }, 043 { "55 + 24 + @java.awt.Event@ALT_MASK", Boolean.TRUE }, { "name", Boolean.FALSE }, 044 { "name[i]", Boolean.FALSE }, { "name[i].property", Boolean.FALSE }, { "name.{? foo }", Boolean.FALSE }, 045 { "name.{ foo }", Boolean.FALSE }, { "name.{ 25 }", Boolean.FALSE } 046 047 }; 048 049 /* 050 * =================================================================== Public static methods 051 * =================================================================== 052 */ 053 @Parameters 054 public static Collection<Object[]> data() 055 { 056 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 057 for ( int i = 0; i < TESTS.length; i++ ) 058 { 059 Object[] tmp = new Object[6]; 060 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")"; 061 tmp[1] = null; 062 tmp[2] = TESTS[i][0]; 063 tmp[3] = TESTS[i][1]; 064 tmp[4] = null; 065 tmp[5] = null; 066 067 data.add( tmp ); 068 } 069 return data; 070 } 071 072 /* 073 * =================================================================== Overridden methods 074 * =================================================================== 075 */ 076 @Override 077 public void runTest() 078 throws Exception 079 { 080 assertTrue( Ognl.isConstant( getExpression(), _context ) == ( (Boolean) getExpectedResult() ).booleanValue() ); 081 } 082 083 /* 084 * =================================================================== Constructors 085 * =================================================================== 086 */ 087 public ConstantTreeTest( String name, Object root, String expressionString, Object expectedResult, Object setValue, 088 Object expectedAfterSetResult ) 089 { 090 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 091 } 092 }