FSKeystoreProvider implements IKeystoreProvider { @Override public void writeTo(final OutputStream outputStream) { try { getKeyStore().store(outputStream, keystorePass.toCharArray()); } catch (Exception e) { throw new RuntimeException(e); } } FSKeystoreProvider(final String keystorePath,
                              final String keystorePass,
                              final String keystoreType); KeyStore getKeyStore(); @Override void writeTo(final OutputStream outputStream);  }
@Test public void testWriteTo() throws Exception { FSKeystoreProvider provider = new FSKeystoreProvider(KS_PATH, KS_PASS, KS_TYPE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); provider.writeTo(baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(bais, "kangaroo".toCharArray()); assertEquals("kangaroo", keyStore.aliases().nextElement()); }