Linky { public static String linkify(List<Link> links, String text) { int addedChars = 0; for (Link link : links) { StringBuilder stringBuilder = new StringBuilder(text); int start = link.getStart(); int end = link.getEnd(); String href = link.getHref(); String openTag = String.format(aherf, href); stringBuilder.insert(addedChars + start, openTag); addedChars += openTag.length(); stringBuilder.insert(addedChars + end, closeTag); addedChars += closeTag.length(); text = stringBuilder.toString(); } return text; }  static String linkify(List<Link> links, String text); static boolean hasLinks(List<Link> links);  }
@Test public void testLinkify_firstAndThirdLink() throws Exception { links = new ArrayList<>(); links.add(firstLink()); links.add(thirdLink()); final String expected = "<a href=\"http: assertThat(linkify(links, mockString)).isEqualTo(expected); }
@Test public void testLinkify_noLink() throws Exception { links = new ArrayList<>(); final String expected = mockString; assertThat(linkify(links, mockString)).isEqualTo(expected); }
@Test public void testLinkify_oneLink() throws Exception { links = new ArrayList<>(); links.add(firstLink()); final String expected = "<a href=\"http: assertThat(linkify(links, mockString)).isEqualTo(expected); }
@Test public void testLinkify_secondLink() throws Exception { links = new ArrayList<>(); links.add(secondLink()); final String expected = "One <a href=\"http: assertThat(linkify(links, mockString)).isEqualTo(expected); }
@Test public void testLinkify_thirdLink() throws Exception { links = new ArrayList<>(); links.add(thirdLink()); final String expected = "One two <a href=\"http: assertThat(linkify(links, mockString)).isEqualTo(expected); }