ShellCommandUtil { public static Result delete(String file, boolean force, boolean sudo) throws IOException, InterruptedException { List<String> command = new ArrayList<>(); if (WINDOWS) { command.add("del"); if (force) { command.add("/f"); } } else { command.add("/bin/rm"); if (force) { command.add("-f"); } } command.add(file); return runCommand(command, null, null, sudo); }  static void logOpenSslExitCode(String command, int exitCode); static String hideOpenSslPassword(String command); static String getOpenSslCommandResult(String command, int exitCode); static String getUnixFilePermissions(String path); static void setUnixFilePermissions(String mode, String path); static Result setFileOwner(String path, String ownerName); static Result setFileGroup(String path,  String groupName); static Result setFileMode(String path,
                                   boolean ownerReadable, boolean ownerWritable, boolean ownerExecutable,
                                   boolean groupReadable, boolean groupWritable, boolean groupExecutable,
                                   boolean otherReadable, boolean otherWritable, boolean otherExecutable); static Result pathExists(String path, boolean sudo); static Result mkdir(String directoryPath, boolean sudo); static Result copyFile(String srcFile, String destFile, boolean force, boolean sudo); static Result delete(String file, boolean force, boolean sudo); static Result runCommand(List<String> args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars); static Result runCommand(String[] args); static final boolean WINDOWS; static final boolean LINUX; static final boolean MAC; static final boolean UNIX_LIKE; static final String MASK_OWNER_ONLY_RW; static final String MASK_OWNER_ONLY_RWX; static final String MASK_EVERYBODY_RWX; }
@Test public void deleteExistingFile() throws Exception { File file = temp.newFile(); ShellCommandUtil.Result result = ShellCommandUtil.delete(file.getAbsolutePath(), false, false); Assert.assertTrue(result.getStderr(), result.isSuccessful()); Assert.assertFalse(file.exists()); }
@Test public void deleteNonexistentFile() throws Exception { File file = temp.newFile(); if (file.delete()) { ShellCommandUtil.Result result = ShellCommandUtil.delete(file.getAbsolutePath(), false, false); Assert.assertFalse(result.getStderr(), result.isSuccessful()); Assert.assertFalse(file.exists()); } }
@Test public void forceDeleteNonexistentFile() throws Exception { File file = temp.newFile(); if (file.delete()) { ShellCommandUtil.Result result = ShellCommandUtil.delete(file.getAbsolutePath(), true, false); Assert.assertTrue(result.getStderr(), result.isSuccessful()); Assert.assertFalse(file.exists()); } }