39
39
import org .springframework .web .testfixture .servlet .MockPageContext ;
40
40
41
41
import static org .assertj .core .api .Assertions .assertThat ;
42
+ import static org .mockito .ArgumentMatchers .any ;
42
43
import static org .mockito .ArgumentMatchers .eq ;
43
44
import static org .mockito .ArgumentMatchers .isNull ;
44
- import static org .mockito .ArgumentMatchers .same ;
45
45
import static org .mockito .BDDMockito .given ;
46
46
import static org .mockito .Mockito .mock ;
47
- import static org .mockito .Mockito .spy ;
48
47
49
48
/**
50
49
* @author Keith Donald
@@ -60,15 +59,9 @@ class EvalTagTests extends AbstractTagTests {
60
59
void setup () {
61
60
LocaleContextHolder .setDefaultLocale (Locale .UK );
62
61
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
-
70
62
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean ();
71
63
factory .afterPropertiesSet ();
64
+ context = createPageContext ();
72
65
context .getRequest ().setAttribute ("org.springframework.core.convert.ConversionService" , factory .getObject ());
73
66
context .getRequest ().setAttribute ("bean" , new Bean ());
74
67
@@ -198,12 +191,18 @@ void mapAccess() throws Exception {
198
191
199
192
@ Test
200
193
void resolveImplicitVariable () throws Exception {
194
+ ELContext elContext = mock ();
195
+ ELResolver elResolver = mock ();
196
+ given (elContext .getELResolver ()).willReturn (elResolver );
197
+ given (elResolver .getValue (any (ELContext .class ), isNull (), eq ("pageContext" ))).willReturn (context );
198
+ ((ExtendedMockPageContext ) context ).setELContext (elContext );
199
+
201
200
tag .setExpression ("pageContext.getClass().getSimpleName()" );
202
201
int action = tag .doStartTag ();
203
202
assertThat (action ).isEqualTo (Tag .EVAL_BODY_INCLUDE );
204
203
action = tag .doEndTag ();
205
204
assertThat (action ).isEqualTo (Tag .EVAL_PAGE );
206
- assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("MockPageContext " );
205
+ assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("ExtendedMockPageContext " );
207
206
}
208
207
209
208
0 commit comments