大家好,又见面了,我是你们的朋友全栈君。
private PayController payController;
private HttpServletRequest request;
private User user;
private HttpSession session;
@Before
public void before(){
payController=new PayController();
user=new User();
user.setUsername("18350591915");
user.setUseNo("4f62f0e5516346748843df6131072ae0");
}
@Test
public void Testalipay_notify(){
request=EasyMock.createMock(HttpServletRequest.class);
session=EasyMock.createMock(HttpSession.class);
EasyMock.expect(request.getParameter("type")).andReturn("1");
EasyMock.expect(request.getParameter("money")).andReturn("1");
EasyMock.expect(request.getParameter("paymentId")).andReturn("1");
//EasyMock.expect((User)request.getSession().getAttribute("user")).andReturn(user);
//这句话不知道为什么不能实现``
EasyMock.expect(request.getSession()).andReturn(session);
EasyMock.expect(session.getAttribute("user")).andReturn(user);
EasyMock.replay(request);
assertNotNull(payController.recharge(null, request));
EasyMock.verify(request);
}
参考http://blog.csdn.net/chjttony/article/details/14522771[参考地址](http://blog.csdn.net/chjttony/article/details/14522771%20%E5%8F%82%E8%80%83%E5%8D%9A%E5%AE%A2easymock)
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/128637.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...