### Question:
StatelessAdminRestriction { public boolean isRestricted(SSOToken token) throws SessionException { Reject.ifNull(token); if (!factory.containsJwt(token.toString())) { throw new SessionException("Not a Stateless Session"); } try { return isRestricted(token.getPrincipal().getName()); } catch (SSOException e) { throw new SessionException(e); } } @Inject  StatelessAdminRestriction(SuperUserDelegate delegate, StatelessSessionFactory factory); boolean isRestricted(SSOToken token); boolean isRestricted(String userDN); static SuperUserDelegate createAuthDDelegate();  }### Answer:
@Test(expectedExceptions = NullPointerException.class) public void shouldNotAllowNullSSOToken() throws SessionException { restriction.isRestricted((SSOToken)null); }
@Test(expectedExceptions = NullPointerException.class) public void shouldNotAllowNullUserDN() throws SessionException { restriction.isRestricted((String)null); }
@Test (expectedExceptions = SessionException.class) public void shouldErrorForNonStatelessSession() throws SessionException { given(mockFactory.containsJwt(anyString())).willReturn(false); SSOToken token = mock(SSOToken.class); given(token.toString()).willReturn("badger"); restriction.isRestricted(token); }
@Test (expectedExceptions = SessionException.class) public void shouldHandleErrorProcessingSSOToken() throws SessionException, SSOException { given(mockFactory.containsJwt(anyString())).willReturn(true); SSOToken token = mock(SSOToken.class); given(token.toString()).willReturn("badger"); given(token.getPrincipal()).willThrow(new SSOException("TEST")); restriction.isRestricted(token); }
@Test public void shouldIndicateTrueForAdminToken() throws SSOException, SessionException { given(mockFactory.containsJwt(anyString())).willReturn(true); SSOToken token = mock(SSOToken.class); given(token.toString()).willReturn("badger"); Principal mockPrincipal = mock(Principal.class); given(token.getPrincipal()).willReturn(mockPrincipal); given(mockPrincipal.getName()).willReturn("badger"); given(mockDelegate.isSuperUser(anyString())).willReturn(true); boolean result = restriction.isRestricted(token); assertThat(result).isTrue(); }