### Question:
GoogleClientSecretsBuilder { public GoogleClientSecretsForApiBuilder forApi(Api api) { return new GoogleClientSecretsForApiBuilder(api); } GoogleClientSecretsBuilder(); GoogleClientSecretsForApiBuilder forApi(Api api);  }### Answer:
@Test public void testGoogleSecretsReadPropertiesFromConfiguration() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); GoogleClientSecrets googleClientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); assertEquals("clientId", googleClientSecrets.getInstalled().getClientId()); assertEquals("clientSecret", googleClientSecrets.getInstalled().getClientSecret()); }
@Test public void testGoogleSecretsReadPropertiesFromConfiguration_properPrefix() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientIdDfp"); config.setProperty("api.admanager.clientSecret", "clientSecretDfp"); config.setProperty("api.adwords.clientId", "clientIdAdWords"); config.setProperty("api.adwords.clientSecret", "clientSecretAdWords"); GoogleClientSecrets googleClientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); assertEquals("clientIdDfp", googleClientSecrets.getInstalled().getClientId()); assertEquals("clientSecretDfp", googleClientSecrets.getInstalled().getClientSecret()); }
@Test public void testGoogleSecretsReadPropertiesFromConfiguration_missingClientId() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); thrown.expect(ValidationException.class); new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); }
@Test public void testGoogleSecretsReadPropertiesFromConfiguration_missingClientSecret() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); thrown.expect(ValidationException.class); new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); }
@Test public void testBuilder() throws Exception { GoogleClientSecrets clientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .withClientSecrets("clientId", "clientSecret") .build(); assertNotNull(clientSecrets.getDetails()); assertEquals("clientId", clientSecrets.getDetails().getClientId()); assertEquals("clientSecret", clientSecrets.getDetails().getClientSecret()); }
@Test public void testBuilder_defaultClientIdAndSecret() throws Exception { thrown.expect(ValidationException.class); thrown.expectMessage("Client ID must be set." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https: new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .withClientSecrets("INSERT_CLIENT_ID_HERE", "INSERT_CLIENT_SECRET_HERE") .build(); }