### Question:
StringUtils { public static String replaceVariable(final String string, final String name, final String value) { return string.replace(String.format("${%s}", name), value); } private  StringUtils(); static boolean isNullOrEmpty(final String str); static boolean isNullOrWhitespace(final String str); static String replaceVariable(final String string, final String name, final String value); static boolean equalsIgnoreCase(
      Optional<String> optionalString1, Optional<String> optionalString2);  }### Answer:
@Test public void replaceVariableOnStringWithoutVariablesReturnsStringItself() { MatcherAssert.assertThat( StringUtils.replaceVariable("quick brown fox", "variable", "-"), IsEqual.equalTo("quick brown fox")); MatcherAssert.assertThat(StringUtils.replaceVariable("", "variable", "-"), IsEqual.equalTo("")); MatcherAssert.assertThat( StringUtils.replaceVariable("variable", "variable", "-"), IsEqual.equalTo("variable")); }
@Test public void replaceVariableReplaceOnlyExactVariables() { MatcherAssert.assertThat( StringUtils.replaceVariable("${ }", " ", "-"), IsEqual.equalTo("${ }")); MatcherAssert.assertThat( StringUtils.replaceVariable("${ foo}", "foo", "-"), IsEqual.equalTo("${ foo}")); }
@Test public void replaceVariableOnStringWithVariablesReturnsCorrectResults() { MatcherAssert.assertThat( StringUtils.replaceVariable("${variable}", "variable", "-"), IsEqual.equalTo("-")); MatcherAssert.assertThat(StringUtils.replaceVariable("${ }", " ", "-"), IsEqual.equalTo("-")); MatcherAssert.assertThat( StringUtils.replaceVariable("${ }", " ", "-"), IsEqual.equalTo("-")); }
@Test public void replaceVariableMustMatchVariableCaseSensitively() { MatcherAssert.assertThat( StringUtils.replaceVariable("${Variable}", "variable", "-"), IsEqual.equalTo("${Variable}")); MatcherAssert.assertThat( StringUtils.replaceVariable("${Variable}", "xx", "-"), IsEqual.equalTo("${Variable}")); MatcherAssert.assertThat( StringUtils.replaceVariable("${Variable}", "", "-"), IsEqual.equalTo("${Variable}")); }
@Test public void replaceVariableCanReplaceVariableOccurrencesBetweenText() { MatcherAssert.assertThat( StringUtils.replaceVariable("quick ${color} fox", "color", "brown"), IsEqual.equalTo("quick brown fox")); MatcherAssert.assertThat( StringUtils.replaceVariable("jumps over the ${adj} dog", "adj", "lazy"), IsEqual.equalTo("jumps over the lazy dog")); }
@Test public void replaceVariableCanReplaceMultipleOccurrencesOfVariable() { MatcherAssert.assertThat( StringUtils.replaceVariable("quick ${color} ${color} fox", "color", "brown"), IsEqual.equalTo("quick brown brown fox")); MatcherAssert.assertThat( StringUtils.replaceVariable("Buffalo ${} Buffalo ${} ${} ${} Buffalo ${}", "", "buffalo"), IsEqual.equalTo("Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo")); }