GoEnvironment { public String replaceVariables(String str) { Matcher m = envPat.matcher(str); StringBuffer sb = new StringBuffer(); while (m.find()) { String replacement = get(m.group(1)); if(replacement != null) { m.appendReplacement(sb, replacement); } } m.appendTail(sb); return sb.toString(); } GoEnvironment();  GoEnvironment(Map<String, String> defaultEnvironment); GoEnvironment putAll(Map<String, String> existing); Map<String,String> asMap(); String get(String name); String getOrElse(String name, String defaultValue); boolean has(String name); boolean isAbsent(String name); String traceBackUrl(); String triggeredUser(); String replaceVariables(String str); String artifactsLocationTemplate(); String artifactsLocationTemplate(String pipeline, String stageName, String jobName, String pipelineCounter, String stageCounter); boolean hasAWSUseIamRole();  }
@Test public void shouldReplaceWithEnvVariables() { final String envTestTemplate = "COUNT:${GO_STAGE_COUNTER} Name:${GO_STAGE_NAME} COUNT2:${GO_STAGE_COUNTER}"; final String replaced = goEnvironment.replaceVariables(envTestTemplate); assertThat(replaced, is("COUNT:1 Name:build-and-publish COUNT2:1")); }
@Test public void shouldNotReplaceUnknownEnvVariables() { final String envTestTemplate = "COUNT:${GO_STAGE_COUNTER} ${DOESNT_EXIST}"; final String replaced = goEnvironment.replaceVariables(envTestTemplate); assertThat(replaced, is("COUNT:1 ${DOESNT_EXIST}")); }