Create FileUtils#delete and write tests for FileUtils

This commit is contained in:
ljacqu
2016-09-17 00:42:18 +02:00
parent 0aa02b70f0
commit bdf8819aa7
4 changed files with 150 additions and 7 deletions
@@ -6,6 +6,7 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.FileUtils;
import fr.xephi.authme.util.StringUtils;
import org.apache.commons.mail.EmailConstants;
import org.apache.commons.mail.EmailException;
@@ -91,9 +92,7 @@ public class SendMailSSL {
}
sendEmail(content, email);
if (file != null) {
file.delete();
}
FileUtils.delete(file);
}
});
}
@@ -68,7 +68,22 @@ public final class FileUtils {
if (target.isDirectory()) {
purgeDirectory(target);
}
target.delete();
delete(target);
}
}
/**
* Delete the given file or directory and log a message if it was unsuccessful.
* Method is null safe and does nothing when null is passed.
*
* @param file the file to delete
*/
public static void delete(File file) {
if (file != null) {
boolean result = file.delete();
if (!result) {
ConsoleLogger.warning("Could not delete file '" + file + "'");
}
}
}
}
@@ -64,9 +64,7 @@ public class GeoLiteAPI {
return false;
}
} else {
if (!dataFile.delete()) {
ConsoleLogger.warning("Failed to delete GeoLiteAPI database");
}
FileUtils.delete(dataFile);
}
}
// Ok, let's try to download the data file!