DefaultProviderConfig { public Optional<Provider> createProvider() { if (accessKey.isEmpty() || secretKey.isEmpty()) { return Optional.absent(); } final ProviderBuilder builder = Provider.builder() .id(AmazonProvisionr.ID) .accessKey(accessKey) .secretKey(secretKey); if (!region.isEmpty()) { builder.option("region", region); } if (endpoint.isEmpty()) { builder.endpoint(Optional.<String>absent()); } else { builder.endpoint(endpoint); } return Optional.of(builder.createProvider()); } DefaultProviderConfig(String accessKey, String secretKey, String region, String endpoint); Optional<Provider> createProvider();  }
@Test public void testProviderIsAbsentIfCredentialsAreEmpty() { DefaultProviderConfig config = new DefaultProviderConfig("", "", "us-east-1", ""); assertThat(config.createProvider().isPresent()).isFalse(); }
@Test public void testProviderWithNoRegionAndEndpoint() { DefaultProviderConfig config = new DefaultProviderConfig("access", "secret", "", ""); Optional<Provider> provider = config.createProvider(); assertThat(provider.isPresent()).isTrue(); assertThat(provider.get().getEndpoint().isPresent()).isFalse(); assertThat(provider.get().getOptions().containsKey("region")).isFalse(); }