Words { public static String wrap(String str, int wrapLength) { return wrap(str, wrapLength, null, false); } private  Words(); static String wrap(String str, int wrapLength); static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords); static String capitalize(String str); static String capitalize(String str, char[] delimiters); static String capitalizeFully(String str); static String capitalizeFully(String str, char[] delimiters); static String uncapitalize(String str); static String uncapitalize(String str, char[] delimiters); static String initials(String str); static String initials(String str, char[] delimiters);  }
@Test public void testWrap_StringInt() { assertEquals(null, wrap(null, 20)); assertEquals(null, wrap(null, -1)); assertEquals("", wrap("", 20)); assertEquals("", wrap("", -1)); String systemNewLine = System.getProperty("line.separator"); String input = "Here is one line of text that is going to be wrapped after 20 columns."; String expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns."; assertEquals(expected, wrap(input, 20)); input = "Click here to jump to the jakarta website - http: expected = "Click here to jump" + systemNewLine + "to the jakarta" + systemNewLine + "website -" + systemNewLine + "http: assertEquals(expected, wrap(input, 20)); input = "Click here, http: expected = "Click here," + systemNewLine + "http: + "to jump to the" + systemNewLine + "jakarta website"; assertEquals(expected, wrap(input, 20)); }
@Test public void testWrap_StringIntStringBoolean() { assertEquals(null, wrap(null, 20, "\n", false)); assertEquals(null, wrap(null, 20, "\n", true)); assertEquals(null, wrap(null, 20, null, true)); assertEquals(null, wrap(null, 20, null, false)); assertEquals(null, wrap(null, -1, null, true)); assertEquals(null, wrap(null, -1, null, false)); assertEquals("", wrap("", 20, "\n", false)); assertEquals("", wrap("", 20, "\n", true)); assertEquals("", wrap("", 20, null, false)); assertEquals("", wrap("", 20, null, true)); assertEquals("", wrap("", -1, null, false)); assertEquals("", wrap("", -1, null, true)); String input = "Here is one line of text that is going to be wrapped after 20 columns."; String expected = "Here is one line of\ntext that is going\nto be wrapped after\n20 columns."; assertEquals(expected, wrap(input, 20, "\n", false)); assertEquals(expected, wrap(input, 20, "\n", true)); input = "Here is one line of text that is going to be wrapped after 20 columns."; expected = "Here is one line of<br />text that is going<br />to be wrapped after<br />20 columns."; assertEquals(expected, wrap(input, 20, "<br />", false)); assertEquals(expected, wrap(input, 20, "<br />", true)); input = "Here is one line"; expected = "Here\nis one\nline"; assertEquals(expected, wrap(input, 6, "\n", false)); expected = "Here\nis\none\nline"; assertEquals(expected, wrap(input, 2, "\n", false)); assertEquals(expected, wrap(input, -1, "\n", false)); String systemNewLine = System.getProperty("line.separator"); input = "Here is one line of text that is going to be wrapped after 20 columns."; expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns."; assertEquals(expected, wrap(input, 20, null, false)); assertEquals(expected, wrap(input, 20, null, true)); input = " Here: is one line of text that is going to be wrapped after 20 columns."; expected = "Here: is one line\nof text that is \ngoing to be \nwrapped after 20 \ncolumns."; assertEquals(expected, wrap(input, 20, "\n", false)); assertEquals(expected, wrap(input, 20, "\n", true)); input = "Here is\tone line of text that is going to be wrapped after 20 columns."; expected = "Here is\tone line of\ntext that is going\nto be wrapped after\n20 columns."; assertEquals(expected, wrap(input, 20, "\n", false)); assertEquals(expected, wrap(input, 20, "\n", true)); input = "Here is one line of\ttext that is going to be wrapped after 20 columns."; expected = "Here is one line\nof\ttext that is\ngoing to be wrapped\nafter 20 columns."; assertEquals(expected, wrap(input, 20, "\n", false)); assertEquals(expected, wrap(input, 20, "\n", true)); input = "Click here to jump to the jakarta website - http: expected = "Click here to jump\nto the jakarta\nwebsite -\nhttp: assertEquals(expected, wrap(input, 20, "\n", false)); expected = "Click here to jump\nto the jakarta\nwebsite -\nhttp: assertEquals(expected, wrap(input, 20, "\n", true)); input = "Click here, http: expected = "Click here,\nhttp: assertEquals(expected, wrap(input, 20, "\n", false)); expected = "Click here,\nhttp: assertEquals(expected, wrap(input, 20, "\n", true)); }