21
21
import java .util .Locale ;
22
22
import java .util .Map ;
23
23
24
+ import jakarta .el .ELContext ;
25
+ import jakarta .el .ELResolver ;
24
26
import jakarta .servlet .jsp .tagext .Tag ;
25
27
import org .junit .jupiter .api .AfterEach ;
26
28
import org .junit .jupiter .api .BeforeEach ;
37
39
import org .springframework .web .testfixture .servlet .MockPageContext ;
38
40
39
41
import static org .assertj .core .api .Assertions .assertThat ;
42
+ import static org .mockito .ArgumentMatchers .eq ;
43
+ import static org .mockito .ArgumentMatchers .isNull ;
44
+ import static org .mockito .ArgumentMatchers .same ;
45
+ import static org .mockito .BDDMockito .given ;
46
+ import static org .mockito .Mockito .mock ;
47
+ import static org .mockito .Mockito .spy ;
40
48
41
49
/**
42
50
* @author Keith Donald
@@ -52,11 +60,18 @@ class EvalTagTests extends AbstractTagTests {
52
60
void setup () {
53
61
LocaleContextHolder .setDefaultLocale (Locale .UK );
54
62
55
- context = createPageContext ();
63
+ context = spy (createPageContext ());
64
+ ELContext elContext = mock ();
65
+ ELResolver elResolver = mock ();
66
+ given (elResolver .getValue (same (elContext ), isNull (), eq ("pageContext" ))).willReturn (context );
67
+ given (elContext .getELResolver ()).willReturn (elResolver );
68
+ given (context .getELContext ()).willReturn (elContext );
69
+
56
70
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean ();
57
71
factory .afterPropertiesSet ();
58
72
context .getRequest ().setAttribute ("org.springframework.core.convert.ConversionService" , factory .getObject ());
59
73
context .getRequest ().setAttribute ("bean" , new Bean ());
74
+
60
75
tag = new EvalTag ();
61
76
tag .setPageContext (context );
62
77
}
@@ -181,6 +196,15 @@ void mapAccess() throws Exception {
181
196
assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("value" );
182
197
}
183
198
199
+ @ Test
200
+ void resolveImplicitVariable () throws Exception {
201
+ tag .setExpression ("pageContext.getClass().getSimpleName()" );
202
+ int action = tag .doStartTag ();
203
+ assertThat (action ).isEqualTo (Tag .EVAL_BODY_INCLUDE );
204
+ action = tag .doEndTag ();
205
+ assertThat (action ).isEqualTo (Tag .EVAL_PAGE );
206
+ assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("MockPageContext" );
207
+ }
184
208
185
209
186
210
public static class Bean {
0 commit comments