im doing test for one method with junit and mockito. I want to test if a .setatribute in httpsession is ok.
This is my code:
@Test
@PrepareForTest({PortalUtil.class})
public void changeStagingSourceUrlValueLive(){
ActionRequest request = mock(ActionRequest.class);
ActionResponse response = mock(ActionResponse.class);
HttpSession httpSession = mock(HttpSession.class);
HttpServletRequest httpServletSession = mock(HttpServletRequest.class);
StagingActions stagingActions = new StagingActions();
PowerMockito.mockStatic(PortalUtil.class);
when(request.getParameter("stagingStatusIsUse")).thenReturn("false");
when(PortalUtil.getHttpServletRequest(request)).thenReturn(httpServletSession);
when(httpServletSession.getSession()).thenReturn(httpSession);
stagingActions.changeStagingSourceUrlValue(request, response);
String attribute = (String) httpSession.getAttribute(KeyConstants.STAGING_URL_STATUS_KEY.getKey());
assertFalse(Boolean.valueOf(attribute));
}
The method changeStagingSourceUrlValue is correct, im sure, but in my test, when i do a getAttribute always return me null. Must i to do anything before or after call my method to can get attributes of mock httpsession?.
Thanks.