3030 * Unit tests for {@link MethodBasedEvaluationContext}.
3131 *
3232 * @author Stephane Nicoll
33+ * @author Juergen Hoeller
3334 * @author Sergey Podgurskiy
3435 */
3536public class MethodBasedEvaluationContextTests {
3637
3738 private final ParameterNameDiscoverer paramDiscover = new DefaultParameterNameDiscoverer ();
3839
40+
3941 @ Test
4042 public void simpleArguments () {
41- Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" ,
42- String .class , Boolean .class );
43- MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] {"test" , true });
43+ Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , String .class , Boolean .class );
44+ MethodBasedEvaluationContext context = createEvaluationContext (method , "test" , true );
4445
4546 assertEquals ("test" , context .lookupVariable ("a0" ));
4647 assertEquals ("test" , context .lookupVariable ("p0" ));
@@ -51,56 +52,80 @@ public void simpleArguments() {
5152 assertEquals (true , context .lookupVariable ("flag" ));
5253
5354 assertNull (context .lookupVariable ("a2" ));
55+ assertNull (context .lookupVariable ("p2" ));
5456 }
5557
5658 @ Test
5759 public void nullArgument () {
58- Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" ,
59- String .class , Boolean .class );
60- MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] {null , null });
60+ Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , String .class , Boolean .class );
61+ MethodBasedEvaluationContext context = createEvaluationContext (method , null , null );
6162
6263 assertNull (context .lookupVariable ("a0" ));
6364 assertNull (context .lookupVariable ("p0" ));
65+ assertNull (context .lookupVariable ("foo" ));
66+
67+ assertNull (context .lookupVariable ("a1" ));
68+ assertNull (context .lookupVariable ("p1" ));
69+ assertNull (context .lookupVariable ("flag" ));
6470 }
6571
6672 @ Test
6773 public void varArgEmpty () {
6874 Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , Boolean .class , String [].class );
6975 MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] {null });
7076
77+ assertNull (context .lookupVariable ("a0" ));
7178 assertNull (context .lookupVariable ("p0" ));
79+ assertNull (context .lookupVariable ("flag" ));
80+
81+ assertNull (context .lookupVariable ("a1" ));
7282 assertNull (context .lookupVariable ("p1" ));
83+ assertNull (context .lookupVariable ("vararg" ));
7384 }
7485
7586 @ Test
7687 public void varArgNull () {
7788 Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , Boolean .class , String [].class );
78- MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] { null , null } );
89+ MethodBasedEvaluationContext context = createEvaluationContext (method , null , null );
7990
91+ assertNull (context .lookupVariable ("a0" ));
8092 assertNull (context .lookupVariable ("p0" ));
93+ assertNull (context .lookupVariable ("flag" ));
94+
95+ assertNull (context .lookupVariable ("a1" ));
8196 assertNull (context .lookupVariable ("p1" ));
97+ assertNull (context .lookupVariable ("vararg" ));
8298 }
8399
84100 @ Test
85101 public void varArgSingle () {
86102 Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , Boolean .class , String [].class );
87- MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] { null , "hello" } );
103+ MethodBasedEvaluationContext context = createEvaluationContext (method , null , "hello" );
88104
105+ assertNull (context .lookupVariable ("a0" ));
89106 assertNull (context .lookupVariable ("p0" ));
107+ assertNull (context .lookupVariable ("flag" ));
108+
109+ assertEquals ("hello" , context .lookupVariable ("a1" ));
90110 assertEquals ("hello" , context .lookupVariable ("p1" ));
111+ assertEquals ("hello" , context .lookupVariable ("vararg" ));
91112 }
92113
93114 @ Test
94115 public void varArgMultiple () {
95116 Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , Boolean .class , String [].class );
96- MethodBasedEvaluationContext context = createEvaluationContext (method ,
97- new Object [] {null , new String []{"hello" , "hi" }});
117+ MethodBasedEvaluationContext context = createEvaluationContext (method , null , "hello" , "hi" );
98118
119+ assertNull (context .lookupVariable ("a0" ));
99120 assertNull (context .lookupVariable ("p0" ));
100- assertArrayEquals (new String []{"hello" , "hi" }, (String []) context .lookupVariable ("p1" ));
121+ assertNull (context .lookupVariable ("flag" ));
122+
123+ assertArrayEquals (new Object [] {"hello" , "hi" }, (Object []) context .lookupVariable ("a1" ));
124+ assertArrayEquals (new Object [] {"hello" , "hi" }, (Object []) context .lookupVariable ("p1" ));
125+ assertArrayEquals (new Object [] {"hello" , "hi" }, (Object []) context .lookupVariable ("vararg" ));
101126 }
102127
103- private MethodBasedEvaluationContext createEvaluationContext (Method method , Object [] args ) {
128+ private MethodBasedEvaluationContext createEvaluationContext (Method method , Object ... args ) {
104129 return new MethodBasedEvaluationContext (this , method , args , this .paramDiscover );
105130 }
106131
@@ -112,9 +137,7 @@ private void hello(String foo, Boolean flag) {
112137 }
113138
114139 private void hello (Boolean flag , String ... vararg ){
115-
116140 }
117-
118141 }
119142
120- }
143+ }
0 commit comments