### Question:
TransactionConfig implements CertificateConfigurable<TransactionConfig> { public Optional<URI> getAssertionConsumerServiceUri(Optional<Integer> index) { for (AssertionConsumerService service : assertionConsumerServices) { boolean isDesiredEndpoint; if (index.isPresent() && service.getIndex().isPresent()) { isDesiredEndpoint = (service.getIndex().get().equals(index.get())); } else { isDesiredEndpoint = service.getDefault(); } if (isDesiredEndpoint) { return ofNullable(service.getUri()); } } return Optional.empty(); } @SuppressWarnings("unused") // needed to prevent guice injection protected  TransactionConfig(); Optional<URI> getAssertionConsumerServiceUri(Optional<Integer> index); URI getServiceHomepage(); boolean isEnabled(); boolean isEnabledForSingleIdp(); String getEntityId(); @Override FederationEntityType getEntityType(); Certificate getEncryptionCertificate(); Optional<MatchingProcess> getMatchingProcess(); String getMatchingServiceEntityId(); List<LevelOfAssurance> getLevelsOfAssurance(); boolean getShouldHubSignResponseMessages(); boolean getShouldHubUseLegacySamlStandard(); Collection<Certificate> getSignatureVerificationCertificates(); Optional<List<UserAccountCreationAttribute>> getUserAccountCreationAttributes(); Optional<String> getSimpleId(); boolean isEidasEnabled(); Optional<List<String>> getEidasCountries(); URI getHeadlessStartpage(); Optional<URI> getSingleIdpStartPage(); boolean isUsingMatching(); boolean isEidasProxyNode(); boolean isSelfService(); CertificateOrigin getCertificateOrigin(); @Override TransactionConfig override(List<String> signatureVerificationCertificates, String encryptionCertificate, CertificateOrigin certificateOrigin);  }### Answer:
@Test public void getAssertionConsumerServiceUri_shouldReturnCorrectUriWhenIndexIsSpecified() { URI uri = URI.create("/expected-uri"); int index = 1; TransactionConfig systemUnderTests = aTransactionConfigData() .addAssertionConsumerService(anAssertionConsumerService().withIndex(0).build()) .addAssertionConsumerService(anAssertionConsumerService().withIndex(index).withUri(uri).build()) .build(); final Optional<URI> returnedUri = systemUnderTests.getAssertionConsumerServiceUri(Optional.of(index)); assertThat(returnedUri.isPresent()).isEqualTo(true); assertThat(returnedUri.get()).isEqualTo(uri); }
@Test public void getAssertionConsumerServiceUri_shouldReturnAbsentWhenInvalidIndexIsSpecified() { TransactionConfig systemUnderTests = aTransactionConfigData() .addAssertionConsumerService(anAssertionConsumerService().withIndex(0).build()) .build(); final Optional<URI> returnedUri = systemUnderTests.getAssertionConsumerServiceUri(Optional.of(1)); assertThat(returnedUri.isPresent()).isEqualTo(false); }
@Test public void getAssertionConsumerServiceUri_shouldReturnDefaultUriWhenNoIndexIsSpecified() { URI uri = URI.create("/some-uri"); TransactionConfig systemUnderTests = aTransactionConfigData() .addAssertionConsumerService(anAssertionConsumerService().isDefault(false).build()) .addAssertionConsumerService(anAssertionConsumerService().isDefault(true).withUri(uri).build()) .build(); final Optional<URI> returnedUri = systemUnderTests.getAssertionConsumerServiceUri(Optional.empty()); assertThat(returnedUri.isPresent()).isEqualTo(true); assertThat(returnedUri.get()).isEqualTo(uri); }