View Javadoc

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