StandardEnvironment extends AbstractEnvironment { @Override public URL getResource(String resourceName) { URL resourceURL = null; if (this.resourceDirectory != null) { try { File resourceFile = new File(this.resourceDirectory, resourceName); if (resourceFile.exists()) { resourceURL = resourceFile.toURI().toURL(); } } catch (MalformedURLException e) { this.logger.debug("Failed to access resource [{}]", resourceName, e); } } if (resourceURL == null) { resourceURL = (this.resourceClassLoader == null ? Thread.currentThread().getContextClassLoader() : this.resourceClassLoader).getResource(resourceName); } return resourceURL; }  void setResourceDirectory(File resourceDirectory); void setResourceClassLoader(ClassLoader classLoader); @Override InputStream getResourceAsStream(String resourceName); @Override URL getResource(String resourceName);  }
@Test void getResourceWhenResourceDirNotSet() { assertNull(this.environment.getResource("doesntexist")); }
@Test void getResourceWhenResourceDirNotSetButResourceAvailableInDefaultClassLoader() { URL resource = this.environment.getResource("test"); assertNotNull(resource); }