FileLocator implements Locator<FileLocation> { @Override public File copyToDirectory(FileLocation fileLocation, File toDir) { File file = locate(fileLocation); if (file != null && file.exists()) { try { FileUtils.copyFileToDirectory(file, toDir); file = new File(toDir, file.getName()); } catch (IOException e) { throw new IllegalStateException("Fail to copy file to directory: " + toDir, e); } } return file; }  @Override File locate(FileLocation location); @Override File copyToDirectory(FileLocation fileLocation, File toDir); @Override File copyToFile(FileLocation fileLocation, File toFile); @Override InputStream openInputStream(FileLocation location);  }
@Test public void copy_to_directory() throws Exception { FileLocator locator = new FileLocator(); File fileToCopy = new File(getClass().getResource("/com/sonar/orchestrator/locator/FileLocatorTest/foo.txt").toURI()); File toDir = temp.newFolder(); File copy = locator.copyToDirectory(FileLocation.of(fileToCopy), toDir); assertThat(copy).isNotNull(); assertThat(copy).isEqualTo(new File(toDir, "foo.txt")); assertThat(copy.length()).isGreaterThan(0L); }