@Test public void nestedVariablesAreReplaced() throws Exception { when(variableAccessor.getValue("A")).thenReturn(Optional.of("A_VAR")); when(variableAccessor.getValue("A_VAR")).thenReturn(Optional.of("xyz")); when(variableAccessor.getValue("B")).thenReturn(Optional.of("B_VAR")); when(variableAccessor.getValue("X_B_VAR_Y")).thenReturn(Optional.of("C_VAR")); when(variableAccessor.getValue("C_VAR")).thenReturn(Optional.of("abc")); final EnvironmentVariableReplacer replacer = new EnvironmentVariableReplacer(variableAccessor, problemHandler); assertThat(replacer.replaceKnownEnvironmentVariables("%{%{A}}/%{%{X_%{B}_Y}}/file.txt")) .isEqualTo("xyz/abc/file.txt"); verifyNoInteractions(problemHandler); }
public String replaceKnownEnvironmentVariables(final String path) { final Set<String> undefinedVarNames = new LinkedHashSet<>(); String before = path; String after = replaceWithProblemReporting(before, undefinedVarNames); while (!before.equals(after)) { before = after; after = replaceWithProblemReporting(before, undefinedVarNames); } undefinedVarNames.forEach(problemHandler); return after; }
EnvironmentVariableReplacer { public String replaceKnownEnvironmentVariables(final String path) { final Set<String> undefinedVarNames = new LinkedHashSet<>(); String before = path; String after = replaceWithProblemReporting(before, undefinedVarNames); while (!before.equals(after)) { before = after; after = replaceWithProblemReporting(before, undefinedVarNames); } undefinedVarNames.forEach(problemHandler); return after; } }
EnvironmentVariableReplacer { public String replaceKnownEnvironmentVariables(final String path) { final Set<String> undefinedVarNames = new LinkedHashSet<>(); String before = path; String after = replaceWithProblemReporting(before, undefinedVarNames); while (!before.equals(after)) { before = after; after = replaceWithProblemReporting(before, undefinedVarNames); } undefinedVarNames.forEach(problemHandler); return after; } EnvironmentVariableReplacer();  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor);  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor,
            final Consumer<String> problemHandler); }
EnvironmentVariableReplacer { public String replaceKnownEnvironmentVariables(final String path) { final Set<String> undefinedVarNames = new LinkedHashSet<>(); String before = path; String after = replaceWithProblemReporting(before, undefinedVarNames); while (!before.equals(after)) { before = after; after = replaceWithProblemReporting(before, undefinedVarNames); } undefinedVarNames.forEach(problemHandler); return after; } EnvironmentVariableReplacer();  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor);  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor,
            final Consumer<String> problemHandler); boolean hasUnknownEnvironmentVariables(final String path); String replaceKnownEnvironmentVariables(final String path); }
EnvironmentVariableReplacer { public String replaceKnownEnvironmentVariables(final String path) { final Set<String> undefinedVarNames = new LinkedHashSet<>(); String before = path; String after = replaceWithProblemReporting(before, undefinedVarNames); while (!before.equals(after)) { before = after; after = replaceWithProblemReporting(before, undefinedVarNames); } undefinedVarNames.forEach(problemHandler); return after; } EnvironmentVariableReplacer();  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor);  EnvironmentVariableReplacer(final SystemVariableAccessor variableAccessor,
            final Consumer<String> problemHandler); boolean hasUnknownEnvironmentVariables(final String path); String replaceKnownEnvironmentVariables(final String path);  }