Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
*/ |
17 |
package javax.el; |
18 |
|
19 |
import java.lang.reflect.Method; |
20 |
import java.util.HashMap; |
21 |
import java.util.Map; |
22 |
|
23 |
import javax.el.BeanELResolver; |
24 |
import javax.el.ELContext; |
25 |
import javax.el.ELResolver; |
26 |
import javax.el.FunctionMapper; |
27 |
import javax.el.ValueExpression; |
28 |
import javax.el.VariableMapper; |
29 |
|
30 |
import org.junit.Assert; |
31 |
import org.junit.Before; |
32 |
import org.junit.Test; |
33 |
|
34 |
public class TestBeanELResolverVarargsInvocation { |
35 |
public static class Foo { |
36 |
|
37 |
public String joinDelimited(String delim, String... strings) { |
38 |
StringBuilder result = new StringBuilder(); |
39 |
if (strings != null) { |
40 |
for (String s : strings) { |
41 |
if (delim != null && result.length() > 0) { |
42 |
result.append(delim); |
43 |
} |
44 |
result.append(s); |
45 |
} |
46 |
} |
47 |
return result.toString(); |
48 |
} |
49 |
|
50 |
public String join(String... strings) { |
51 |
return joinDelimited(null, strings); |
52 |
} |
53 |
} |
54 |
|
55 |
private Foo foo; |
56 |
private ELContext elContext; |
57 |
private BeanELResolver beanELResolver; |
58 |
|
59 |
@Before |
60 |
public void setup() { |
61 |
foo = new Foo(); |
62 |
beanELResolver = new BeanELResolver(); |
63 |
elContext = new ELContext() { |
64 |
private VariableMapper variableMapper = new VariableMapper() { |
65 |
private Map<String, ValueExpression> vars = new HashMap<String, ValueExpression>(); |
66 |
|
67 |
@Override |
68 |
public ValueExpression setVariable(String arg0, ValueExpression arg1) { |
69 |
return vars.put(arg0, arg1); |
70 |
} |
71 |
|
72 |
@Override |
73 |
public ValueExpression resolveVariable(String arg0) { |
74 |
return vars.get(arg0); |
75 |
} |
76 |
}; |
77 |
private FunctionMapper functionMapper = new FunctionMapper() { |
78 |
|
79 |
@Override |
80 |
public Method resolveFunction(String arg0, String arg1) { |
81 |
return null; |
82 |
} |
83 |
}; |
84 |
|
85 |
@Override |
86 |
public VariableMapper getVariableMapper() { |
87 |
return variableMapper; |
88 |
} |
89 |
|
90 |
@Override |
91 |
public FunctionMapper getFunctionMapper() { |
92 |
return functionMapper; |
93 |
} |
94 |
|
95 |
@Override |
96 |
public ELResolver getELResolver() { |
97 |
return beanELResolver; |
98 |
} |
99 |
}; |
100 |
} |
101 |
|
102 |
/** |
103 |
* Tests varargs that come after an opening argument. |
104 |
*/ |
105 |
@Test |
106 |
public void testJoinDelimited() { |
107 |
Assert.assertEquals(foo.joinDelimited("-", "foo", "bar", "baz"), |
108 |
beanELResolver.invoke(elContext, foo, "joinDelimited", null, new Object[] { "-", "foo", "bar", "baz" })); |
109 |
} |
110 |
|
111 |
/** |
112 |
* Tests varargs that constitute a method's only parameters, as well as bogus results |
113 |
* due to improper matching of ANY vararg method, and depending on the order in which |
114 |
* reflected methods are encountered. |
115 |
*/ |
116 |
@Test |
117 |
public void testJoin() { |
118 |
Assert.assertEquals(foo.join("foo", "bar", "baz"), |
119 |
beanELResolver.invoke(elContext, foo, "join", null, new Object[] { "foo", "bar", "baz" })); |
120 |
} |
121 |
|
122 |
} |
0 |
+ native |
123 |
+ native |