### Question:
SSLUtils { @Nullable public static SSLContext createSSLClientContext(Configuration sslConfig) throws Exception { Preconditions.checkNotNull(sslConfig); SSLContext clientSSLContext = null; if (getSSLEnabled(sslConfig)) { LOG.debug("Creating client SSL context from configuration"); String trustStoreFilePath = sslConfig.getString(SecurityOptions.SSL_TRUSTSTORE); String trustStorePassword = sslConfig.getString(SecurityOptions.SSL_TRUSTSTORE_PASSWORD); String sslProtocolVersion = sslConfig.getString(SecurityOptions.SSL_PROTOCOL); Preconditions.checkNotNull(trustStoreFilePath, SecurityOptions.SSL_TRUSTSTORE.key() + " was not configured."); Preconditions.checkNotNull(trustStorePassword, SecurityOptions.SSL_TRUSTSTORE_PASSWORD.key() + " was not configured."); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream trustStoreFile = null; try { trustStoreFile = new FileInputStream(new File(trustStoreFilePath)); trustStore.load(trustStoreFile, trustStorePassword.toCharArray()); } finally { if (trustStoreFile != null) { trustStoreFile.close(); } } TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(trustStore); clientSSLContext = SSLContext.getInstance(sslProtocolVersion); clientSSLContext.init(null, trustManagerFactory.getTrustManagers(), null); } return clientSSLContext; }  static boolean getSSLEnabled(Configuration sslConfig); static void setSSLVerAndCipherSuites(ServerSocket socket, Configuration config); static SSLEngineFactory createServerSSLEngineFactory(final Configuration config); static SSLEngineFactory createClientSSLEngineFactory(final Configuration config); @Deprecated static void setSSLVerAndCipherSuites(SSLEngine engine, Configuration config); static void setSSLVerifyHostname(Configuration sslConfig, SSLParameters sslParams); @Nullable static SSLContext createSSLClientContext(Configuration sslConfig); @Nullable static SSLContext createSSLServerContext(Configuration sslConfig);  }### Answer:
@Test public void testCreateSSLClientContext() throws Exception { Configuration clientConfig = new Configuration(); clientConfig.setBoolean(SecurityOptions.SSL_ENABLED, true); clientConfig.setString(SecurityOptions.SSL_TRUSTSTORE, "src/test/resources/local127.truststore"); clientConfig.setString(SecurityOptions.SSL_TRUSTSTORE_PASSWORD, "password"); SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig); Assert.assertNotNull(clientContext); }
@Test public void testCreateSSLClientContextWithSSLDisabled() throws Exception { Configuration clientConfig = new Configuration(); clientConfig.setBoolean(SecurityOptions.SSL_ENABLED, false); SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig); Assert.assertNull(clientContext); }
@Test public void testCreateSSLClientContextMisconfiguration() { Configuration clientConfig = new Configuration(); clientConfig.setBoolean(SecurityOptions.SSL_ENABLED, true); clientConfig.setString(SecurityOptions.SSL_TRUSTSTORE, "src/test/resources/local127.truststore"); clientConfig.setString(SecurityOptions.SSL_TRUSTSTORE_PASSWORD, "badpassword"); try { SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig); Assert.fail("SSL client context created even with bad SSL configuration "); } catch (Exception e) { } }