### Question:
AWSIotSslUtility { public static SSLSocketFactory getSocketFactoryWithKeyStore(KeyStore keyStore, int portNumber) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException, NoSuchProviderException { SSLContext context; if (portNumber == 443) { Security.addProvider(new OpenSSLProvider()); context = SSLContext.getInstance(TLS_V_1_2, "Conscrypt"); } else { context = SSLContext.getInstance(TLS_V_1_2); } KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory .getDefaultAlgorithm()); kmf.init(keyStore, AWSIotKeystoreHelper.AWS_IOT_INTERNAL_KEYSTORE_PASSWORD.toCharArray()); KeyManager[] km = kmf.getKeyManagers(); context.init(km, null, new SecureRandom()); return new AWSIotTLSSocketFactory(context.getSocketFactory()); } private  AWSIotSslUtility(); static SSLSocketFactory getSocketFactoryWithKeyStore(KeyStore keyStore, int portNumber); static SSLSocketFactory getSocketFactoryWithKeyStoreAndProxy(KeyStore keyStore,
                                                                        int portNumber, String proxyHost,
                                                                        int proxyPort);  }### Answer:
@Test public void testGetSocketFactory() throws Exception { File keystoreFile = new File(KEYSTORE_PATH, KEYSTORE_NAME); FileInputStream fis = new FileInputStream(keystoreFile); KeyStore testKeystore = KeyStore.getInstance(KeyStore.getDefaultType()); testKeystore.load(fis, AWSIotKeystoreHelper.AWS_IOT_INTERNAL_KEYSTORE_PASSWORD.toCharArray()); SSLSocketFactory factory = AWSIotSslUtility.getSocketFactoryWithKeyStore(testKeystore, 8883); assertTrue(factory instanceof AWSIotTLSSocketFactory); }