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.*;
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 MethodTest
32 extends OgnlTestCase
33 {
34
35 private static Simple ROOT = new Simple();
36
37 private static ListSource LIST = new ListSourceImpl();
38
39 private static BaseGeneric<GameGenericObject, Long> GENERIC = new GameGeneric();
40
41 private static Object[][] TESTS = { { "hashCode()", new Integer( ROOT.hashCode() ) },
42 { "getBooleanValue() ? \"here\" : \"\"", "" }, { "getValueIsTrue(!false) ? \"\" : \"here\" ", "" },
43 { "messages.format('ShowAllCount', one)", "foo" },
44 { "getTestValue(@org.apache.commons.ognl.test.objects.SimpleEnum@ONE.value)", new Integer( 2 ) },
45 { "@org.apache.commons.ognl.test.MethodTest@getA().isProperty()", Boolean.FALSE },
46 { "isDisabled()", Boolean.TRUE }, { "isEditorDisabled()", Boolean.FALSE },
47 { LIST, "addValue(name)", Boolean.TRUE }, { "getDisplayValue(methodsTest.allowDisplay)", "test" },
48 { "isThisVarArgsWorking(three, rootValue)", Boolean.TRUE },
49 { GENERIC, "service.getFullMessageFor(value, null)", "Halo 3" } };
50
51 public static class A
52 {
53 public boolean isProperty()
54 {
55 return false;
56 }
57 }
58
59 public static A getA()
60 {
61 return new A();
62 }
63
64
65
66
67
68 @Parameters
69 public static Collection<Object[]> data()
70 {
71 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
72 for ( int i = 0; i < TESTS.length; i++ )
73 {
74 Object[] tmp = new Object[6];
75
76 if ( TESTS[i].length == 3 )
77 {
78 tmp[0] = TESTS[i][1] + " (" + TESTS[i][2] + ")";
79 tmp[1] = TESTS[i][0];
80 tmp[2] = TESTS[i][1];
81 tmp[3] = TESTS[i][2];
82 }
83 else
84 {
85 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
86 tmp[1] = ROOT;
87 tmp[2] = TESTS[i][0];
88 tmp[3] = TESTS[i][1];
89 }
90
91 data.add( tmp );
92 }
93 return data;
94 }
95
96
97
98
99
100 public MethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
101 Object expectedAfterSetResult )
102 {
103 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
104 }
105 }