File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
main/java/org/apache/struts2/dispatcher
test/java/org/apache/struts2/dispatcher Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ public Object get(Object key) {
86
86
87
87
PageContext pc = getPageContext ();
88
88
89
- if (pc == null ) {
89
+ if (pc == null || pc . getRequest () == null ) {
90
90
RequestMap request = (RequestMap ) context .get (DispatcherConstants .REQUEST );
91
91
SessionMap session = (SessionMap ) context .get (DispatcherConstants .SESSION );
92
92
ApplicationMap application = (ApplicationMap ) context .get (DispatcherConstants .APPLICATION );
Original file line number Diff line number Diff line change 40
40
import static org .junit .Assert .assertNull ;
41
41
import static org .junit .Assert .assertThrows ;
42
42
import static org .junit .Assert .assertTrue ;
43
+ import static org .mockito .ArgumentMatchers .anyString ;
44
+ import static org .mockito .Mockito .mock ;
45
+ import static org .mockito .Mockito .never ;
46
+ import static org .mockito .Mockito .verify ;
47
+ import static org .mockito .Mockito .when ;
43
48
44
49
public class AttributeMapTest {
45
50
@@ -360,4 +365,21 @@ public void shouldContainsKey() {
360
365
assertEquals ("value" , value );
361
366
}
362
367
363
- }
368
+ @ Test
369
+ public void get_whenPageContextHasNoRequest () {
370
+ PageContext pageContext = mock (PageContext .class );
371
+ when (pageContext .getRequest ()).thenReturn (null );
372
+
373
+ HttpServletRequest req = new MockHttpServletRequest ();
374
+ req .setAttribute ("attr" , "reqValue" );
375
+
376
+ AttributeMap attributeMap = new AttributeMap (new HashMap <String , Object >() {{
377
+ put (StrutsStatics .PAGE_CONTEXT , pageContext );
378
+ put (DispatcherConstants .REQUEST , new RequestMap (req ));
379
+ }});
380
+
381
+ assertEquals ("reqValue" , attributeMap .get ("attr" ));
382
+ verify (pageContext , never ()).findAttribute (anyString ());
383
+ }
384
+
385
+ }
You can’t perform that action at this time.
0 commit comments