summaryrefslogtreecommitdiff
path: root/src/test/java/com/keuin/kbackupfabric/TestUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/TestUtils.java')
-rw-r--r--src/test/java/com/keuin/kbackupfabric/TestUtils.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/TestUtils.java b/src/test/java/com/keuin/kbackupfabric/TestUtils.java
new file mode 100644
index 0000000..ea98ca1
--- /dev/null
+++ b/src/test/java/com/keuin/kbackupfabric/TestUtils.java
@@ -0,0 +1,35 @@
+package com.keuin.kbackupfabric;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Paths;
+
+public class TestUtils {
+
+ public static String getTempDirectory(String subDirectory) throws IOException {
+ String testTempPath;
+ String path = System.getenv("KB_TEMP_DIR");
+ if (path == null || path.isEmpty() || !new File(path).isDirectory()) {
+ path = findTempPath();
+ }
+ return Paths.get(path, subDirectory).toString();
+ }
+
+ private static String findTempPath() throws IOException {
+ String path;
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ // Windows
+ path = System.getProperty("java.io.tmpdir");
+ } else {
+ // Unix
+ path = System.getenv("XDG_RUNTIME_DIR");
+ if (!new File(path).isDirectory()) {
+ path = "/tmp";
+ }
+ }
+ if (!new File(path).isDirectory()) {
+ throw new IOException("Cannot find suitable temporary path");
+ }
+ return path;
+ }
+}