### Question:
JwtAudienceValidator implements Validator<Token> { static Set<String> extractAudiencesFromToken(Token token) { Set<String> audiences = new LinkedHashSet<>(); for (String audience : token.getAudiences()) { if (audience.contains("" + DOT)) { String aud = extractAppId(audience); if (!aud.isEmpty()) { audiences.add(aud); } } else { audiences.add(audience); } } if (Service.XSUAA.equals(token.getService())) { if (token.hasClaim(TokenClaims.XSUAA.CLIENT_ID)) { audiences.add(token.getClaimAsString(TokenClaims.XSUAA.CLIENT_ID)); } if (token.getAudiences().isEmpty()) { for (String scope : token.getClaimAsStringList(TokenClaims.XSUAA.SCOPES)) { if (scope.contains(".")) { audiences.add(extractAppId(scope)); } } } } logger.info("The audiences that are derived from the token: {}.", audiences); return audiences; } JwtAudienceValidator(String clientId); @Override ValidationResult validate(Token token); Set<String> getTrustedClientIds();  }### Answer:
@Test public void extractAudiencesFromTokenScopes() { ArrayList<String> scopes = new ArrayList(); scopes.add("client.read"); scopes.add("test1!t1.read"); scopes.add("client.write"); scopes.add("xsappid.namespace.ns.write"); scopes.add("openid"); Mockito.when(token.getClaimAsStringList(TokenClaims.XSUAA.SCOPES)).thenReturn(scopes); Mockito.when(token.getAudiences()).thenReturn(Collections.EMPTY_SET); Set audiences = JwtAudienceValidator.extractAudiencesFromToken(token); assertThat(audiences.size()).isEqualTo(3); assertThat(audiences).containsExactlyInAnyOrder("test1!t1", "client", "xsappid"); }