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