### Question:
AuthorityCheckerImpl implements AuthorityChecker { @Override public boolean verifyCertificates(String certificateDirectory) { try { Set<Certificate> ordinaryCertificates = readCertificates(certificateDirectory, certificateSuffix, certificatePrefixes); Certificate intermediateCertificate = readCertificate(certificateDirectory + "/" + intermediateCertificateName); if (intermediateCertificate == null) { return false; } for (Certificate certificate : ordinaryCertificates) { certificate.verify(intermediateCertificate.getPublicKey()); } if (caCertificate == null) { Path path = downloadCACertificate(caCertificateUrl); LOG.info("Downloaded ca certificate from " + caCertificateUrl); caCertificate = readCertificate(path); } intermediateCertificate.verify(caCertificate.getPublicKey()); return true; } catch (CertificateException | IOException | URISyntaxException e) { LOG.error("Unable to read or load certificate", e); } catch (NoSuchAlgorithmException | SignatureException | NoSuchProviderException | InvalidKeyException e) { LOG.error("Unable to verify certificate signature", e); } return false; } AuthorityCheckerImpl(Certificate caCertificate);  AuthorityCheckerImpl(String caCertificateUrl, String certificateSuffix, String intermediateCertificateName, String... certificatePrefixes);  AuthorityCheckerImpl(Certificate rootCertificate, String certificateSuffix, String intermediateCertificateName,
                                String... certificatePrefixes);  AuthorityCheckerImpl(String caCertificateUrl); String getCertificateSuffix(); void setCertificateSuffix(String certificateSuffix); String[] getCertificatePrefixes(); void setCertificatePrefixes(String[] certificatePrefixes); @Override boolean verifyCertificates(String certificateDirectory); @Override void verifyJarSignature(Certificate certificate, Path jarFilePath); @Override boolean verifyJarSignature(String certificateDirectory, Path jarFilePath);  }### Answer:
@Test public void testVerifyCertificates() throws Exception { String testRootCAPath = "certs/rootCA.crt"; Certificate certificate = UpdaterUtil.readCertificate(testRootCAPath); AuthorityChecker correctAuthorityChecker = new AuthorityCheckerImpl(certificate, ".crt", "intermediate.crt", "1_", "2_"); boolean verified = correctAuthorityChecker.verifyCertificates("certs"); assertTrue(verified); }
@Test public void testNotVerifiedCertificatesWhenIncorrectRootCertificate() throws Exception { String fakeRootCACertificate = "certs/1_1.crt"; Certificate certificate = UpdaterUtil.readCertificate(fakeRootCACertificate); AuthorityChecker incorrectAuthorityChecker = new AuthorityCheckerImpl(certificate, ".crt", "intermediate.crt", "1_", "2_"); ; boolean isVerified = incorrectAuthorityChecker.verifyCertificates("certs"); assertFalse(isVerified); }
@Test public void testNotVerifiedCertificatesWhenIncorrectPathIntermediateCertificate() { AuthorityChecker incorrectAuthorityChecker = new AuthorityCheckerImpl("rootCA.crt", ".crt", "intermediat.crt", "1_", "2_"); assertThrows(RuntimeException.class, () -> incorrectAuthorityChecker.verifyCertificates("certs")); }