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