### Question:
JwsJwksJwtAccessTokenValidator extends JwtAccessTokenValidator { @Override protected JwsSignatureVerifier getInitializedSignatureVerifier(JwsHeaders jwsHeaders) { Objects.requireNonNull(jwsHeaders.getKeyId()); final JwkHolder jwkHolder = jsonWebKeys.computeIfAbsent(jwsHeaders.getKeyId(), keyId -> updateJwk(keyId)); return jwkHolder != null ? jwkHolder.getJwsSignatureVerifier() : null; }  void setJwksURL(String jwksURL); @Override void setJwsVerifier(JwsSignatureVerifier theJwsVerifier);  }### Answer:
@Test public void testGetInitializedSignatureVerifier() { final JsonWebKey jwk = new JsonWebKey(); jwk.setKeyId("anyKid"); jwk.setPublicKeyUse(PublicKeyUse.ENCRYPT); final JsonWebKey jwk1 = new JsonWebKey(); jwk1.setKeyId("kid1"); final JsonWebKey jwk2 = new JsonWebKey(); jwk2.setKeyId("kid2"); jwk2.setPublicKeyUse(PublicKeyUse.SIGN); final JsonWebKey jwk3 = new JsonWebKey(); jwk3.setKeyId("kid3"); jwk3.setPublicKeyUse(PublicKeyUse.SIGN); final JwsJwksJwtAccessTokenValidator validator = new JwsJwksJwtAccessTokenValidator() { int invokeCnt; @Override JsonWebKeys getJsonWebKeys() { ++invokeCnt; if (invokeCnt == 1) { return new JsonWebKeys(Arrays.asList(jwk, jwk1, jwk2)); } else if (invokeCnt == 2) { return new JsonWebKeys(Arrays.asList(jwk, jwk1, jwk3)); } throw new IllegalStateException(); } }; validator.setJwksURL("https: validator.getInitializedSignatureVerifier(new JwsHeaders(jwk2.getKeyId())); assertEquals(new HashSet<>(Arrays.asList(jwk1.getKeyId(), jwk2.getKeyId())), validator.jsonWebKeys.keySet()); validator.getInitializedSignatureVerifier(new JwsHeaders(jwk3.getKeyId())); assertEquals(new HashSet<>(Arrays.asList(jwk1.getKeyId(), jwk3.getKeyId())), validator.jsonWebKeys.keySet()); }
@Test(expected = NullPointerException.class) public void testGetInitializedSignatureVerifierUninitialized() { new JwsJwksJwtAccessTokenValidator().getInitializedSignatureVerifier(new JwsHeaders("kid")); }
@Test(expected = NullPointerException.class) public void testGetInitializedSignatureVerifierNoKid() { new JwsJwksJwtAccessTokenValidator().getInitializedSignatureVerifier(new JwsHeaders()); }