Map paramMap = new LinkedHashMap();
Map sessionMap = new LinkedHashMap();
ActionSupport action = new ActionSupport();
action.addActionError("some action error 1");
action.addActionError("some action error 2");
action.addActionMessage("some action message 1");
action.addActionMessage("some action message 2");
action.addFieldError("field1", "some field error 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.put(ActionContext.SESSION, sessionMap);
// Mock (ActionInvocation)
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
EasyMock.expectLastCall().andReturn(actionContext);
EasyMock.expectLastCall().anyTimes();
mockActionInvocation.invoke();
EasyMock.expectLastCall().andReturn(Action.SUCCESS);
mockActionInvocation.getAction();
EasyMock.expectLastCall().andReturn(action);
EasyMock.expectLastCall().anyTimes();
mockActionInvocation.getResult();
EasyMock.expectLastCall().andReturn(new ServletActionRedirectResult());
EasyMock.replay(mockActionInvocation);
interceptor.init();
interceptor.intercept(mockActionInvocation);
interceptor.destroy();
assertEquals(3, sessionMap.size());
assertTrue(sessionMap.containsKey(MessageStoreInterceptor.actionErrorsSessionKey));
assertTrue(sessionMap.containsKey(MessageStoreInterceptor.actionMessagesSessionKey));
assertTrue(sessionMap.containsKey(MessageStoreInterceptor.fieldErrorsSessionKey));
List actionErrors = (List) sessionMap.get(MessageStoreInterceptor.actionErrorsSessionKey);
List actionMessages = (List) sessionMap.get(MessageStoreInterceptor.actionMessagesSessionKey);
Map fieldErrors = (Map) sessionMap.get(MessageStoreInterceptor.fieldErrorsSessionKey);
assertEquals(2, actionErrors.size());
assertEquals(2, actionMessages.size());
assertEquals(2, fieldErrors.size());
assertTrue(actionErrors.contains("some action error 1"));
assertTrue(actionErrors.contains("some action error 2"));
assertTrue(actionMessages.contains("some action message 1"));
assertTrue(actionMessages.contains("some action message 2"));
assertTrue(fieldErrors.containsKey("field1"));
assertTrue(fieldErrors.containsKey("field2"));
assertEquals(((List)fieldErrors.get("field1")).size(), 1);
assertEquals(((List)fieldErrors.get("field2")).size(), 1);
assertEquals(((List)fieldErrors.get("field1")).get(0), "some field error 1");
assertEquals(((List)fieldErrors.get("field2")).get(0), "some field error 2");
EasyMock.verify(mockActionInvocation);
action = new ActionSupport();
mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.invoke();
EasyMock.expectLastCall().andReturn(Action.SUCCESS);
sessionMap.put(MessageStoreInterceptor.actionErrorsSessionKey, actionErrors);
sessionMap.put(MessageStoreInterceptor.actionMessagesSessionKey, actionMessages);
sessionMap.put(MessageStoreInterceptor.fieldErrorsSessionKey, fieldErrors);
actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.put(ActionContext.SESSION, sessionMap);
mockActionInvocation.getInvocationContext();
EasyMock.expectLastCall().andReturn(actionContext);
EasyMock.expectLastCall().anyTimes();
mockActionInvocation.getAction();
EasyMock.expectLastCall().andReturn(action);
EasyMock.expectLastCall().anyTimes();
mockActionInvocation.getResult();
EasyMock.expectLastCall().andReturn(new ServletActionRedirectResult());
EasyMock.replay(mockActionInvocation);
interceptor.init();
interceptor.intercept(mockActionInvocation);
interceptor.destroy();
assertEquals(action.getActionErrors().size(), 2);
assertEquals(action.getActionMessages().size(), 2);
assertEquals(action.getFieldErrors().size(), 2);
assertTrue(action.getActionErrors().contains("some action error 1"));
assertTrue(action.getActionErrors().contains("some action error 2"));
assertTrue(action.getActionMessages().contains("some action message 1"));
assertTrue(action.getActionMessages().contains("some action message 2"));
assertEquals(((List)action.getFieldErrors().get("field1")).size(), 1);
assertEquals(((List)action.getFieldErrors().get("field2")).size(), 1);
assertEquals(((List)action.getFieldErrors().get("field1")).get(0), "some field error 1");
assertEquals(((List)action.getFieldErrors().get("field2")).get(0), "some field error 2");
EasyMock.verify(mockActionInvocation);
}