@Test public void allKnownVariablesAreReplaced() throws Exception { when(variableAccessor.getValue("VAR_1")).thenReturn(Optional.of("a")); when(variableAccessor.getValue("VAR_2")).thenReturn(Optional.of("b")); when(variableAccessor.getValue("VAR_3")).thenReturn(Optional.of("c")); final EnvironmentVariableReplacer replacer = new EnvironmentVariableReplacer(variableAccessor, problemHandler); assertThat(replacer.replaceKnownEnvironmentVariables("%{VAR_1}/%{VAR_2}/%{VAR_3}/file.txt")) .isEqualTo("a/b/c/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);  }