### Question:
StatelessOperations implements SessionOperations { @Override public void destroy(final Session requester, final Session session) throws SessionException { sessionService.checkPermissionToDestroySession(requester, session.getID()); if (session instanceof StatelessSession) { SessionInfo sessionInfo = statelessSessionFactory.getSessionInfo(session.getID()); sessionLogging.logEvent(sessionInfo, SessionEvent.DESTROY); if (sessionAuditor != null) { sessionAuditor.auditActivity(sessionInfo, AM_SESSION_DESTROYED); } } try { sessionBlacklist.blacklist(session); } catch (BlacklistException e) { throw new SessionException(e); } } @Inject  StatelessOperations(final LocalOperations localOperations,
                               final SessionService sessionService,
                               final StatelessSessionFactory statelessSessionFactory,
                               final Blacklist<Session> sessionBlacklist,
                               final SessionLogging sessionLogging,
                               final SessionAuditor sessionAuditor); @Override SessionInfo refresh(final Session session, final boolean reset); @Override void logout(final Session session); @Override void destroy(final Session requester, final Session session); @Override void setProperty(final Session session, final String name, final String value);  }### Answer:
@Test public void shouldCheckPermissionToDestroySession() throws Exception { Session requester = mock(Session.class); statelessOperations.destroy(requester, mockSession); verify(mockSessionService).checkPermissionToDestroySession(requester, sid); }
@Test public void shouldBlacklistSessionOnDestroyWhenAllowed() throws Exception { Session requester = mock(Session.class); statelessOperations.destroy(requester, mockSession); verify(mockSessionLogging).logEvent( mockSessionFactory.getSessionInfo(mockSession.getSessionID()), SessionEvent.DESTROY); verify(mockSessionBlacklist).blacklist(mockSession); }
@Test(expectedExceptions = SessionException.class, expectedExceptionsMessageRegExp = "test") public void shouldNotBlacklistSessionOnDestroyIfNotAllowed() throws Exception { Session requester = mock(Session.class); SessionException ex = new SessionException("test"); willThrow(ex).given(mockSessionService).checkPermissionToDestroySession(requester, sid); try { statelessOperations.destroy(requester, mockSession); } finally { verifyZeroInteractions(mockSessionBlacklist); } }