### Question:
AttributePrincipalProxyTicketProvider implements ProxyTicketProvider { @Override public String getProxyTicket(String service) { Assert.hasText(service, "service cannot not be null or blank"); Assertion assertion = assertionProvider.getAssertion(); AttributePrincipal principal = assertion.getPrincipal(); if (principal == null) { throw new IllegalStateException(String.format(EXCEPTION_MESSAGE, AttributePrincipal.class.getSimpleName())); } return principal.getProxyTicketFor(service); } AttributePrincipalProxyTicketProvider(AssertionProvider assertionProvider); @Override String getProxyTicket(String service);  }### Answer:
@Test public void getProxyTicket_NullAttributePrincipal_IllegalStateException() { String service = "http: Assertion assertion = mock(Assertion.class); when(assertionProvider.getAssertion()).thenReturn(assertion); when(assertion.getPrincipal()).thenReturn(null); assertThatThrownBy(() -> proxyTicketProvider.getProxyTicket(service)) .isInstanceOf(IllegalStateException.class) .hasMessage("Unable to provide a proxy ticket with null %s", AttributePrincipal.class.getSimpleName()); verify(assertionProvider, times(1)).getAssertion(); verify(assertion, times(1)).getPrincipal(); }
@Test public void getProxyTicket_ValidService_ProxyTicketValue() { String service = "http: Assertion assertion = mock(Assertion.class); AttributePrincipal attributePrincipal = mock(AttributePrincipal.class); when(assertionProvider.getAssertion()).thenReturn(assertion); when(assertion.getPrincipal()).thenReturn(attributePrincipal); when(attributePrincipal.getProxyTicketFor(service)).thenReturn("ST-21-c1gk6jBcfYnatLbNExfx-0623277bc36a"); assertThat(proxyTicketProvider.getProxyTicket(service)).isEqualTo("ST-21-c1gk6jBcfYnatLbNExfx-0623277bc36a"); verify(assertionProvider, times(1)).getAssertion(); verify(assertion, times(1)).getPrincipal(); verify(attributePrincipal, times(1)).getProxyTicketFor(service); }