Skip to content

Commit

Permalink
Ignore null values in system-props/env-variables for test launch-configs
Browse files Browse the repository at this point in the history
Fixes #1832
  • Loading branch information
treilhes authored and HannesWell committed Nov 26, 2024
1 parent 70cf76f commit 85b9ac8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,30 @@ public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectT
private static final String SUREFIRE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=surefireArgLineValue
--argLineItem=surefireArgLineValue --undefinedArgLineItem=${undefinedProperty}
</argLine>
<systemPropertyVariables>
<surefireProp1>surefireProp1Value</surefireProp1>
<surefireEmptyProp>${undefinedProperty}</surefireEmptyProp>
</systemPropertyVariables>
<environmentVariables>
<surefireEnvironmentVariables1>surefireEnvironmentVariables1Value</surefireEnvironmentVariables1>
<surefireEmptyEnvironmentVariables1>${undefinedProperty}</surefireEmptyEnvironmentVariables1>
</environmentVariables>
</configuration>
""";
private static final String FAILSAFE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=failsafeArgLineValue
--argLineItem=failsafeArgLineValue --undefinedArgLineItem=${undefinedProperty}
</argLine>
<systemPropertyVariables>
<failsafeProp1>failsafeProp1Value</failsafeProp1>
<failsafeEmptyProp>${undefiniedProperty}</failsafeEmptyProp>
</systemPropertyVariables>
<environmentVariables>
<failsafeEnvironmentVariables1>failsafeEnvironmentVariables1Value</failsafeEnvironmentVariables1>
<failsafeEmptyEnvironmentVariables1>${undefinedProperty}</failsafeEmptyEnvironmentVariables1>
</environmentVariables>
</configuration>
""";
Expand Down Expand Up @@ -144,6 +148,10 @@ public void test_configuration_must_be_updated_with_surefire_config()

// check systemPropertyVariables
assertTrue(argLine.contains("-DsurefireProp1=surefireProp1Value"));

// check systemPropertyVariables with null value aren't set
assertTrue(!argLine.contains("-DsurefireEmptyProp="));

}

@Test
Expand Down Expand Up @@ -193,6 +201,9 @@ public void test_configuration_must_be_updated_with_failsafe_config()

// check systemPropertyVariables
assertTrue(argLine.contains("-DfailsafeProp1=failsafeProp1Value"));

// check systemPropertyVariables with null value aren't set
assertTrue(!argLine.contains("-DfailsafeEmptyProp="));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;
import java.util.StringJoiner;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -278,7 +279,9 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
launchArguments.add(args.argLine());
}
if(args.systemPropertyVariables() != null) {
args.systemPropertyVariables().forEach((key, value) -> launchArguments.add("-D" + key + "=" + value));
args.systemPropertyVariables().entrySet().stream() //
.filter(e -> e.getKey() != null && e.getValue() != null)
.forEach(e -> launchArguments.add("-D" + e.getKey() + "=" + e.getValue()));
}
copy.setAttribute(LAUNCH_CONFIG_VM_ARGUMENTS, launchArguments.toString());

Expand All @@ -294,7 +297,10 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
}

if(args.environmentVariables() != null) {
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, args.environmentVariables());
Map<String, String> filteredMap = args.environmentVariables().entrySet().stream()
.filter(entry -> entry.getKey() != null && entry.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, filteredMap);
}

copy.doSave();
Expand Down

0 comments on commit 85b9ac8

Please sign in to comment.