You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/04/28 12:18:21 UTC

[GitHub] [maven-surefire] akomakom commented on a change in pull request #289: SUREFIRE-1784 Fork JVM defined by jvm param should not inherit JAVA_HOME from Maven process

akomakom commented on a change in pull request #289:
URL: https://github.com/apache/maven-surefire/pull/289#discussion_r416565218



##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java
##########
@@ -154,6 +157,36 @@ public void shouldChangeJavaHomeFromToolchain() throws Exception
         assertThat( mojo.getEnvironmentVariables() ).includes( MapAssert.entry( "JAVA_HOME", "/some/path" ) );
     }
 
+    /**
+     * Ensures that the environmentVariables map for launching a test jvm
+     * contains a jvm parameter-driven entry when jvm is set.
+     */
+    @Test
+    public void shouldChangeJavaHomeFromJvm() throws Exception
+    {
+        AbstractSurefireMojoTest.Mojo mojo = new AbstractSurefireMojoTest.Mojo();
+        String fakeJava = "/some/path/to/jdk/bin/java";
+        mojo.setJvm( fakeJava );
+
+        //Set up a mocked File-object
+        File mockedFile = mock( File.class );
+        when( mockedFile.getAbsoluteFile() ).thenReturn( mockedFile );
+        when( mockedFile.getPath() ).thenReturn( fakeJava );
+        when( mockedFile.getName() ).thenReturn( "java" );
+        when( mockedFile.isFile() ).thenReturn( true );
+
+        //Trap constructor calls to return the mocked File-object
+        whenNew( File.class ).
+            withParameterTypes( String.class ).
+            withArguments( anyString() ).
+            thenReturn( mockedFile );
+
+        assertThat( mojo.getEnvironmentVariables() ).isEmpty();
+        invokeMethod( mojo, "getEffectiveJvm" );
+        assertThat( mojo.getEnvironmentVariables() ).includes( MapAssert.entry( "JAVA_HOME", "/some/path/to/jdk" ) );

Review comment:
       That makes sense, I never think about Windows :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org