@Test
public void whenSelfSignIsTrue_itGeneratesAValidSelfSignedCertificate() throws Exception {

  final X509Certificate certificate = new JcaX509CertificateConverter().setProvider(BouncyCastleFipsProvider.PROVIDER_NAME)
    .getCertificate(generateX509SelfSignedCert());
  generationParameters.setCaName(null);
  generationParameters.setSelfSigned(true);
  inputParameters = new CertificateGenerationParameters(generationParameters);
  when(keyGenerator.generateKeyPair(anyInt())).thenReturn(rootCaKeyPair);
  when(signedCertificateGenerator.getSelfSigned(rootCaKeyPair, inputParameters))
    .thenReturn(certificate);
  final CertificateCredentialValue certificateCredential = subject.generateCredential(inputParameters);
  assertThat(certificateCredential.getPrivateKey(),
    equalTo(CertificateFormatter.pemOf(rootCaKeyPair.getPrivate())));
  assertThat(certificateCredential.getCertificate(),
    equalTo(CertificateFormatter.pemOf(certificate)));
  assertThat(certificateCredential.getCa(), equalTo(CertificateFormatter.pemOf(certificate)));
  verify(signedCertificateGenerator, times(1)).getSelfSigned(rootCaKeyPair, inputParameters);
}