View Javadoc

1   /*
2    * $Id: NullHandlerTest.java 1188000 2011-10-23 23:10:24Z 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 org.apache.commons.ognl.OgnlRuntime;
23  import org.apache.commons.ognl.test.objects.CorrectedObject;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.Parameterized;
28  import org.junit.runners.Parameterized.Parameters;
29  
30  import java.util.ArrayList;
31  import java.util.Collection;
32  
33  @RunWith(value = Parameterized.class)
34  public class NullHandlerTest
35      extends OgnlTestCase
36  {
37      private static CorrectedObject CORRECTED = new CorrectedObject();
38  
39      private static Object[][] TESTS = {
40          // NullHandler
41          { CORRECTED, "stringValue", "corrected" }, { CORRECTED, "getStringValue()", "corrected" },
42          { CORRECTED, "#root.stringValue", "corrected" }, { CORRECTED, "#root.getStringValue()", "corrected" }, };
43  
44      /*
45       * =================================================================== Public static methods
46       * ===================================================================
47       */
48      @Parameters
49      public static Collection<Object[]> data()
50      {
51          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
52          for ( int i = 0; i < TESTS.length; i++ )
53          {
54              Object[] tmp = new Object[6];
55              tmp[0] = TESTS[i][1];
56              tmp[1] = TESTS[i][0];
57              tmp[2] = TESTS[i][1];
58  
59              switch ( TESTS[i].length )
60              {
61                  case 3:
62                      tmp[3] = TESTS[i][2];
63                      break;
64  
65                  case 4:
66                      tmp[3] = TESTS[i][2];
67                      tmp[4] = TESTS[i][3];
68                      break;
69  
70                  case 5:
71                      tmp[3] = TESTS[i][2];
72                      tmp[4] = TESTS[i][3];
73                      tmp[5] = TESTS[i][4];
74                      break;
75  
76                  default:
77                      throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
78              }
79  
80              data.add( tmp );
81          }
82          return data;
83      }
84  
85      /*
86       * =================================================================== Constructors
87       * ===================================================================
88       */
89      public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
90                              Object expectedAfterSetResult )
91      {
92          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
93      }
94  
95      /*
96       * =================================================================== Overridden methods
97       * ===================================================================
98       */
99      @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 }