ApiAnnotationConfig { public void setAudiencesIfSpecified(String[] audiences) { if (!AnnotationUtil.isUnspecified(audiences)) { config.setAudiences(Arrays.asList(audiences)); } } ApiAnnotationConfig(ApiConfig config); ApiConfig getConfig(); void setRootIfNotEmpty(String root); void setNameIfNotEmpty(String name); void setCanonicalNameIfNotEmpty(String canonicalName); void setVersionIfNotEmpty(String version); void setTitleIfNotEmpty(String title); void setDescriptionIfNotEmpty(String description); void setDocumentationLinkIfNotEmpty(String documentationLink); void setBackendRootIfNotEmpty(String backendRoot); void setIsAbstractIfSpecified(AnnotationBoolean isAbstract); void setIsDefaultVersionIfSpecified(AnnotationBoolean defaultVersion); void setIsDiscoverableIfSpecified(AnnotationBoolean discoverable); void setUseDatastoreIfSpecified(AnnotationBoolean useDatastore); void setResourceIfNotEmpty(String resource); void setAuthLevelIfSpecified(AuthLevel authLevel); void setScopesIfSpecified(String[] scopes); void setAudiencesIfSpecified(String[] audiences); void setIssuersIfSpecified(ApiIssuerConfigs issuers); void setIssuerAudiencesIfSpecified(ApiIssuerAudienceConfig issuerAudiences); void setClientIdsIfSpecified(String[] clientIds); void setAuthenticatorsIfSpecified(Class<? extends Authenticator>[] authenticators); void setPeerAuthenticatorsIfSpecified(
      Class<? extends PeerAuthenticator>[] peerAuthenticators); void setApiKeyRequiredIfSpecified(AnnotationBoolean apiKeyRequired); void setApiLimitMetrics(ApiLimitMetric[] apiLimitMetrics);  }
@Test public void testSetAudiencesIfSpecified() throws Exception { String[] audiences = { "foo", "bar" }; annotationConfig.setAudiencesIfSpecified(audiences); assertEquals(Arrays.asList(audiences), config.getAudiences()); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(getResultNoParamsMethod()); assertEquals(Arrays.asList(audiences), methodConfig.getAudiences()); }
@Test public void testSetAudiencesIfSpecified_empty() throws Exception { String[] empty = {}; annotationConfig.setAudiencesIfSpecified(empty); EndpointMethod method = getResultNoParamsMethod(); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method); assertEquals(Collections.emptyList(), methodConfig.getAudiences()); String[] audiences = { "bleh", "more bleh" }; annotationConfig.setAudiencesIfSpecified(audiences); annotationConfig.setAudiencesIfSpecified(empty); assertEquals(Collections.emptyList(), config.getAudiences()); }