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.apache.commons.ognl.test.objects.Simple;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.Parameterized;
26 import org.junit.runners.Parameterized.Parameters;
27
28 import java.util.ArrayList;
29 import java.util.Collection;
30
31 @RunWith(value = Parameterized.class)
32 public class MethodWithConversionTest
33 extends OgnlTestCase
34 {
35
36 private static Simple SIMPLE = new Simple();
37
38 private static Object[][] TESTS = {
39
40 { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null }, { SIMPLE, "stringValue", "10" },
41 { SIMPLE, "stringValue", "10", new Character( 'x' ), "x" },
42 { SIMPLE, "setStringValue('x')", null },
43 { SIMPLE, "floatValue", new Float( 10.56 ) }, { SIMPLE, "getValueIsTrue(rootValue)", Boolean.TRUE },
44 { SIMPLE, "messages.format('Testing', one, two, three)", "blah" } };
45
46
47
48
49
50 @Parameters
51 public static Collection<Object[]> data()
52 {
53 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
54 for ( int i = 0; i < TESTS.length; i++ )
55 {
56 Object[] tmp = new Object[6];
57 tmp[0] = TESTS[i][1];
58 tmp[1] = TESTS[i][0];
59 tmp[2] = TESTS[i][1];
60
61 switch ( TESTS[i].length )
62 {
63 case 3:
64 tmp[3] = TESTS[i][2];
65 break;
66
67 case 4:
68 tmp[3] = TESTS[i][2];
69 tmp[4] = TESTS[i][3];
70 break;
71
72 case 5:
73 tmp[3] = TESTS[i][2];
74 tmp[4] = TESTS[i][3];
75 tmp[5] = TESTS[i][4];
76 break;
77
78 default:
79 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
80 }
81
82 data.add( tmp );
83 }
84 return data;
85 }
86
87
88
89
90
91 public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult,
92 Object setValue, Object expectedAfterSetResult )
93 {
94 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
95 }
96
97 @Test
98
99 @Override
100 public void runTest()
101 throws Exception
102 {
103 super.runTest();
104 }
105 }