### Question:
FileUtils { public static boolean copyFileFromResource(File destinationFile, String resourcePath) { if (destinationFile.exists()) { return true; } else if (!createDirectory(destinationFile.getParentFile())) { ConsoleLogger.warning("Cannot create parent directories for '" + destinationFile + "'"); return false; } try (InputStream is = getResourceFromJar(resourcePath)) { if (is == null) { ConsoleLogger.warning(format("Cannot copy resource '%s' to file '%s': cannot load resource", resourcePath, destinationFile.getPath())); } else { java.nio.file.Files.copy(is, destinationFile.toPath()); return true; } } catch (IOException e) { ConsoleLogger.logException(format("Cannot copy resource '%s' to file '%s':", resourcePath, destinationFile.getPath()), e); } return false; } private  FileUtils(); static boolean copyFileFromResource(File destinationFile, String resourcePath); static boolean createDirectory(File dir); static InputStream getResourceFromJar(String path); static void purgeDirectory(File directory); static void delete(File file); static void create(File file); static String makePath(String... elements); static String createCurrentTimeString(); static String createBackupFilePath(File file);  }### Answer:
@Test public void shouldNotCopyFile() throws IOException { File folder = temporaryFolder.newFolder(); File file = new File(folder, "config.yml"); File emailJarFile = TestHelper.getJarFile("/email.html"); Files.copy(emailJarFile, file); boolean result = FileUtils.copyFileFromResource(file, "config.yml"); assertThat(result, equalTo(true)); assertThat(file.length(), equalTo(emailJarFile.length())); }
@Test public void shouldCopyFileFromJar() throws IOException { File folder = temporaryFolder.newFolder(); File file = new File(folder, "some/folders/welcome.txt"); boolean result = FileUtils.copyFileFromResource(file, "welcome.txt"); assertThat(result, equalTo(true)); assertThat(file.exists(), equalTo(true)); File configJarFile = TestHelper.getJarFile("/welcome.txt"); assertThat(file.length(), equalTo(configJarFile.length())); }
@Test public void shouldReturnFalseForInvalidJarFile() throws IOException { File folder = temporaryFolder.newFolder(); File file = new File(folder, "bogus"); boolean result = FileUtils.copyFileFromResource(file, "does-not-exist"); assertThat(result, equalTo(false)); assertThat(file.exists(), equalTo(false)); }
@Test public void shouldReturnFalseForParentInvalidParentFolders() throws IOException { File folder = temporaryFolder.newFolder(); new File(folder, "hello").createNewFile(); File fileToCreate = new File(folder, "hello/test"); boolean result = FileUtils.copyFileFromResource(fileToCreate, "welcome.txt"); assertThat(result, equalTo(false)); }