2121import java .util .Locale ;
2222import java .util .Map ;
2323
24+ import jakarta .el .ELContext ;
25+ import jakarta .el .ELResolver ;
2426import jakarta .servlet .jsp .tagext .Tag ;
2527import org .junit .jupiter .api .AfterEach ;
2628import org .junit .jupiter .api .BeforeEach ;
2729import org .junit .jupiter .api .Test ;
2830
31+ import org .mockito .ArgumentMatchers ;
2932import org .springframework .context .i18n .LocaleContextHolder ;
3033import org .springframework .context .support .GenericApplicationContext ;
3134import org .springframework .core .env .MapPropertySource ;
3740import org .springframework .web .testfixture .servlet .MockPageContext ;
3841
3942import 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 ;
4049
4150/**
4251 * @author Keith Donald
@@ -52,7 +61,13 @@ class EvalTagTests extends AbstractTagTests {
5261 void setup () {
5362 LocaleContextHolder .setDefaultLocale (Locale .UK );
5463
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 );
5671 FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean ();
5772 factory .afterPropertiesSet ();
5873 context .getRequest ().setAttribute ("org.springframework.core.convert.ConversionService" , factory .getObject ());
@@ -181,7 +196,15 @@ void mapAccess() throws Exception {
181196 assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("value" );
182197 }
183198
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+ }
185208
186209 public static class Bean {
187210
0 commit comments