Wrap { private Wrap() { } private  Wrap(); static int length(final CharSequence cs); static boolean isBlank(final CharSequence cs); static String wrap(final String str, final int wrapLength); static String wrap(final String str, final int wrapLength, final String newLineStr, final boolean wrapLongWords); static String wrap(final String str, int wrapLength, String newLineStr, final boolean wrapLongWords, String wrapOn);  }
@Test public void testWrap_StringInt() { assertNull(Wrap.wrap(null, 20)); assertNull(Wrap.wrap(null, -1)); assertEquals("", Wrap.wrap("", 20)); assertEquals("", Wrap.wrap("", -1)); final String systemNewLine = System.lineSeparator(); 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.wrap(input, 20)); input = "Click here to jump to the commons website - https: expected = "Click here to jump" + systemNewLine + "to the commons" + systemNewLine + "website -" + systemNewLine + "https: assertEquals(expected, Wrap.wrap(input, 20)); input = "Click here, https: expected = "Click here," + systemNewLine + "https: + "to jump to the" + systemNewLine + "commons website"; assertEquals(expected, Wrap.wrap(input, 20)); input = "word1 word2 word3"; expected = "word1 " + systemNewLine + "word2 " + systemNewLine + "word3"; assertEquals(expected, Wrap.wrap(input, 7)); }
@Test public void testWrap_StringIntStringBoolean() { assertNull(Wrap.wrap(null, 20, "\n", false)); assertNull(Wrap.wrap(null, 20, "\n", true)); assertNull(Wrap.wrap(null, 20, null, true)); assertNull(Wrap.wrap(null, 20, null, false)); assertNull(Wrap.wrap(null, -1, null, true)); assertNull(Wrap.wrap(null, -1, null, false)); assertEquals("", Wrap.wrap("", 20, "\n", false)); assertEquals("", Wrap.wrap("", 20, "\n", true)); assertEquals("", Wrap.wrap("", 20, null, false)); assertEquals("", Wrap.wrap("", 20, null, true)); assertEquals("", Wrap.wrap("", -1, null, false)); assertEquals("", Wrap.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.wrap(input, 20, "\n", false)); assertEquals(expected, Wrap.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.wrap(input, 20, "<br />", false)); assertEquals(expected, Wrap.wrap(input, 20, "<br />", true)); input = "Here is one line"; expected = "Here\nis one\nline"; assertEquals(expected, Wrap.wrap(input, 6, "\n", false)); expected = "Here\nis\none\nline"; assertEquals(expected, Wrap.wrap(input, 2, "\n", false)); assertEquals(expected, Wrap.wrap(input, -1, "\n", false)); final String systemNewLine = System.lineSeparator(); 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.wrap(input, 20, null, false)); assertEquals(expected, Wrap.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.wrap(input, 20, "\n", false)); assertEquals(expected, Wrap.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.wrap(input, 20, "\n", false)); assertEquals(expected, Wrap.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.wrap(input, 20, "\n", false)); assertEquals(expected, Wrap.wrap(input, 20, "\n", true)); input = "Click here to jump to the commons website - https: expected = "Click here to jump\nto the commons\nwebsite -\nhttps: assertEquals(expected, Wrap.wrap(input, 20, "\n", false)); expected = "Click here to jump\nto the commons\nwebsite -\nhttps: assertEquals(expected, Wrap.wrap(input, 20, "\n", true)); input = "Click here, https: expected = "Click here,\nhttps: assertEquals(expected, Wrap.wrap(input, 20, "\n", false)); expected = "Click here,\nhttps: assertEquals(expected, Wrap.wrap(input, 20, "\n", true)); }
@Test public void testWrap_StringIntStringBooleanString() { String input = "flammable/inflammable"; String expected = "flammable/inflammable"; assertEquals(expected, Wrap.wrap(input, 30, "\n", false, "/")); expected = "flammable\ninflammable"; assertEquals(expected, Wrap.wrap(input, 2, "\n", false, "/")); expected = "flammable\ninflammab\nle"; assertEquals(expected, Wrap.wrap(input, 9, "\n", true, "/")); expected = "flammable\ninflammable"; assertEquals(expected, Wrap.wrap(input, 15, "\n", true, "/")); input = "flammableinflammable"; expected = "flammableinflam\nmable"; assertEquals(expected, Wrap.wrap(input, 15, "\n", true, "/")); }
@Test public void testLANG1292() { Wrap.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 70); }
@Test public void testLANG1397() { Wrap.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Integer.MAX_VALUE); }