### Question:
KeyStoreHeaplet extends GenericHeaplet { @Override public Object create() throws HeapException { JsonValue urlString = config.get("url").required(); URL url = evaluateJsonStaticExpression(urlString).asURL(); String password = evaluate(config.get("password")); String type = config.get("type").defaultTo(KeyStore.getDefaultType()).asString().toUpperCase(); KeyStore keyStore = null; InputStream keyInput = null; try { keyStore = KeyStore.getInstance(type); keyInput = url.openStream(); char[] credentials = (password == null) ? null : password.toCharArray(); keyStore.load(keyInput, credentials); } catch (Exception e) { throw new HeapException(format("Cannot load %S KeyStore from %s", type, urlString.asString()), e); } finally { closeSilently(keyInput); } return keyStore; }  @Override Object create();  }### Answer:
@Test public void shouldLoadJksKeyStore() throws Exception { JsonValue config = json(object( field("url", resource("/keypair-keystore.jks")), field("password", "changeit") )); KeyStoreHeaplet heaplet = new KeyStoreHeaplet(); KeyStore store = (KeyStore) heaplet.create(Name.of(OBJECT_NAME), config, null); assertThat(store.containsAlias("keypair")).isTrue(); assertThat(store.getType()).isEqualToIgnoringCase("JKS"); }
@Test public void shouldLoadPkcs12KeyStore() throws Exception { JsonValue config = json(object( field("url", resource("/mykey-keystore.pkcs12")), field("password", "changeit"), field("type", "PKCS12") )); KeyStoreHeaplet heaplet = new KeyStoreHeaplet(); KeyStore store = (KeyStore) heaplet.create(of(OBJECT_NAME), config, null); assertThat(store.containsAlias("mykey")).isTrue(); assertThat(store.getType()).isEqualToIgnoringCase("PKCS12"); }