### Question:
CTSOperations implements SessionOperations { public void logout(Session session) throws SessionException { SessionID sessionID = session.getID(); if (sessionService.checkSessionLocal(sessionID)) { throw new SessionException("CTSOperations received a local session (only remote sessions expected)"); } remote.logout(session); } @Inject  CTSOperations(CTSPersistentStore cts, SessionAdapter adapter,
                         TokenIdFactory idFactory, SessionInfoFactory sessionInfoFactory,
                         SessionService sessionService, RemoteOperations remote,
                         @Named(SessionConstants.SESSION_DEBUG) Debug debug); SessionInfo refresh(Session session, boolean reset); void logout(Session session); @Override void destroy(Session requester, Session session); void setProperty(Session session, String name, String value);  }### Answer:
@Test(expectedExceptions = SessionException.class) public void shouldDThrowExceptionWhenGivenLocalSession() throws SessionException { SessionID mockSessionID = mock(SessionID.class); given(mockSession.getID()).willReturn(mockSessionID); given(mockSessionService.checkSessionLocal(mockSessionID)).willReturn(true); ctsOperations.logout(mockSession); }
@Test public void shouldDeleteRemoteTokenDuringLogout() throws SessionException, CoreTokenException { SessionID mockSessionID = mock(SessionID.class); given(mockSession.getID()).willReturn(mockSessionID); given(mockSessionService.checkSessionLocal(mockSessionID)).willReturn(false); ctsOperations.logout(mockSession); verify(mockRemote).logout(mockSession); }
@Test(expectedExceptions = SessionException.class) public void shouldNotDeleteLocalTokenDuringLogout() throws SessionException, CoreTokenException { SessionID mockSessionID = mock(SessionID.class); given(mockSession.getID()).willReturn(mockSessionID); given(mockSessionService.checkSessionLocal(mockSessionID)).willReturn(true); ctsOperations.logout(mockSession); }
@Test (expectedExceptions = SessionException.class) public void shouldThrowExceptionWhenDeleteFails() throws CoreTokenException, SessionException { SessionID mockSessionID = mock(SessionID.class); given(mockSession.getID()).willReturn(mockSessionID); doThrow(new SessionException("")).when(mockRemote).logout(mockSession); ctsOperations.logout(mockSession); }