URLLocator implements Locator<URLLocation> { @Override public File copyToFile(URLLocation location, File toFile) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); httpCall.downloadToFile(toFile); } else { FileUtils.copyURLToFile(location.getURL(), toFile); } return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to file: %s", location, toFile), e); } }  @Override File locate(URLLocation location); @Override File copyToDirectory(URLLocation location, File toDir); @Override InputStream openInputStream(URLLocation location); @Override File copyToFile(URLLocation location, File toFile);  }
@Test public void copyToFile() throws Exception { File toFile = temp.newFile(); File copy = underTest.copyToFile(location, toFile); assertThat(copy).exists().isFile(); assertThat(copy).isSameAs(toFile); assertThat(FileUtils.readFileToString(copy)).isEqualTo("foo"); }
@Test public void test_copyToFile() throws Exception { File toFile = temp.newFile(); webServer.enqueue(new MockResponse().setBody("hello world")); underTest.copyToFile(URLLocation.create(webServer.url("/").url()), toFile); assertThat(toFile).exists().isFile().hasContent("hello world"); }