### Question:
SSLContextFactory { public static SSLContext create(InputStream pkcs12Stream, char[] pkcs12Password) { Preconditions.checkArgument(pkcs12Stream != null, "pkcs12 store is required"); Preconditions.checkArgument(pkcs12Password != null, "pkcs12 store password is required"); KeyStore keyStore; try { keyStore = loadPKCS12KeyStore(pkcs12Stream, pkcs12Password); KeyManagerFactory keyManager = configureKeyManagerFactory(keyStore, pkcs12Password); return buildSSLContext(trustAllx509Manager(), keyManager.getKeyManagers()); } catch (KeyStoreException e) { throw Throwables.propagate(e); } catch (NoSuchAlgorithmException e) { throw Throwables.propagate(e); } catch (CertificateException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } catch (UnrecoverableKeyException e) { throw Throwables.propagate(e); } }  static SSLContext create(InputStream pkcs12Stream, char[] pkcs12Password); static final SSLContext TRUST_ALL; }### Answer:
@Test(expected=IllegalArgumentException.class) public void testRequirePKCS12() { SSLContextFactory.create(null, "password".toCharArray()); }
@Test(expected=IllegalArgumentException.class) public void testRequirePKCS12Password() { SSLContextFactory.create(new ByteArrayInputStream("test".getBytes()), null); }
@Test(expected=EOFException.class) public void testKeyStoreFailsIfNotPKCS12() throws Throwable { InputStream pkcs12Stream = IOUtils.toInputStream("I'm not a pkcs12 key store"); char[] pkcs12Password = "toto".toCharArray(); try { SSLContextFactory.create(pkcs12Stream, pkcs12Password); } catch (RuntimeException e) { assertThat(e.getCause()).isNotNull(); throw e.getCause(); } }
@Test public void testCorrectSSLContextFactoryCall() { InputStream pkcs12Stream = ClassLoader.getSystemClassLoader().getResourceAsStream("pkcs_pwd_toto.p12"); char[] pkcs12Password = "toto".toCharArray(); SSLContext sslContext = SSLContextFactory.create(pkcs12Stream, pkcs12Password); assertThat(sslContext).isNotNull(); }