EnvironmentUrlResourceProvider extends OperatesOnDeploymentAwareProvider { @Override public Object doLookup(ArquillianResource resource, Annotation... qualifiers) { if (DeploymentEnabler.shouldEnableDeployment(algeronProviderConfigurationInstance.get())) { return resolveResourceProvider(resource, qualifiers); } else { final Optional<Environment> environmentAnnotation = getEnvironmentAnnotation(qualifiers); if (environmentAnnotation.isPresent()) { return resolveAnnotation(environmentAnnotation.get()); } else { return resolveResourceProvider(resource, qualifiers); } } } EnvironmentUrlResourceProvider(); @Override Object doLookup(ArquillianResource resource, Annotation... qualifiers); @Override boolean canProvide(Class<?> type);  }
@Test public void should_resolve_url_if_environment_annotation_present() throws NoSuchFieldException { try { System.setProperty("urlvar", "http: EnvironmentUrlResourceProvider environmentUrlResourceProvider = new EnvironmentUrlResourceProvider(); environmentUrlResourceProvider.algeronProviderConfigurationInstance = () -> { final HashMap<String, String> config = new HashMap<>(); 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: 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: environmentUrlResourceProvider.injectorInstance = () -> injector; 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("mocked.org"); } finally { System.clearProperty("urlvar"); } }