class 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());
    }

}

class DefaultProviderConfigTest {

    @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();
    }

}