### Question:
StatelessSessionActivator extends DefaultSessionActivator { @Override public boolean activateSession(final LoginState loginState, final SessionService sessionService, final InternalSession authSession, final Subject subject, final Object loginContext) throws AuthException { if (loginState.getForceFlag()) { if (DEBUG.messageEnabled()) { DEBUG.message("Cannot force auth stateless sessions."); } throw new AuthException(AMAuthErrorCode.STATELESS_FORCE_FAILED, null); } if (loginState.isSessionUpgrade()) { SessionID sid = new SessionID(loginState.getHttpServletRequest()); try { SessionInfo info = getStatelessSessionFactory().getSessionInfo(sid); oldSession = getStatelessSessionFactory().generate(info); loginState.setOldStatelessSession(oldSession); } catch (SessionException e) { throw new AuthException(AMAuthErrorCode.SESSION_UPGRADE_FAILED, null); } } final InternalSession session = createSession(sessionService, loginState); loginState.setSession(session); return updateSessions(session, loginState, session, authSession, sessionService, subject, loginContext); } @VisibleForTesting  StatelessSessionActivator(final StatelessSessionFactory statelessSessionFactory); private  StatelessSessionActivator(); @Override boolean activateSession(final LoginState loginState, final SessionService sessionService,
                                   final InternalSession authSession, final Subject subject, final Object loginContext);  }### Answer:
@Test public void shouldActivateStatelessSessions() throws Exception { InternalSession mockSession = mock(InternalSession.class); String userDn = "fred"; given(mockLoginState.getUserDN()).willReturn(userDn); testActivator.activateSession(mockSession, mockLoginState); verify(mockSession).activate(userDn, true); }
@Test public void shouldGenerateStatelessSessionId() throws Exception { InternalSession mockSession = mock(InternalSession.class); String userDn = "fred"; given(mockLoginState.getUserDN()).willReturn(userDn); given(mockSession.activate(userDn, true)).willReturn(true); StatelessSession mockStatelessSession = mock(StatelessSession.class); given(mockSessionFactory.generate(mockSession)).willReturn(mockStatelessSession); SessionID statelessSessionId = new SessionID("stateless"); given(mockStatelessSession.getID()).willReturn(statelessSessionId); testActivator.activateSession(mockSession, mockLoginState); verify(mockSessionFactory).generate(mockSession); verify(mockLoginState).setSessionID(statelessSessionId); }
@Test public void shouldEnsureSessionIsNotScheduled() throws Exception { InternalSession mockSession = mock(InternalSession.class); testActivator.activateSession(mockSession, mockLoginState); verify(mockSession).cancel(); }