### Question:
HtmlUtils { public static String applyBoldFragments(String fragment, String sourceText) { if (Strings.isNullOrEmpty(fragment) || Strings.isNullOrEmpty(sourceText)) { return "<html>" + sourceText + "</html>"; } String lowerFragment = fragment.toLowerCase(); String lowerSource = sourceText.toLowerCase(); int sourceIndex = 0; int matchIndex; StringBuilder sb = new StringBuilder("<html>"); do { matchIndex = lowerSource.indexOf(lowerFragment, sourceIndex); if (matchIndex > -1) { sb.append(sourceText.substring(sourceIndex, matchIndex)) .append("<b>") .append(sourceText.substring(matchIndex, matchIndex + fragment.length())) .append("</b>"); sourceIndex = matchIndex + fragment.length(); } } while (matchIndex > -1); sb.append(sourceText.substring(sourceIndex)); sb.append("</html>"); return sb.toString(); } private  HtmlUtils(); static String localiseWithLineBreaks(String[] lines); static String localiseWithCenteredLinedBreaks(String[] lines); static String applyBoldFragments(String fragment, String sourceText); static String stripHtml(String html);  }### Answer:
@Test public void testApplyBoldFragments_NoFragment() throws Exception { Configurations.currentConfiguration = new Configuration(); String expected = "<html>hello world</html>"; assertThat(HtmlUtils.applyBoldFragments("","hello world")).isEqualTo(expected); }
@Test public void testApplyBoldFragments_VariableCase() throws Exception { Configurations.currentConfiguration = new Configuration(); String expected = "<html><b>abc</b> <b>ABC</b> <b>Abc</b> <b>AbC</b> <b>abC</b> hello<b>abc</b>world</html>"; assertThat(HtmlUtils.applyBoldFragments("abc","abc ABC Abc AbC abC helloabcworld")).isEqualTo(expected); }
@Test public void testApplyBoldFragments_NoMatch() throws Exception { Configurations.currentConfiguration = new Configuration(); String expected = "<html>hello world</html>"; assertThat(HtmlUtils.applyBoldFragments("abc","hello world")).isEqualTo(expected); }
@Test public void testApplyBoldFragments_MatchAtEnd() throws Exception { Configurations.currentConfiguration = new Configuration(); String expected = "<html>hello world<b>abc</b></html>"; assertThat(HtmlUtils.applyBoldFragments("abc","hello worldabc")).isEqualTo(expected); }
@Test public void testApplyBoldFragments_PartialMatches() throws Exception { Configurations.currentConfiguration = new Configuration(); String expected = "<html>ab ab <b>abc</b><b>abc</b><b>abc</b><b>abc</b></html>"; assertThat(HtmlUtils.applyBoldFragments("abc","ab ab abcabcabcabc")).isEqualTo(expected); }