EasyMock + Spring的Mock

本来想模拟JSF的
FacesContext.getCurrentInstance().getExternalContext().getRequest()
来获得Principal 但发现比较麻烦,所以只实现模拟HttpServletRequest

使用EasyMock + Spring的MockObject做较为简单

Principal principal = EasyMock.createMock(Principal.class);
expect(principal.getName()).andReturn("JUDYEUNG");
MockHttpServletRequest request = new MockHttpServletRequest();
replay(principal);

request.setUserPrincipal(principal);

uploadBean.setRequest(request);

你可能感兴趣的:(EasyMock + Spring的Mock)