FormatUtil { public static String addDot(String text) { return isNotBlank(text) && !text.matches("^(?s).*(?:[.?!:;)\"]|</(?:p|ul|ol)>)\\s*$") && !text.endsWith(" ") ? text + "." : text; } private  FormatUtil(); static String arrayToString(Object[] o); static String collectionToString(Collection<?> c); static String addDot(String text); static String join(String delimiter, Object... texts); static String fixLineSeparator(String str);  }
@Test public void addDot() { assertThat(FormatUtil.addDot(null)).isNull(); assertThat(FormatUtil.addDot("")).isEqualTo(""); assertThat(FormatUtil.addDot(".")).isEqualTo("."); assertThat(FormatUtil.addDot("text.")).isEqualTo("text."); assertThat(FormatUtil.addDot("text")).isEqualTo("text."); assertThat(FormatUtil.addDot("text?")).isEqualTo("text?"); assertThat(FormatUtil.addDot("text!")).isEqualTo("text!"); assertThat(FormatUtil.addDot("text:")).isEqualTo("text:"); assertThat(FormatUtil.addDot("text;")).isEqualTo("text;"); assertThat(FormatUtil.addDot("text)")).isEqualTo("text)"); assertThat(FormatUtil.addDot("text\"")).isEqualTo("text\""); assertThat(FormatUtil.addDot("text+")).isEqualTo("text+."); assertThat(FormatUtil.addDot("text with html:\n<ul>\n<li>first</li>\n<li>second</li>\n</ul>")) .isEqualTo("text with html:\n<ul>\n<li>first</li>\n<li>second</li>\n</ul>"); assertThat(FormatUtil.addDot("text with html:\r\n<ul>\r\n<li>first</li>\r\n<li>second</li>\r\n</ul>")) .isEqualTo("text with html:\r\n<ul>\r\n<li>first</li>\r\n<li>second</li>\r\n</ul>"); assertThat(FormatUtil.addDot("text with html:\r\n<ol>\r\n<li>first</li>\r\n<li>second</li>\r\n</ol>")) .isEqualTo("text with html:\r\n<ol>\r\n<li>first</li>\r\n<li>second</li>\r\n</ol>"); assertThat(FormatUtil.addDot("text with html:\r\n<p>another paragraph</p>")) .isEqualTo("text with html:\r\n<p>another paragraph</p>"); }