CertificateUtils { public static Element buildCertDataFromFile(SupplierWithIO<InputStream> certFileLocation, Document document, CertificateFactory certificateFactory) { X509Certificate cert = loadCertificateFromFile(certFileLocation, certificateFactory); return createCertDataElementFromCert(cert, document); } private  CertificateUtils(); static CertificateFactory createX509CertificateFactory(); static Element buildCertDataFromFile(SupplierWithIO<InputStream> certFileLocation, Document document, CertificateFactory certificateFactory); static Element createCertDataElementFromCert(@NotNull X509Certificate cert, Document document); static Element createCertDataElementFromCert(String issuerName, BigInteger serialNumber, String subjectName, String encodedData, Document document); static void writeCertificateData(@NotNull final File certFolder, @NotNull final String certName, @NotNull final String certEncodedData); static final String PEM_CERT_FILE_EXTENSION; static final String P12_CERT_FILE_EXTENSION; }
@Test void buildCertDataFromMissingFile() { assertThrows( CertificateUtilsException.class, () -> buildCertDataFromFile( () -> Files.newInputStream(Paths.get(rootProjectDir.getRoot().toPath().toString(), "cert.cert")), DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(), CertificateFactory.getInstance("X.509") ) ); }
@Test void buildCertDataFromInvalidCert() { assertThrows( CertificateUtilsException.class, () -> buildCertDataFromFile( () -> new ByteArrayInputStream("certificate".getBytes()), DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(), CertificateFactory.getInstance("X.509") ) ); }