@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();
// Set up some fake HTTP requests
// If the user isn't logged in, use this request
when(mockRequestNotLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
when(mockRequestNotLoggedIn.getUserPrincipal()).thenReturn(null);
// If the user is logged in, use this request
when(mockRequestLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
// Most of the classes that implement Principal have been
// deprecated. JMXPrincipal seems like a safe choice.
when(mockRequestLoggedIn.getUserPrincipal()).thenReturn(new JMXPrincipal(FAKE_NAME));
// Set up a fake HTTP response.
responseWriter = new StringWriter();
when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter));
servletUnderTest = new UsersServlet();
}
UsersServletTest.java 文件源码
java
阅读 17
收藏 0
点赞 0
评论 0
项目:java-docs-samples
作者:
评论列表
文章目录