package easymocktest;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import org.testng.Reporter;
public class TestUserController {
public UserController userController;
public HttpServletRequest request;
public User user;
public HttpSession session;
@Before
public void before(){
user=new User();
userController=new UserController();
request=EasyMock.createStrictMock(HttpServletRequest.class);
session=EasyMock.createStrictMock(HttpSession.class);
}
@Test
public void testValidatLogin() {
EasyMock.expect(request.getSession()).andReturn(session);
EasyMock.expect(session.getAttribute("user")).andReturn(user);
EasyMock.replay(request,session);
EasyMock.verify(request, session);
assertNotNull(userController.validatLogin(request).getStatus());
}
}
加了这句话EasyMock.verify(request, session);立马就通过了,不知道是什么原因。但是如果验证失败怎么办?