Execute home dir tests twice, once with HOME and once with user.home
@@ -11,6 +11,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.UnaryOperator;
import com.google.common.collect.ImmutableMap;
import com.google.gson.GsonBuilder;
@@ -302,14 +304,31 @@ public class AuthConfigFactoryTest {
ReflectionAccessor.getInstance().makeAccessible(envField);
@SuppressWarnings("unchecked")
UnaryOperator<String> origEnv = (UnaryOperator<String>) envField.get(null);
+ String origUserHome = System.getProperty("user.home");
try {
- File tempDir = Files.createTempDirectory("d-m-p").toFile();
+ final AtomicReference<String> homeDir = new AtomicReference<>();
UnaryOperator<String> homeEnv = name -> {
- return "HOME".equals(name) ? tempDir.getAbsolutePath() : origEnv.apply(name);
+ return "HOME".equals(name) ? homeDir.get() : origEnv.apply(name);
};
envField.set(null, homeEnv);
+
+ // execute with HOME environment variable (preferred)
+ File tempDir = Files.createTempDirectory("d-m-p").toFile();
+ homeDir.set(tempDir.getAbsolutePath());
+ System.setProperty("user.home", "/dev/null/ignore/me");
+ executor.exec(tempDir);
+
+ // execute with user.home system property (fallback)
+ tempDir = Files.createTempDirectory("d-m-p").toFile();
+ homeDir.set(null);
+ System.setProperty("user.home", tempDir.getAbsolutePath());
executor.exec(tempDir);
} finally {
+ if (origUserHome == null) {
+ System.clearProperty("user.home");
+ } else {
+ System.setProperty("user.home", origUserHome);
+ }
envField.set(null, origEnv);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
