1 /*
2 * $Id: PrimitiveNullHandlingTest.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 java.util.ArrayList;
23 import java.util.Collection;
24
25 import org.apache.commons.ognl.test.objects.Simple;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.junit.runners.Parameterized.Parameters;
29
30 @RunWith(value = Parameterized.class)
31 public class PrimitiveNullHandlingTest
32 extends OgnlTestCase
33 {
34
35 private static Simple SIMPLE = new Simple();
36
37 static
38 {
39 SIMPLE.setFloatValue( 10.56f );
40 SIMPLE.setIntValue( 34 );
41 }
42
43 private static Object[][] TESTS = {
44 // Primitive null handling
45 { SIMPLE, "floatValue", new Float( 10.56f ), null, new Float( 0f ) }, // set float to
46 // null, should
47 // yield 0.0f
48 { SIMPLE, "intValue", new Integer( 34 ), null, new Integer( 0 ) },// set int to null,
49 // should yield 0
50 { SIMPLE, "booleanValue", Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },// set boolean
51 // to TRUE,
52 // should yield
53 // true
54 { SIMPLE, "booleanValue", Boolean.TRUE, null, Boolean.FALSE }, // set boolean to null,
55 // should yield false
56
57 };
58
59 /*
60 * =================================================================== Public static methods
61 * ===================================================================
62 */
63 @Parameters
64 public static Collection<Object[]> data()
65 {
66 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
67 for ( int i = 0; i < TESTS.length; i++ )
68 {
69 Object[] tmp = new Object[6];
70 tmp[0] = TESTS[i][1];
71 tmp[1] = TESTS[i][0];
72 tmp[2] = TESTS[i][1];
73
74 switch ( TESTS[i].length )
75 {
76 case 3:
77 tmp[3] = TESTS[i][2];
78 break;
79
80 case 4:
81 tmp[3] = TESTS[i][2];
82 tmp[4] = TESTS[i][3];
83 break;
84
85 case 5:
86 tmp[3] = TESTS[i][2];
87 tmp[4] = TESTS[i][3];
88 tmp[5] = TESTS[i][4];
89 break;
90
91 default:
92 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
93 }
94
95 data.add( tmp );
96 }
97 return data;
98 }
99
100 /*
101 * =================================================================== Constructors
102 * ===================================================================
103 */
104 public PrimitiveNullHandlingTest( String name, Object root, String expressionString, Object expectedResult,
105 Object setValue, Object expectedAfterSetResult )
106 {
107 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
108 }
109 }