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 java.util.ArrayList;
23 import java.util.Collection;
24
25 import org.apache.commons.ognl.test.objects.Root;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.junit.runners.Parameterized.Parameters;
30
31 @RunWith(value = Parameterized.class)
32 public class NullStringCatenationTest
33 extends OgnlTestCase
34 {
35
36 public static final String MESSAGE = "blarney";
37
38 private static Root ROOT = new Root();
39
40 private static Object[][] TESTS =
41 {
42
43 { ROOT, "\"bar\" + null", "barnull" },
44 { ROOT, "\"bar\" + nullObject", "barnull" },
45 { ROOT, "20.56 + nullObject", NullPointerException.class },
46 { ROOT, "(true ? 'tabHeader' : '') + (false ? 'tabHeader' : '')", "tabHeader" },
47 { ROOT, "theInt == 0 ? '5%' : theInt + '%'", "6%" },
48 { ROOT, "'width:' + width + ';'", "width:238px;" },
49 { ROOT, "theLong + '_' + index", "4_1" },
50 { ROOT, "'javascript:' + @org.apache.commons.ognl.test.NullStringCatenationTest@MESSAGE", "javascript:blarney" },
51 { ROOT, "printDelivery ? '' : 'javascript:deliverySelected(' + property.carrier + ',' + currentDeliveryId + ')'", "" },
52 { ROOT, "bean2.id + '_' + theInt", "1_6" }
53 };
54
55
56
57
58
59
60 @Parameters
61 public static Collection<Object[]> data()
62 {
63 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
64 for ( int i = 0; i < TESTS.length; i++ )
65 {
66 Object[] tmp = new Object[4];
67 tmp[0] = TESTS[i][1];
68 tmp[1] = TESTS[i][0];
69 tmp[2] = TESTS[i][1];
70 tmp[3] = TESTS[i][2];
71
72 data.add( tmp );
73 }
74 return data;
75 }
76
77
78
79
80
81 public NullStringCatenationTest( String name, Object root, String expressionString, Object expectedResult)
82 {
83 super( name, root, expressionString, expectedResult );
84 }
85
86 @Test
87 @Override
88 public void runTest() throws Exception
89 {
90 super.runTest();
91 }
92 }