### Question:
InternalTlsCertificateService { public X509Certificate importInternalTlsCertificate(byte[] certificateBytes) throws InvalidCertificateException { X509Certificate x509Certificate = null; try { x509Certificate = CryptoUtils.readCertificate(certificateBytes); } catch (Exception e) { throw new InvalidCertificateException("cannot convert bytes to certificate", e); } auditDataHelper.putCertificateHash(x509Certificate); try { CertUtils.writePemToFile(certificateBytes, internalCertPath); CertUtils.createPkcs12(internalKeyPath, internalCertPath, internalKeystorePath); } catch (Exception e) { log.error("Failed to import internal TLS cert", e); throw new DeviationAwareRuntimeException("cannot import internal tls cert", e, new ErrorDeviation(IMPORT_INTERNAL_CERT_FAILED)); } return x509Certificate; } @Autowired  InternalTlsCertificateService(InternalTlsCertificateRepository internalTlsCertificateRepository,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-certificate.path}") String generateCertScriptPath,
            @Value("${script.generate-certificate.args}") String generateCertScriptArgs,
            AuditDataHelper auditDataHelper); X509Certificate getInternalTlsCertificate(); byte[] exportInternalTlsCertificate(); void generateInternalTlsKeyAndCertificate(); X509Certificate importInternalTlsCertificate(byte[] certificateBytes); static final String KEY_CERT_GENERATION_FAILED; static final String IMPORT_INTERNAL_CERT_FAILED; }### Answer:
@Test public void importInternalTlsCertificate() throws Exception { prepareTlsImportForTesting(); byte[] certFileData = CertificateTestUtils.getMockCertificateBytes(); try { internalTlsCertificateService.importInternalTlsCertificate(certFileData); } catch (Exception e) { fail("should not throw exceptions"); } }
@Test(expected = InvalidCertificateException.class) public void importInternalTlsInvalidCertificate() throws Exception { prepareTlsImportForTesting(); byte[] certFileData = CertificateTestUtils.getInvalidCertBytes(); internalTlsCertificateService.importInternalTlsCertificate(certFileData); }