1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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
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 }