001 /* 002 * $Id: ConstantTest.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.ExpressionSyntaxException; 023 import org.junit.Before; 024 import org.junit.runner.RunWith; 025 import org.junit.runners.Parameterized; 026 import org.junit.runners.Parameterized.Parameters; 027 028 import java.math.BigDecimal; 029 import java.util.ArrayList; 030 import java.util.Arrays; 031 import java.util.Collection; 032 033 @RunWith(value = Parameterized.class) 034 public class ConstantTest 035 extends OgnlTestCase 036 { 037 038 private static Object[][] TESTS = { 039 { "12345", new Integer( 12345 ) }, 040 { "0x100", new Integer( 256 ) }, 041 { "0xfE", new Integer( 254 ) }, 042 { "01000", new Integer( 512 ) }, 043 { "1234L", new Integer( 1234 ) }, 044 { "12.34", new Double( 12.34 ) }, 045 { ".1234", new Double( .12340000000000 ) }, 046 { "12.34f", Double.valueOf( 12.34 ) }, 047 { "12.", new Double( 12 ) }, 048 { "12e+1d", new Double( 120 ) }, 049 { "'x'", new Character( 'x' ) }, 050 { "'\\n'", new Character( '\n' ) }, 051 { "'\\u048c'", new Character( '\u048c' ) }, 052 { "'\\47'", new Character( '\47' ) }, 053 { "'\\367'", new Character( '\367' ) }, 054 { "'\\367", ExpressionSyntaxException.class }, 055 { "'\\x'", ExpressionSyntaxException.class }, 056 { "\"hello world\"", "hello world" }, 057 { "\"\\u00a0\\u0068ell\\'o\\\\\\n\\r\\f\\t\\b\\\"\\167orld\\\"\"", "\u00a0hell'o\\\n\r\f\t\b\"world\"" }, 058 { "\"hello world", ExpressionSyntaxException.class }, 059 { "\"hello\\x world\"", ExpressionSyntaxException.class }, 060 { "null", null }, 061 { "true", Boolean.TRUE }, 062 { "false", Boolean.FALSE }, 063 { "{ false, true, null, 0, 1. }", 064 Arrays.asList( new Object[] { Boolean.FALSE, Boolean.TRUE, null, new Integer( 0 ), new Double( 1 ) } ) }, 065 { "'HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"'", 066 "HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"" }, }; 067 068 /* 069 * =================================================================== Public static methods 070 * =================================================================== 071 */ 072 @Parameters 073 public static Collection<Object[]> data() 074 { 075 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 076 for ( int i = 0; i < TESTS.length; i++ ) 077 { 078 Object[] tmp = new Object[6]; 079 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")"; 080 tmp[1] = null; 081 tmp[2] = TESTS[i][0]; 082 tmp[3] = TESTS[i][1]; 083 tmp[4] = null; 084 tmp[5] = null; 085 086 data.add( tmp ); 087 } 088 return data; 089 } 090 091 /* 092 * =================================================================== Constructors 093 * =================================================================== 094 */ 095 public ConstantTest( String name, Object root, String expressionString, Object expectedResult, Object setValue, 096 Object expectedAfterSetResult ) 097 { 098 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 099 } 100 101 @Before 102 @Override 103 public void setUp() 104 { 105 super.setUp(); 106 _context.put( "x", "1" ); 107 _context.put( "y", new BigDecimal( 1 ) ); 108 } 109 }