### Question:
AlreadyLoggedInRule extends AuthenticationRule { @Override public boolean doAuthorize(final HttpServletRequestAccessor request, HttpServletResponse response, final TenantIdAccessor tenantIdAccessor) throws ServletException { if (isUserAlreadyLoggedIn(request, tenantIdAccessor)) { ensureUserSession(request.asHttpServletRequest(), request.getHttpSession(), request.getApiSession()); return true; } return false; }  @Override boolean doAuthorize(final HttpServletRequestAccessor request, HttpServletResponse response, final TenantIdAccessor tenantIdAccessor);  }### Answer:
@Test public void testIfRuleAuthorizeAlreadyLoggedUser() throws Exception { doReturn(apiSession).when(request).getApiSession(); doReturn("").when(httpSession).getAttribute(SessionUtil.USER_SESSION_PARAM_KEY); final boolean authorization = rule.doAuthorize(request, response, tenantAccessor); assertThat(authorization, is(true)); }
@Test public void testIfRuleDoesntAuthorizeNullSession() throws Exception { doReturn(null).when(request).getApiSession(); final boolean authorization = rule.doAuthorize(request, response, tenantAccessor); assertFalse(authorization); }