### Question:
StatelessSSOToken implements SSOToken { public boolean isValid(boolean reset) { try { final int state = session.getState(reset); return (state == SessionConstants.VALID || state == SessionConstants.INACTIVE) && !session.isTimedOut(); } catch (SessionException e) { return false; } } StatelessSSOToken(StatelessSession session); boolean isValid(boolean reset); @Override Principal getPrincipal(); @Override String getAuthType(); @Override int getAuthLevel(); @Override InetAddress getIPAddress(); @Override String getHostName(); @Override long getTimeLeft(); @Override long getMaxSessionTime(); @Override long getIdleTime(); @Override long getMaxIdleTime(); @Override SSOTokenID getTokenID(); @Override void setProperty(String name, String value); @Override String getProperty(String name); @Override String getProperty(String name, boolean ignoreState); @Override void addSSOTokenListener(SSOTokenListener listener); @Override String encodeURL(String url); @Override boolean isTokenRestricted(); @Override String dereferenceRestrictedTokenID(SSOToken requester, String restrictedId); @Override String toString();  }### Answer:
@Test public void shouldBeInvalidIfTimedOut() throws Exception { given(mockSession.isTimedOut()).willReturn(true); given(mockSession.getState(false)).willReturn(SessionConstants.VALID); assertFalse(statelessSSOToken.isValid(false)); }
@Test(dataProvider = "sessionStates") public void shouldBeInvalidIfNotValidOrInactive(int state) throws Exception { given(mockSession.isTimedOut()).willReturn(false); given(mockSession.getState(false)).willReturn(state); boolean result = statelessSSOToken.isValid(false); if (state == SessionConstants.INACTIVE || state == SessionConstants.VALID) { assertTrue(result, "Token should be valid in state: " + state); } else { assertFalse(result, "Token should NOT be valid in state: " + state); } }