30
30
* Unit tests for {@link MethodBasedEvaluationContext}.
31
31
*
32
32
* @author Stephane Nicoll
33
+ * @author Juergen Hoeller
33
34
* @author Sergey Podgurskiy
34
35
*/
35
36
public class MethodBasedEvaluationContextTests {
36
37
37
38
private final ParameterNameDiscoverer paramDiscover = new DefaultParameterNameDiscoverer ();
38
39
40
+
39
41
@ Test
40
42
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 );
44
45
45
46
assertEquals ("test" , context .lookupVariable ("a0" ));
46
47
assertEquals ("test" , context .lookupVariable ("p0" ));
@@ -51,56 +52,80 @@ public void simpleArguments() {
51
52
assertEquals (true , context .lookupVariable ("flag" ));
52
53
53
54
assertNull (context .lookupVariable ("a2" ));
55
+ assertNull (context .lookupVariable ("p2" ));
54
56
}
55
57
56
58
@ Test
57
59
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 );
61
62
62
63
assertNull (context .lookupVariable ("a0" ));
63
64
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" ));
64
70
}
65
71
66
72
@ Test
67
73
public void varArgEmpty () {
68
74
Method method = ReflectionUtils .findMethod (SampleMethods .class , "hello" , Boolean .class , String [].class );
69
75
MethodBasedEvaluationContext context = createEvaluationContext (method , new Object [] {null });
70
76
77
+ assertNull (context .lookupVariable ("a0" ));
71
78
assertNull (context .lookupVariable ("p0" ));
79
+ assertNull (context .lookupVariable ("flag" ));
80
+
81
+ assertNull (context .lookupVariable ("a1" ));
72
82
assertNull (context .lookupVariable ("p1" ));
83
+ assertNull (context .lookupVariable ("vararg" ));
73
84
}
74
85
75
86
@ Test
76
87
public void varArgNull () {
77
88
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 );
79
90
91
+ assertNull (context .lookupVariable ("a0" ));
80
92
assertNull (context .lookupVariable ("p0" ));
93
+ assertNull (context .lookupVariable ("flag" ));
94
+
95
+ assertNull (context .lookupVariable ("a1" ));
81
96
assertNull (context .lookupVariable ("p1" ));
97
+ assertNull (context .lookupVariable ("vararg" ));
82
98
}
83
99
84
100
@ Test
85
101
public void varArgSingle () {
86
102
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" );
88
104
105
+ assertNull (context .lookupVariable ("a0" ));
89
106
assertNull (context .lookupVariable ("p0" ));
107
+ assertNull (context .lookupVariable ("flag" ));
108
+
109
+ assertEquals ("hello" , context .lookupVariable ("a1" ));
90
110
assertEquals ("hello" , context .lookupVariable ("p1" ));
111
+ assertEquals ("hello" , context .lookupVariable ("vararg" ));
91
112
}
92
113
93
114
@ Test
94
115
public void varArgMultiple () {
95
116
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" );
98
118
119
+ assertNull (context .lookupVariable ("a0" ));
99
120
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" ));
101
126
}
102
127
103
- private MethodBasedEvaluationContext createEvaluationContext (Method method , Object [] args ) {
128
+ private MethodBasedEvaluationContext createEvaluationContext (Method method , Object ... args ) {
104
129
return new MethodBasedEvaluationContext (this , method , args , this .paramDiscover );
105
130
}
106
131
@@ -112,9 +137,7 @@ private void hello(String foo, Boolean flag) {
112
137
}
113
138
114
139
private void hello (Boolean flag , String ... vararg ){
115
-
116
140
}
117
-
118
141
}
119
142
120
- }
143
+ }
0 commit comments