// Path: provider/core/src/main/java/org/arquillian/algeron/provider/core/AlgeronProviderConfiguration.java
// public class AlgeronProviderConfiguration {
// 
//     private static final String SKIP_DEPLOYMENT = "skipDeployment";
//     private static final String RETRIEVER_CONFIGURATION = "retrieverConfiguration";
// 
//     private boolean skipDeployment = false;
//     private Map<String, Object> retrieverConfiguration = null;
// 
//     public boolean isSkipDeployment() {
//         return skipDeployment;
//     }
// 
//     public boolean isRetrieverConfigurationSet() {
//         return this.retrieverConfiguration != null;
//     }
// 
//     public Map<String, Object> getRetrieverConfiguration() {
//         return retrieverConfiguration;
//     }
// 
//     public static AlgeronProviderConfiguration fromMap(Map<String, String> config) {
//         AlgeronProviderConfiguration configuration = new AlgeronProviderConfiguration();
// 
//         if (config.containsKey(SKIP_DEPLOYMENT)) {
//             configuration.skipDeployment = Boolean.parseBoolean(config.get(SKIP_DEPLOYMENT));
//         }
// 
//         if (config.containsKey(RETRIEVER_CONFIGURATION)) {
//             configuration.retrieverConfiguration = loadConfiguration(config.get(RETRIEVER_CONFIGURATION));
//         }
// 
//         return configuration;
//     }
// 
//     private final static Map<String, Object> loadConfiguration(String configurationContent) {
//         return (Map<String, Object>) new Yaml().load(configurationContent);
//     }
// }


import org.arquillian.algeron.provider.api.deployment.Environment;
import org.arquillian.algeron.provider.core.AlgeronProviderConfiguration;
import org.jboss.arquillian.container.test.impl.enricher.resource.URLResourceProvider;
import org.jboss.arquillian.core.api.Injector;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
                config.put("skipDeployment", "true");
                return AlgeronProviderConfiguration.fromMap(config);
            };

            final Field urlField = TestWithFieldEnricher.class.getField("url");
            final Object url = environmentUrlResourceProvider.doLookup(urlField.getAnnotation(ArquillianResource.class),
                urlField.getAnnotation(Environment.class));
            assertThat(url).isInstanceOf(URL.class);
            URL urlObject = (URL) url;
            assertThat(urlObject).hasHost("www.arquillian.org");
        } finally {
            System.clearProperty("urlvar");
        }
    }

    @Test
    public void should_resolve_url_with_default_provider() throws NoSuchFieldException, MalformedURLException {

        try {
            System.setProperty("urlvar", "http://www.arquillian.org");
            EnvironmentUrlResourceProvider environmentUrlResourceProvider = new EnvironmentUrlResourceProvider();
            environmentUrlResourceProvider.algeronProviderConfigurationInstance = () -> {
                final HashMap<String, String> config = new HashMap<>();
                config.put("skipDeployment", "false");
                return AlgeronProviderConfiguration.fromMap(config);
            };

            when(injector.inject(Matchers.any())).thenReturn(urlResourceProvider);
            when(urlResourceProvider.doLookup(Matchers.any(), Matchers.any())).thenReturn(new URL("http://mocked.org"));

// Path: provider/core/src/main/java/org/arquillian/algeron/provider/core/AlgeronProviderConfiguration.java
// public class AlgeronProviderConfiguration {
// 
//     private static final String SKIP_DEPLOYMENT = "skipDeployment";
//     private static final String RETRIEVER_CONFIGURATION = "retrieverConfiguration";
// 
//     private boolean skipDeployment = false;
//     private Map<String, Object> retrieverConfiguration = null;
// 
//     public boolean isSkipDeployment() {
//         return skipDeployment;
//     }
// 
//     public boolean isRetrieverConfigurationSet() {
//         return this.retrieverConfiguration != null;
//     }
// 
//     public Map<String, Object> getRetrieverConfiguration() {
//         return retrieverConfiguration;
//     }
// 
//     public static AlgeronProviderConfiguration fromMap(Map<String, String> config) {
//         AlgeronProviderConfiguration configuration = new AlgeronProviderConfiguration();
// 
//         if (config.containsKey(SKIP_DEPLOYMENT)) {
//             configuration.skipDeployment = Boolean.parseBoolean(config.get(SKIP_DEPLOYMENT));
//         }
// 
//         if (config.containsKey(RETRIEVER_CONFIGURATION)) {
//             configuration.retrieverConfiguration = loadConfiguration(config.get(RETRIEVER_CONFIGURATION));
//         }
// 
//         return configuration;
//     }
// 
//     private final static Map<String, Object> loadConfiguration(String configurationContent) {
//         return (Map<String, Object>) new Yaml().load(configurationContent);
//     }
// }


// Path: provider/core/src/test/java/org/arquillian/algeron/provider/core/deployment/EnvironmentUrlResourceProviderTest.java
import org.arquillian.algeron.provider.api.deployment.Environment;
import org.arquillian.algeron.provider.core.AlgeronProviderConfiguration;
import org.jboss.arquillian.container.test.impl.enricher.resource.URLResourceProvider;
import org.jboss.arquillian.core.api.Injector;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

                config.put("skipDeployment", "true");
                return AlgeronProviderConfiguration.fromMap(config);
            };

            final Field urlField = TestWithFieldEnricher.class.getField("url");
            final Object url = environmentUrlResourceProvider.doLookup(urlField.getAnnotation(ArquillianResource.class),
                urlField.getAnnotation(Environment.class));
            assertThat(url).isInstanceOf(URL.class);
            URL urlObject = (URL) url;
            assertThat(urlObject).hasHost("www.arquillian.org");
        } finally {
            System.clearProperty("urlvar");
        }
    }

    @Test
    public void should_resolve_url_with_default_provider() throws NoSuchFieldException, MalformedURLException {

        try {
            System.setProperty("urlvar", "http://www.arquillian.org");
            EnvironmentUrlResourceProvider environmentUrlResourceProvider = new EnvironmentUrlResourceProvider();
            environmentUrlResourceProvider.algeronProviderConfigurationInstance = () -> {
                final HashMap<String, String> config = new HashMap<>();
                config.put("skipDeployment", "false");
                return AlgeronProviderConfiguration.fromMap(config);
            };

            when(injector.inject(Matchers.any())).thenReturn(urlResourceProvider);
            when(urlResourceProvider.doLookup(Matchers.any(), Matchers.any())).thenReturn(new URL("http://mocked.org"));

            environmentUrlResourceProvider.injectorInstance = () -> injector;