### Question:
TrustedAuthorityValidator implements Validator { boolean isCertificateChainValid(List<X509Certificate> certificates) { X509Certificate targetCert = certificates.get(0); X509CertSelector selector = new X509CertSelector(); selector.setCertificate(targetCert); try { List<X509Certificate> intermediateCerts = certRepo.getCaCerts(); List<X509Certificate> trustedAuthorityCerts = certRepo.getTrustedCaCerts(); Set<TrustAnchor> trustAnchors = asTrustAnchors(trustedAuthorityCerts); CertStoreParameters intermediateParams = new CollectionCertStoreParameters(intermediateCerts); CertStoreParameters certificateParams = new CollectionCertStoreParameters(certificates); PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector); pkixParams.addCertStore(CertStore.getInstance("Collection", intermediateParams)); pkixParams.addCertStore(CertStore.getInstance("Collection", certificateParams)); pkixParams.setRevocationEnabled(false); CertPathBuilder builder = CertPathBuilder.getInstance("PKIX"); CertPath certPath = builder.build(pkixParams).getCertPath(); pkixParams.setRevocationEnabled(enableRevocation); if (enableRevocation) { List<X509CRL> crls = certRepo.getCRLs(); if (!crls.isEmpty()) { CertStoreParameters crlParams = new CollectionCertStoreParameters(crls); pkixParams.addCertStore(CertStore.getInstance("Collection", crlParams)); } } CertPathValidator validator = CertPathValidator.getInstance("PKIX"); validator.validate(certPath, pkixParams); } catch (InvalidAlgorithmParameterException e) { LOG.log(Level.WARNING, "Invalid algorithm parameter by certificate chain validation. " + "It is likely that issuer certificates are not found in XKMS trusted storage. " + e.getMessage(), e); return false; } catch (NoSuchAlgorithmException e) { LOG.log(Level.WARNING, "Unknown algorithm by trust chain validation: " + e.getMessage(), e); return false; } catch (CertPathBuilderException e) { LOG.log(Level.WARNING, "Cannot build certification path: " + e.getMessage(), e); return false; } catch (CertPathValidatorException e) { LOG.log(Level.WARNING, "Cannot vaidate certification path: " + e.getMessage(), e); return false; } return true; } TrustedAuthorityValidator(CertificateRepo certRepo); @Override StatusType validate(ValidateRequestType request); boolean isEnableRevocation(); void setEnableRevocation(boolean enableRevocation);  }### Answer:
@Test public void testIsCertChainValid() throws CertificateException { TrustedAuthorityValidator validator = new TrustedAuthorityValidator(certificateRepo); Assert.assertTrue("Root should be valid", validator.isCertificateChainValid(Arrays.asList(certificateRoot))); Assert.assertTrue("Alice should be valid", validator.isCertificateChainValid(Arrays.asList(certificateAlice))); }