Skip to content

Commit

Permalink
Merge pull request #2479 from dvargas46/develop
Browse files Browse the repository at this point in the history
fix system properties issue on runner #2474
  • Loading branch information
ptrthomas authored Jan 18, 2024
2 parents 3affad9 + 9bc789e commit 48f2b23
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
4 changes: 1 addition & 3 deletions karate-core/src/main/java/com/intuit/karate/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ public List<FeatureCall> resolveAll() {
if (systemProperties == null) {
systemProperties = new HashMap(System.getProperties());
} else {
Map temp = new HashMap(System.getProperties());
temp.putAll(systemProperties); // make sure user-specified takes precedence
systemProperties = temp;
systemProperties.putAll(new HashMap(System.getProperties()));
}
// env
String tempOptions = StringUtils.trimToNull(systemProperties.get(Constants.KARATE_OPTIONS));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.intuit.karate;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import com.intuit.karate.Runner.Builder;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SystemPropertiesTest {

private static final String TEST_PROP = "testProperty";

@AfterEach
void clearTestProperty() {
System.clearProperty(TEST_PROP);
}

@Test
void testSystemPropertiesSetOnRunner() {
Builder<?> builder = Runner.builder().systemProperty(TEST_PROP, "setOnRunner");
builder.resolveAll();
String propertyValue = builder.systemProperties.get(TEST_PROP);
assertEquals(propertyValue, "setOnRunner");
}

@Test
void testSystemPropertiesSetOnJVM() {
System.setProperty(TEST_PROP, "setOnJVM"); // -DtestProperty=setOnJVM
Builder<?> builder = Runner.builder();
builder.resolveAll();
String propertyValue = builder.systemProperties.get(TEST_PROP);
assertEquals(propertyValue, "setOnJVM");
}

@Test
void testPrecedenceOfSystemPropertiesSetOnRunnerAndJVM() {
System.setProperty(TEST_PROP, "setOnJVM"); // -DtestProperty=setOnJVM
Builder<?> builder = Runner.builder().systemProperty(TEST_PROP, "setOnRunner");
builder.resolveAll();
String propertyValue = builder.systemProperties.get(TEST_PROP);
assertEquals(propertyValue, "setOnJVM");
}
}

0 comments on commit 48f2b23

Please sign in to comment.