### Question:
VariableUtils { public static void inject(HtmlAccessor accessor, String name, SafeHtml value) { accessor.setInnerHTML(replaceAll(accessor.getInnerHTML(), name, value)); }  static void inject(HtmlAccessor accessor, String name, SafeHtml value);  }### Answer:
@Test public void testWeCanReplaceASpecificVariable() throws Exception { doReturn("<p>This is %variable1% for variable1 but not for variable2</p>") .when(accessor) .getInnerHTML(); VariableUtils.inject(accessor, "variable1", SafeHtmlUtils.fromTrustedString("working")); verify(accessor).setInnerHTML("<p>This is working for variable1 but not for variable2</p>"); }
@Test public void testWeHtmlWithoutVariableStayTheSame() throws Exception { doReturn("<p class='aside'>This is a test</p>") .when(accessor) .getInnerHTML(); VariableUtils.inject(accessor, "variable", SafeHtmlUtils.fromTrustedString("value")); verify(accessor).setInnerHTML("<p class='aside'>This is a test</p>"); }
@Test public void testWeCanReplaceMultipleVariables() throws Exception { doReturn("<p class='%variable%'>This is %variable%</p>") .when(accessor) .getInnerHTML(); VariableUtils.inject(accessor, "variable", SafeHtmlUtils.fromTrustedString("working")); verify(accessor).setInnerHTML("<p class='working'>This is working</p>"); }