AbstractBuildExecutor { static void appendCoverageArgumentToOpts(Map<String, String> environmentVariables, Configuration config, String optsVariableName) { String jaCoCoArgument = JaCoCoArgumentsBuilder.getJaCoCoArgument(config); if (jaCoCoArgument != null) { if (environmentVariables.containsKey(optsVariableName)) { String opts = environmentVariables.get(optsVariableName) + " " + jaCoCoArgument; environmentVariables.put(optsVariableName, opts); } else { environmentVariables.put(optsVariableName, jaCoCoArgument); } } if (environmentVariables.containsKey(optsVariableName)) { LOG.info("{}: {}", optsVariableName, environmentVariables.get(optsVariableName)); } }    }
@Test public void shouldNotAppendCoverageArgumentToOptsByDefault() { Map<String, String> env = ImmutableMap.of(); Configuration config = Configuration.create(new HashMap<String, String>()); AbstractBuildExecutor.appendCoverageArgumentToOpts(env, config, "SONAR_OPTS"); }
@Test public void shouldAppendCoverageArgumentToOpts() { Map<String, String> env = new HashMap<>(); env.put("SONAR_OPTS", "foo"); Configuration config = Configuration.create(singletonMap("orchestrator.computeCoverage", "true")); AbstractBuildExecutor.appendCoverageArgumentToOpts(env, config, "SONAR_OPTS"); assertThat(env.get("SONAR_OPTS")).startsWith("foo -javaagent:"); }
@Test public void shouldCreateEnvironmentVariableIfNeeded() { Map<String, String> env = new HashMap<>(); Configuration config = Configuration.create(singletonMap("orchestrator.computeCoverage", "true")); AbstractBuildExecutor.appendCoverageArgumentToOpts(env, config, "SONAR_OPTS"); assertThat(env.get("SONAR_OPTS")).startsWith("-javaagent:"); }