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 ;
27
29
import org .junit .jupiter .api .Test ;
28
30
31
+ import org .mockito .ArgumentMatchers ;
29
32
import org .springframework .context .i18n .LocaleContextHolder ;
30
33
import org .springframework .context .support .GenericApplicationContext ;
31
34
import org .springframework .core .env .MapPropertySource ;
37
40
import org .springframework .web .testfixture .servlet .MockPageContext ;
38
41
39
42
import static org .assertj .core .api .Assertions .assertThat ;
43
+ import static org .mockito .ArgumentMatchers .eq ;
44
+ import static org .mockito .ArgumentMatchers .isNull ;
45
+ import static org .mockito .ArgumentMatchers .same ;
46
+ import static org .mockito .Mockito .mock ;
47
+ import static org .mockito .Mockito .spy ;
48
+ import static org .mockito .Mockito .when ;
40
49
41
50
/**
42
51
* @author Keith Donald
@@ -52,7 +61,13 @@ class EvalTagTests extends AbstractTagTests {
52
61
void setup () {
53
62
LocaleContextHolder .setDefaultLocale (Locale .UK );
54
63
55
- context = createPageContext ();
64
+ context = spy (createPageContext ());
65
+ final ELContext elContext = mock (ELContext .class );
66
+ final ELResolver elResolver = when (mock (ELResolver .class ).getValue (same (elContext ), isNull (), eq ("pageContext" )))
67
+ .thenReturn (context )
68
+ .getMock ();
69
+ when (elContext .getELResolver ()).thenReturn (elResolver );
70
+ when (context .getELContext ()).thenReturn (elContext );
56
71
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean ();
57
72
factory .afterPropertiesSet ();
58
73
context .getRequest ().setAttribute ("org.springframework.core.convert.ConversionService" , factory .getObject ());
@@ -181,7 +196,15 @@ void mapAccess() throws Exception {
181
196
assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("value" );
182
197
}
183
198
184
-
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
+ }
185
208
186
209
public static class Bean {
187
210
0 commit comments