### Question:
JsonWebKeySetFactory { static JsonWebKeySet createFromJson(String json) { JsonWebKeySet keySet = new JsonWebKeySet(); if (json != null) { JSONArray keys = new JSONObject(json).getJSONArray(JsonWebKeyConstants.KEYS_PARAMETER_NAME); for (Object key : keys) { if (key instanceof JSONObject) { keySet.put(createJsonWebKey((JSONObject) key)); } } } return keySet; } private  JsonWebKeySetFactory();   }### Answer:
@Test public void getEmptyJsonWebKeySetWhenJsonIsNull() { assertThat(JsonWebKeySetFactory.createFromJson(null).getAll(), equalTo(Collections.EMPTY_SET)); }
@Test public void getKey() throws InvalidKeySpecException, NoSuchAlgorithmException { JsonWebKeySet jwks = JsonWebKeySetFactory.createFromJson(jsonWebTokenKeys); JsonWebKey jwk = jwks.getKeyByAlgorithmAndId(JwtSignatureAlgorithm.RS256, "key-id-1"); assertThat(jwk.getKeyAlgorithm().value(), equalTo("RS256")); assertThat(jwk.getKeyAlgorithm().type(), equalTo("RSA")); assertThat(jwk.getPublicKey().getAlgorithm(), equalTo(jwk.getKeyAlgorithm().type())); assertThat(jwk.getId(), equalTo("key-id-1")); }
@Test public void getKeys() throws InvalidKeySpecException, NoSuchAlgorithmException { JsonWebKeySet jwks = JsonWebKeySetFactory.createFromJson(jsonWebTokenKeys); JsonWebKey jwk = jwks.getKeyByAlgorithmAndId(JwtSignatureAlgorithm.RS256, "key-id-1"); assertThat(jwk.getKeyAlgorithm().value(), equalTo("RS256")); assertThat(jwk.getKeyAlgorithm().type(), equalTo("RSA")); assertThat(jwk.getPublicKey().getAlgorithm(), equalTo(jwk.getKeyAlgorithm().type())); assertThat(jwk.getId(), equalTo("key-id-1")); }
@Test public void getIasKeys() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { jsonWebTokenKeys = IOUtils.resourceToString("/iasJsonWebTokenKeys.json", StandardCharsets.UTF_8); JsonWebKeySet jwks = JsonWebKeySetFactory.createFromJson(jsonWebTokenKeys); JsonWebKey jwk = jwks.getKeyByAlgorithmAndId(JwtSignatureAlgorithm.RS256, null); assertThat(jwk.getKeyAlgorithm().type(), equalTo("RSA")); assertThat(jwk.getPublicKey().getAlgorithm(), equalTo(jwk.getKeyAlgorithm().type())); assertThat(jwk.getId(), equalTo(JsonWebKey.DEFAULT_KEY_ID)); }