001 /* 002 * $Id: OperatorTest.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.junit.runner.RunWith; 023 import org.junit.runners.Parameterized; 024 import org.junit.runners.Parameterized.Parameters; 025 026 import java.util.ArrayList; 027 import java.util.Collection; 028 029 @RunWith(value = Parameterized.class) 030 public class OperatorTest 031 extends OgnlTestCase 032 { 033 private static Object[][] TESTS = { { null, "\"one\" > \"two\"", Boolean.FALSE }, 034 { null, "\"one\" >= \"two\"", Boolean.FALSE }, { null, "\"one\" < \"two\"", Boolean.TRUE }, 035 { null, "\"one\" <= \"two\"", Boolean.TRUE }, { null, "\"one\" == \"two\"", Boolean.FALSE }, 036 { null, "\"o\" > \"o\"", Boolean.FALSE }, { null, "\"o\" gt \"o\"", Boolean.FALSE }, 037 { null, "\"o\" >= \"o\"", Boolean.TRUE }, { null, "\"o\" gte \"o\"", Boolean.TRUE }, 038 { null, "\"o\" < \"o\"", Boolean.FALSE }, { null, "\"o\" lt \"o\"", Boolean.FALSE }, 039 { null, "\"o\" <= \"o\"", Boolean.TRUE }, { null, "\"o\" lte \"o\"", Boolean.TRUE }, 040 { null, "\"o\" == \"o\"", Boolean.TRUE }, { null, "\"o\" eq \"o\"", Boolean.TRUE }, }; 041 042 /* 043 * =================================================================== Public static methods 044 * =================================================================== 045 */ 046 @Parameters 047 public static Collection<Object[]> data() 048 { 049 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length); 050 for ( int i = 0; i < TESTS.length; i++ ) 051 { 052 Object[] tmp = new Object[6]; 053 tmp[0] = TESTS[i][1]; 054 tmp[1] = TESTS[i][0]; 055 tmp[2] = TESTS[i][1]; 056 057 switch ( TESTS[i].length ) 058 { 059 case 3: 060 tmp[3] = TESTS[i][2]; 061 break; 062 063 case 4: 064 tmp[3] = TESTS[i][2]; 065 tmp[4] = TESTS[i][3]; 066 break; 067 068 case 5: 069 tmp[3] = TESTS[i][2]; 070 tmp[4] = TESTS[i][3]; 071 tmp[5] = TESTS[i][4]; 072 break; 073 074 default: 075 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length ); 076 } 077 078 data.add( tmp ); 079 } 080 return data; 081 } 082 083 /* 084 * =================================================================== Constructors 085 * =================================================================== 086 */ 087 public OperatorTest( String name, Object root, String expressionString, Object expectedResult, Object setValue, 088 Object expectedAfterSetResult ) 089 { 090 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult ); 091 } 092 }