Logout { @POST public LoginResult doLogout() { Subject subject = SecurityUtils.getSubject(); subject.logout(); return new LoginResult(""); }  @POST LoginResult doLogout();  }
@Test public void testLogoutOk() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpSession session = mock(HttpSession.class); when(request.getSession()).thenReturn(session); HttpServletResponse response = mock(HttpServletResponse.class); MockLogService logservice = new MockLogService(); loginUser(request, response, "jad", "1ad"); Logout resource = new Logout(); resource.logservice = logservice; LoginResult result = resource.doLogout(); assertEquals(0, result.getRoles().length); assertEquals("", result.getErrorMessage()); }
@Test public void testLogoutNotLoggedIn() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); MockLogService logservice = new MockLogService(); createSubjectAndBindItToThread(request, response); Logout resource = new Logout(); resource.logservice = logservice; LoginResult result = resource.doLogout(); assertEquals(0, result.getRoles().length); assertEquals("", result.getErrorMessage()); }