### Question:
HttpsFactory { public SSLContext createSslContext() { if (config.isVerifySslCertificatesOfServices()) { return createSecureSslContext(); } else { return createIgnoringSslContext(); } } HttpsFactory(HttpsConfig httpsConfig); CloseableHttpClient createSecureHttpClient(); ConnectionSocketFactory createSslSocketFactory(); SSLContext createSslContext(); void setSystemSslProperties(); HostnameVerifier createHostnameVerifier(); EurekaJerseyClientBuilder createEurekaJerseyClientBuilder(String eurekaServerUrl, String serviceId);  }### Answer:
@Test public void shouldCreateSecureSslContextWithEmptyKeystoreWhenNoKeystoreIsProvided() throws KeyStoreException { HttpsConfig httpsConfig = HttpsConfig.builder().protocol("TLSv1.2").verifySslCertificatesOfServices(true).build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); httpsFactory.createSslContext(); assertFalse(httpsFactory.getUsedKeyStore().aliases().hasMoreElements()); }
@Test public void shouldCreateSecureSslContext() { HttpsConfig httpsConfig = httpsConfigBuilder.build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); SSLContext sslContext = httpsFactory.createSslContext(); assertNotNull(sslContext); assertEquals(SSLContext.class, sslContext.getClass()); }
@Test public void shouldCreateIgnoringSslContext() { HttpsConfig httpsConfig = httpsConfigBuilder.verifySslCertificatesOfServices(false).build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); SSLContext sslContext = httpsFactory.createSslContext(); assertNotNull(sslContext); assertEquals(SSLContext.class, sslContext.getClass()); }
@Test(expected = HttpsConfigError.class) public void wrongKeyPasswordConfigurationShouldFail() { HttpsConfig httpsConfig = httpsConfigBuilder.keyPassword(INCORRECT_PARAMETER_VALUE.toCharArray()).build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); SSLContext sslContext = httpsFactory.createSslContext(); assertNull(sslContext); }
@Test(expected = HttpsConfigError.class) public void specificIncorrectAliasShouldFail() { HttpsConfig httpsConfig = httpsConfigBuilder.trustStorePassword(INCORRECT_PARAMETER_VALUE.toCharArray()).build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); SSLContext sslContext = httpsFactory.createSslContext(); assertNull(sslContext); }
@Test(expected = HttpsConfigError.class) public void incorrectProtocolShouldFail() { HttpsConfig httpsConfig = httpsConfigBuilder.verifySslCertificatesOfServices(false).protocol(INCORRECT_PARAMETER_VALUE).build(); HttpsFactory httpsFactory = new HttpsFactory(httpsConfig); SSLContext sslContext = httpsFactory.createSslContext(); assertNull(sslContext); }