### Question:
IdpSingleSignOnServiceHelper { public URI getSingleSignOn(String entityId) { EntityDescriptor idpEntityDescriptor; try { CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(entityId)); idpEntityDescriptor = metadataProvider.resolveSingle(criteria); } catch (ResolverException e) { LOG.error(format("Exception when accessing metadata: {0}", e)); throw new RuntimeException(e); } if(idpEntityDescriptor!=null) { final IDPSSODescriptor idpssoDescriptor = idpEntityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS); final List<SingleSignOnService> singleSignOnServices = idpssoDescriptor.getSingleSignOnServices(); if (singleSignOnServices.isEmpty()) { LOG.error(format("No singleSignOnServices present for IDP entityId: {0}", entityId)); } else { if (singleSignOnServices.size() > 1) { LOG.warn(format("More than one singleSignOnService present: {0} for {1}", singleSignOnServices.size(), entityId)); } return URI.create(singleSignOnServices.get(0).getLocation()); } } throw ApplicationException.createUnauditedException(ExceptionType.NOT_FOUND, UUID.randomUUID(), new RuntimeException(format("no entity descriptor for IDP: {0}", entityId))); } @Inject  IdpSingleSignOnServiceHelper(@Named("VerifyMetadataResolver") MetadataResolver metadataProvider); URI getSingleSignOn(String entityId);  }### Answer:
@Test public void shouldReturnSSOUriForIDP() { final URI singleSignOn = idpSingleSignOnServiceHelper.getSingleSignOn(idpEntityId); assertThat(singleSignOn).isEqualTo(idpSSOUri); }
@Test public void shouldThrowExceptionIfIDPIsNotContainedInMetadata() { try { idpSingleSignOnServiceHelper.getSingleSignOn("thisIdpDoesNotExist"); fail("should have thrown exception"); } catch (ApplicationException e) { assertThat(e.getExceptionType()).isEqualTo(ExceptionType.NOT_FOUND); } }
@Test(expected = RuntimeException.class) public void shouldThrowExceptionWhenMetadataProviderThrowsOne() throws ResolverException { MetadataResolver metadataResolver = mock(MetadataResolver.class); when(metadataResolver.resolveSingle(any(CriteriaSet.class))).thenThrow(new ResolverException()); idpSingleSignOnServiceHelper = new IdpSingleSignOnServiceHelper(metadataResolver); idpSingleSignOnServiceHelper.getSingleSignOn(idpEntityId); }