MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
interceptor.setOperationMode(MessageStoreInterceptor.RETRIEVE_MODE);
interceptor.setAllowRequestParameterSwitch(true);
ActionSupport action = new ActionSupport();
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.invoke();
EasyMock.expectLastCall().andReturn(Action.SUCCESS);
Map paramsMap = new LinkedHashMap();
Map sessionMap = new LinkedHashMap();
List actionErrors = new ArrayList();
List actionMessages = new ArrayList();
Map fieldErrors = new LinkedHashMap();
actionErrors.add("some action error 1");
actionErrors.add("some action error 2");
actionMessages.add("some action messages 1");
actionMessages.add("some action messages 2");
List field1Errors = new ArrayList();
field1Errors.add("some field error 1");
List field2Errors = new ArrayList();
field2Errors.add("some field error 2");
fieldErrors.put("field1", field1Errors);
fieldErrors.put("field2", field2Errors);
sessionMap.put(MessageStoreInterceptor.actionErrorsSessionKey, actionErrors);
sessionMap.put(MessageStoreInterceptor.actionMessagesSessionKey, actionMessages);
sessionMap.put(MessageStoreInterceptor.fieldErrorsSessionKey, fieldErrors);
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramsMap);
actionContext.put(ActionContext.SESSION, sessionMap);
mockActionInvocation.getInvocationContext();
EasyMock.expectLastCall().andReturn(actionContext);
EasyMock.expectLastCall().anyTimes();
mockActionInvocation.getAction();
EasyMock.expectLastCall().andReturn(action);
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 messages 1"));
assertTrue(action.getActionMessages().contains("some action messages 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);
}