This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git

commit eaaa2e5a086e1a1dd0ee539d551c43679d6ddc6c
Author: Arturo Bernal <[email protected]>
AuthorDate: Thu Oct 29 07:59:03 2026 +0100

    Fix versionDoesNotConnectToDaemon to survive DaemonParameters derivation
    
    DefaultClient's constructor always calls parameters.withJdkJavaOpts(...),
    which derives a brand new plain DaemonParameters and therefore drops any
    overridden method on a DaemonParameters subclass. The test was faking
    mvndHome()/registry() through such an override, so the daemon-less copy
    DefaultClient actually uses still fell through to the real environment
    resolution and failed when MVND_HOME could not be determined.
    
    Fake mvnd.home and mvnd.daemonStorage through system properties instead,
    restoring them afterwards, since that resolves the same way regardless of
    how many derived copies of DaemonParameters get created along the way.
---
 .../mvndaemon/mvnd/client/DefaultClientTest.java   | 47 ++++++++++++++--------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git 
a/client/src/test/java/org/mvndaemon/mvnd/client/DefaultClientTest.java 
b/client/src/test/java/org/mvndaemon/mvnd/client/DefaultClientTest.java
index 746f6610..1750a973 100644
--- a/client/src/test/java/org/mvndaemon/mvnd/client/DefaultClientTest.java
+++ b/client/src/test/java/org/mvndaemon/mvnd/client/DefaultClientTest.java
@@ -44,27 +44,40 @@ public class DefaultClientTest {
     /**
      * {@code --version} must complete without ever touching a daemon: with no 
fix, this would try to connect
      * to (and possibly spawn) one using the bogus paths below and fail or 
hang instead of returning quickly.
+     *
+     * <p>{@link DaemonParameters#mvndHome()} is faked through the {@code 
mvnd.home}/{@code mvnd.daemonStorage}
+     * system properties rather than by overriding {@link DaemonParameters}, 
because {@link DefaultClient}'s
+     * constructor derives its own copy of the given parameters (see {@link 
DaemonParameters#withJdkJavaOpts}),
+     * which would silently drop any overridden method.
      */
     @Test
     void versionDoesNotConnectToDaemon(@TempDir Path dir) {
         final Path bogusHome = dir.resolve("no-such-mvnd-home");
-        DaemonParameters parameters = new DaemonParameters() {
-            @Override
-            public Path mvndHome() {
-                return bogusHome;
-            }
-
-            @Override
-            public Path registry() {
-                return bogusHome.resolve("registry.bin");
-            }
-        };
-        DefaultClient client = new DefaultClient(parameters);
-
-        ExecutionResult result = client.execute(new NoopClientOutput(), 
Arrays.asList("--version"));
-
-        assertTrue(result.isSuccess());
-        assertEquals(0, result.getExitCode());
+        final String homeProperty = Environment.MVND_HOME.getProperty();
+        final String storageProperty = 
Environment.MVND_DAEMON_STORAGE.getProperty();
+        final String previousHome = System.getProperty(homeProperty);
+        final String previousStorage = System.getProperty(storageProperty);
+        System.setProperty(homeProperty, bogusHome.toString());
+        System.setProperty(storageProperty, 
bogusHome.resolve("storage").toString());
+        try {
+            DefaultClient client = new DefaultClient(new DaemonParameters());
+
+            ExecutionResult result = client.execute(new NoopClientOutput(), 
Arrays.asList("--version"));
+
+            assertTrue(result.isSuccess());
+            assertEquals(0, result.getExitCode());
+        } finally {
+            restoreProperty(homeProperty, previousHome);
+            restoreProperty(storageProperty, previousStorage);
+        }
+    }
+
+    private static void restoreProperty(final String key, final String 
previousValue) {
+        if (previousValue != null) {
+            System.setProperty(key, previousValue);
+        } else {
+            System.clearProperty(key);
+        }
     }
 
     private static final class NoopClientOutput implements ClientOutput {

Reply via email to