001 /* 002 * $Id: NullHandlerTest.java 1188000 2011-10-23 23:10:24Z 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.OgnlRuntime; 023 import org.apache.commons.ognl.test.objects.CorrectedObject; 024 import org.junit.Before; 025 import org.junit.Test; 026 import org.junit.runner.RunWith; 027 import org.junit.runners.Parameterized; 028 import org.junit.runners.Parameterized.Parameters; 029 030 import java.util.ArrayList; 031 import java.util.Collection; 032 033 @RunWith(value = Parameterized.class) 034 public class NullHandlerTest 035 extends OgnlTestCase 036 { 037 private static CorrectedObject CORRECTED = new CorrectedObject(); 038 039 private static Object[][] TESTS = { 040 // NullHandler 041 { CORRECTED, "stringValue", "corrected" }, { CORRECTED, "getStringValue()", "corrected" }, 042 { CORRECTED, "#root.stringValue", "corrected" }, { CORRECTED, "#root.getStringValue()", "corrected" }, }; 043 044 /* 045 * =================================================================== Public static methods 046 * =================================================================== 047 */ 048 @Parameters 049 public static Collection<Object[]> data() 050 { 051 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 052 for ( int i = 0; i < TESTS.length; i++ ) 053 { 054 Object[] tmp = new Object[6]; 055 tmp[0] = TESTS[i][1]; 056 tmp[1] = TESTS[i][0]; 057 tmp[2] = TESTS[i][1]; 058 059 switch ( TESTS[i].length ) 060 { 061 case 3: 062 tmp[3] = TESTS[i][2]; 063 break; 064 065 case 4: 066 tmp[3] = TESTS[i][2]; 067 tmp[4] = TESTS[i][3]; 068 break; 069 070 case 5: 071 tmp[3] = TESTS[i][2]; 072 tmp[4] = TESTS[i][3]; 073 tmp[5] = TESTS[i][4]; 074 break; 075 076 default: 077 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length ); 078 } 079 080 data.add( tmp ); 081 } 082 return data; 083 } 084 085 /* 086 * =================================================================== Constructors 087 * =================================================================== 088 */ 089 public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult, Object setValue, 090 Object expectedAfterSetResult ) 091 { 092 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 093 } 094 095 /* 096 * =================================================================== Overridden methods 097 * =================================================================== 098 */ 099 @Override 100 @Before 101 public void setUp() 102 { 103 super.setUp(); 104 _compileExpressions = false; 105 OgnlRuntime.setNullHandler( CorrectedObject.class, new CorrectedObjectNullHandler( "corrected" ) ); 106 } 107 108 @Test 109 110 @Override 111 public void runTest() 112 throws Exception 113 { 114 super.runTest(); 115 } 116 }