CertificateTool { public X509Certificate generateSelfSignedCertificate( CertificateData certificateData ) { KeyManager keyManager = new KeyManager(); KeyPairGenerator generator = keyManager.prepareKeyPairGeneration( KeyPairType.RSA, 1024 ); KeyPair keyPair = keyManager.generateKeyPair( generator ); return generateSelfSignedCertificate( keyPair, certificateData ); }  void setDateParamaters(); X509Certificate generateSelfSignedCertificate( CertificateData certificateData ); X509Certificate generateSelfSignedCertificate( KeyPair keyPair, CertificateData certificateData ); X509Certificate convertX509PemToCert( String x509InPem ); String convertX509CertToPem( X509Certificate x509Cert );  }
@Test( expected = RuntimeException.class ) public void testGenerateSelfSignedCertificateException() throws Exception { certificateTool.generateSelfSignedCertificate( keyPair, certificateData ); }
@Test public void testGenerateSelfSignedCertificate() throws Exception { when( certificateData.getCommonName() ).thenReturn( "commonName" ); when( certificateData.getOrganizationUnit() ).thenReturn( "organizationUnit" ); when( certificateData.getOrganizationName() ).thenReturn( "organizationName" ); when( certificateData.getCountry() ).thenReturn( "KG" ); when( certificateData.getLocalityName() ).thenReturn( "localityName" ); when( certificateData.getState() ).thenReturn( "Running" ); when( certificateData.getEmail() ).thenReturn( "email" ); certificateTool.generateSelfSignedCertificate( keyPair, certificateData ); }