### Question:
AggregateTrustManager implements X509TrustManager { public static void initialize(KeyStore... keyStores) throws Exception { TrustManager[] trustManagers = new TrustManager[] { new AggregateTrustManager(keyStores) }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustManagers, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } private  AggregateTrustManager(KeyStore... keyStores); static void initialize(KeyStore... keyStores); @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers();  }### Answer:
@Test public void testWithDefault_usingBothCacertsAndRioKeyStore() throws Exception { AggregateTrustManager.initialize(keyStore); URL locationURL = new URL("https: URLConnection urlConnection = locationURL.openConnection(); urlConnection.connect(); }
@Test(expected= SSLHandshakeException.class) public void testWithJustRioKeystore_shouldFail() throws Exception { System.setProperty("javax.net.ssl.trustStore", keyStoreFile.getPath()); AggregateTrustManager.initialize(keyStore); URL locationURL = new URL("https: URLConnection urlConnection = locationURL.openConnection(); urlConnection.connect(); }