### Question:
WikiTextUtils { public static String replaceAllFormulas(String text, List<MathTag> mathTags) { StringBuilder newText = new StringBuilder(text.length()); int offset = 0; for (MathTag tag : mathTags) { newText.append(text.substring(offset, tag.getPosition())); newText.append(tag.placeholder()); offset = tag.getPosition() + tag.getContent().length(); if (tag.getMarkUpType() == MathMarkUpType.LATEX && !tag.getContent().startsWith("<math")) { offset += 13; } } newText.append(text.substring(offset, text.length())); return newText.toString(); }  static List<MathTag> findMathTags(String text); static String replaceAllFormulas(String text, List<MathTag> mathTags); static String renderAllFormulae(String text); static String subsup(String markup); static String extractPlainText(String wikiMarkup); static String deLinkify(Word word, ParsedWikiDocument doc); static final Pattern MATH_TAG_PATTERN; }### Answer:
@Test public void replaceAllFormulas() { String text = "Text text <math>V = V_0</math> text text <math>V = V_1</math> text. " + "Text <math>V = V_2</math>."; MathTag tag1 = new MathTag(10, "<math>V = V_0</math>", MathMarkUpType.LATEX); MathTag tag2 = new MathTag(41, "<math>V = V_1</math>", MathMarkUpType.LATEX); MathTag tag3 = new MathTag(73, "<math>V = V_2</math>", MathMarkUpType.LATEX); List<MathTag> tags = Arrays.asList(tag1, tag2, tag3); String actual = WikiTextUtils.replaceAllFormulas(text, tags); String expected = "Text text " + tag1.placeholder() + " text text " + tag2.placeholder() + " text. " + "Text " + tag3.placeholder() + "."; assertEquals(expected, actual); }