View Javadoc

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