### Question:
CacheResourcesManager { public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; } CacheResourcesManager();  CacheResourcesManager(Cache<String, Boolean> cache); Path getResource(final String resourceURI); static Path getResourceCachePath(String resourceURI); static Path getResourceCachePath(URI uri); static Path getResourceCachePath(ResourceToDeploy resource); boolean canUseCache(String url); void setUseCache(boolean useCache); boolean isUseCache();  }### Answer:
@Test public void testUnavailableCache() throws Exception { FileServer server = new FileServer(); server.start(); String uri = server.getUri("bad/url"); try { cacheResourcesManager.getResource(uri); fail("cacheResourcesManager should be busy downloading the url"); } catch (CacheResourceDownloadingException ignored) { } TimeUnit.MILLISECONDS.sleep(200); assertNull(cacheResourcesManager.getResource(uri)); TimeUnit.SECONDS.sleep(1); try { cacheResourcesManager.getResource(uri); fail("cacheResourcesManager should be busy re-downloading the url"); } catch (CacheResourceDownloadingException ignored) { } }
@Test public void testAvailableCache() throws Exception { FileServer server = new FileServer(); server.start(); String uri = server.getUri("/dtd/web-app_2_3.dtd"); try { cacheResourcesManager.getResource(uri); fail("cacheResourcesManager should be busy downloading the url"); } catch (CacheResourceDownloadingException ignored) { } TimeUnit.MILLISECONDS.sleep(200); assertNotNull(cacheResourcesManager.getResource(uri)); server.stop(); TimeUnit.SECONDS.sleep(1); assertNotNull(cacheResourcesManager.getResource(uri)); }
@Test public void testGetBadResource() throws IOException { CacheResourceDownloadingException actual = null; try { cacheResourcesManager.getResource("http: } catch (CacheResourceDownloadingException e) { actual = e; } assertNotNull(actual); assertEquals( "The resource 'http: actual.getMessage()); }