View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.lang3.text;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  import static org.junit.jupiter.params.provider.Arguments.arguments;
25  
26  import java.lang.reflect.Constructor;
27  import java.lang.reflect.Modifier;
28  import java.util.stream.Stream;
29  
30  import org.apache.commons.lang3.AbstractLangTest;
31  import org.junit.jupiter.api.Test;
32  import org.junit.jupiter.api.Timeout;
33  import org.junit.jupiter.params.ParameterizedTest;
34  import org.junit.jupiter.params.provider.Arguments;
35  import org.junit.jupiter.params.provider.MethodSource;
36  
37  /**
38   * Tests for WordUtils class.
39   */
40  @Deprecated
41  class WordUtilsTest extends AbstractLangTest {
42  
43      static Stream<Arguments> testWrapStringIntStringBooleanString() {
44          return Stream.of(
45                  // null passthrough
46                  arguments(null, -1, false, "/", null),
47                  // no changes test
48                  arguments("flammable/inflammable", 30, false, "/", "flammable/inflammable"),
49                  // wrap on / and small width
50                  arguments("flammable/inflammable", 2, false, "/", "flammable\ninflammable"),
51                  // wrap long words on / 1
52                  arguments("flammable/inflammable", 9, true, "/", "flammable\ninflammab\nle"),
53                  // wrap long words on / 2
54                  arguments("flammable/inflammable", 15, true, "/", "flammable\ninflammable"),
55                  // wrap long words on / 3
56                  arguments("flammableinflammable", 15, true, "/", "flammableinflam\nmable"),
57                  // default values
58                  arguments("a/a/a/a", -1, false, "/", "a\na\na\na"),
59                  arguments("a a a a", 1, false, null, "a\na\na\na"),
60                  // strip leading / keep trailing
61                  arguments("///abc///def///ghi", 3, false, "/", "abc\ndef\nghi"),
62                  arguments("///abc///def///ghi", 4, false, "/", "abc/\ndef/\nghi"),
63                  arguments("///abc///def///ghi", 5, false, "/", "abc//\ndef//\nghi"),
64                  // keep only two trailing, wrap on third
65                  arguments("///abc///def///ghi", 6, false, "/", "abc//\ndef//\nghi"),
66                  // zero-width regex match must advance to avoid an infinite loop
67                  arguments("abcabc", 3, false, "(?=a)", "abc\nabc"),
68                  arguments("abcdefabcdef", 4, false, "(?=a)", "abcdef\nabcdef"),
69                  arguments("abcdefabcdef", 4, true, "(?=a)", "abcd\nef\nabcd\nef"),
70                  // width two regex
71                  arguments("abc\\/abc", 3, false, "\\\\/", "abc\nabc"),
72                  arguments("abcdef\\/abcdef", 4, false, "\\\\/", "abcdef\nabcdef"),
73                  arguments("abcdef\\/abcdef", 4, true, "\\\\/", "abcd\nef\nabcd\nef"),
74                  // variable-width regex
75                  arguments(".abc.-def.--ghi", 5, false, "[.]-*", "abc\ndef\nghi")
76                  );
77      }
78  
79      @Test
80      void testCapitalize_String() {
81          assertNull(WordUtils.capitalize(null));
82          assertEquals("", WordUtils.capitalize(""));
83          assertEquals("  ", WordUtils.capitalize("  "));
84  
85          assertEquals("I", WordUtils.capitalize("I"));
86          assertEquals("I", WordUtils.capitalize("i"));
87          assertEquals("I Am Here 123", WordUtils.capitalize("i am here 123"));
88          assertEquals("I Am Here 123", WordUtils.capitalize("I Am Here 123"));
89          assertEquals("I Am HERE 123", WordUtils.capitalize("i am HERE 123"));
90          assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123"));
91      }
92  
93      @Test
94      void testCapitalizeFully_String() {
95          assertNull(WordUtils.capitalizeFully(null));
96          assertEquals("", WordUtils.capitalizeFully(""));
97          assertEquals("  ", WordUtils.capitalizeFully("  "));
98  
99          assertEquals("I", WordUtils.capitalizeFully("I"));
100         assertEquals("I", WordUtils.capitalizeFully("i"));
101         assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am here 123"));
102         assertEquals("I Am Here 123", WordUtils.capitalizeFully("I Am Here 123"));
103         assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am HERE 123"));
104         assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123"));
105     }
106 
107     @Test
108     void testCapitalizeFullyWithDelimiters_String() {
109         assertNull(WordUtils.capitalizeFully(null, null));
110         assertEquals("", WordUtils.capitalizeFully(""));
111         assertEquals("  ", WordUtils.capitalizeFully("  "));
112 
113         char[] chars = { '-', '+', ' ', '@' };
114         assertEquals("I", WordUtils.capitalizeFully("I", chars));
115         assertEquals("I", WordUtils.capitalizeFully("i", chars));
116         assertEquals("I-Am Here+123", WordUtils.capitalizeFully("i-am here+123", chars));
117         assertEquals("I Am+Here-123", WordUtils.capitalizeFully("I Am+Here-123", chars));
118         assertEquals("I+Am-Here 123", WordUtils.capitalizeFully("i+am-HERE 123", chars));
119         assertEquals("I-Am Here+123", WordUtils.capitalizeFully("I-AM HERE+123", chars));
120         chars = new char[] {'.'};
121         assertEquals("I am.Fine", WordUtils.capitalizeFully("i aM.fine", chars));
122         assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null));
123     }
124 
125     @Test
126     void testCapitalizeWithDelimiters_String() {
127         assertNull(WordUtils.capitalize(null, null));
128         assertEquals("", WordUtils.capitalize(""));
129         assertEquals("  ", WordUtils.capitalize("  "));
130 
131         char[] chars = { '-', '+', ' ', '@' };
132         assertEquals("I", WordUtils.capitalize("I", chars));
133         assertEquals("I", WordUtils.capitalize("i", chars));
134         assertEquals("I-Am Here+123", WordUtils.capitalize("i-am here+123", chars));
135         assertEquals("I Am+Here-123", WordUtils.capitalize("I Am+Here-123", chars));
136         assertEquals("I+Am-HERE 123", WordUtils.capitalize("i+am-HERE 123", chars));
137         assertEquals("I-AM HERE+123", WordUtils.capitalize("I-AM HERE+123", chars));
138         chars = new char[] {'.'};
139         assertEquals("I aM.Fine", WordUtils.capitalize("i aM.fine", chars));
140         assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null));
141     }
142 
143     @Test
144     void testCase_SupplementaryCodePoint() {
145         // Deseret long-i: capital U+10400, small U+10428 (each a surrogate pair)
146         final String cap = new String(Character.toChars(0x10400));
147         final String small = new String(Character.toChars(0x10428));
148 
149         assertEquals(cap + "bc", WordUtils.capitalize(small + "bc"));
150         assertEquals("Ben " + cap + "ee", WordUtils.capitalize("ben " + small + "ee"));
151         assertEquals("Ben." + cap + "ee", WordUtils.capitalize("ben." + small + "ee", '.'));
152         assertEquals(cap + "bc", WordUtils.capitalizeFully(cap + "BC"));
153 
154         assertEquals(small + "BC", WordUtils.uncapitalize(cap + "BC"));
155         assertEquals("a." + small + "BC", WordUtils.uncapitalize("a." + cap + "BC", '.'));
156 
157         assertEquals(small, WordUtils.swapCase(cap));
158         assertEquals(cap, WordUtils.swapCase(small));
159         assertEquals("A" + small, WordUtils.swapCase("a" + cap));
160     }
161 
162     @Test
163     void testConstructor() {
164         assertNotNull(new WordUtils());
165         final Constructor<?>[] cons = WordUtils.class.getDeclaredConstructors();
166         assertEquals(1, cons.length);
167         assertTrue(Modifier.isPublic(cons[0].getModifiers()));
168         assertTrue(Modifier.isPublic(WordUtils.class.getModifiers()));
169         assertFalse(Modifier.isFinal(WordUtils.class.getModifiers()));
170     }
171 
172     @Test
173     void testContainsAllWords_StringString() {
174         assertFalse(WordUtils.containsAllWords(null, (String) null));
175         assertFalse(WordUtils.containsAllWords(null, ""));
176         assertFalse(WordUtils.containsAllWords(null, "ab"));
177 
178         assertFalse(WordUtils.containsAllWords("", (String) null));
179         assertFalse(WordUtils.containsAllWords("", ""));
180         assertFalse(WordUtils.containsAllWords("", "ab"));
181 
182         assertFalse(WordUtils.containsAllWords("foo", (String) null));
183         assertFalse(WordUtils.containsAllWords("bar", ""));
184         assertFalse(WordUtils.containsAllWords("zzabyycdxx", "by"));
185         assertTrue(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", "lorem", "dolor"));
186         assertFalse(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", null, "lorem", "dolor"));
187         assertFalse(WordUtils.containsAllWords("lorem ipsum null dolor sit amet", "ipsum", null, "lorem", "dolor"));
188         assertFalse(WordUtils.containsAllWords("ab", "b"));
189         assertFalse(WordUtils.containsAllWords("ab", "z"));
190     }
191 
192     @Test
193     void testContainsAllWordsWithNewline() {
194         assertTrue(WordUtils.containsAllWords("foo\nbar", "bar"));
195         assertTrue(WordUtils.containsAllWords("foo\nbar", "foo"));
196         assertTrue(WordUtils.containsAllWords("lorem ipsum\ndolor sit\namet", "ipsum", "amet", "lorem"));
197         assertFalse(WordUtils.containsAllWords("foo\nbar", "baz"));
198     }
199 
200     @Test
201     void testInitials_String() {
202         assertNull(WordUtils.initials(null));
203         assertEquals("", WordUtils.initials(""));
204         assertEquals("", WordUtils.initials("  "));
205 
206         assertEquals("I", WordUtils.initials("I"));
207         assertEquals("i", WordUtils.initials("i"));
208         assertEquals("BJL", WordUtils.initials("Ben John Lee"));
209         assertEquals("BJL", WordUtils.initials("   Ben \n   John\tLee\t"));
210         assertEquals("BJ", WordUtils.initials("Ben J.Lee"));
211         assertEquals("BJ.L", WordUtils.initials(" Ben   John  . Lee"));
212         assertEquals("iah1", WordUtils.initials("i am here 123"));
213     }
214 
215     @Test
216     void testInitials_String_charArray() {
217         char[] array = null;
218         assertNull(WordUtils.initials(null, array));
219         assertEquals("", WordUtils.initials("", array));
220         assertEquals("", WordUtils.initials("  ", array));
221         assertEquals("I", WordUtils.initials("I", array));
222         assertEquals("i", WordUtils.initials("i", array));
223         assertEquals("S", WordUtils.initials("SJC", array));
224         assertEquals("BJL", WordUtils.initials("Ben John Lee", array));
225         assertEquals("BJL", WordUtils.initials("   Ben \n   John\tLee\t", array));
226         assertEquals("BJ", WordUtils.initials("Ben J.Lee", array));
227         assertEquals("BJ.L", WordUtils.initials(" Ben   John  . Lee", array));
228         assertEquals("KO", WordUtils.initials("Kay O'Murphy", array));
229         assertEquals("iah1", WordUtils.initials("i am here 123", array));
230 
231         array = new char[0];
232         assertNull(WordUtils.initials(null, array));
233         assertEquals("", WordUtils.initials("", array));
234         assertEquals("", WordUtils.initials("  ", array));
235         assertEquals("", WordUtils.initials("I", array));
236         assertEquals("", WordUtils.initials("i", array));
237         assertEquals("", WordUtils.initials("SJC", array));
238         assertEquals("", WordUtils.initials("Ben John Lee", array));
239         assertEquals("", WordUtils.initials("   Ben \n   John\tLee\t", array));
240         assertEquals("", WordUtils.initials("Ben J.Lee", array));
241         assertEquals("", WordUtils.initials(" Ben   John  . Lee", array));
242         assertEquals("", WordUtils.initials("Kay O'Murphy", array));
243         assertEquals("", WordUtils.initials("i am here 123", array));
244 
245         array = " ".toCharArray();
246         assertNull(WordUtils.initials(null, array));
247         assertEquals("", WordUtils.initials("", array));
248         assertEquals("", WordUtils.initials("  ", array));
249         assertEquals("I", WordUtils.initials("I", array));
250         assertEquals("i", WordUtils.initials("i", array));
251         assertEquals("S", WordUtils.initials("SJC", array));
252         assertEquals("BJL", WordUtils.initials("Ben John Lee", array));
253         assertEquals("BJ", WordUtils.initials("Ben J.Lee", array));
254         assertEquals("B\nJ", WordUtils.initials("   Ben \n   John\tLee\t", array));
255         assertEquals("BJ.L", WordUtils.initials(" Ben   John  . Lee", array));
256         assertEquals("KO", WordUtils.initials("Kay O'Murphy", array));
257         assertEquals("iah1", WordUtils.initials("i am here 123", array));
258 
259         array = " .".toCharArray();
260         assertNull(WordUtils.initials(null, array));
261         assertEquals("", WordUtils.initials("", array));
262         assertEquals("", WordUtils.initials("  ", array));
263         assertEquals("I", WordUtils.initials("I", array));
264         assertEquals("i", WordUtils.initials("i", array));
265         assertEquals("S", WordUtils.initials("SJC", array));
266         assertEquals("BJL", WordUtils.initials("Ben John Lee", array));
267         assertEquals("BJL", WordUtils.initials("Ben J.Lee", array));
268         assertEquals("BJL", WordUtils.initials(" Ben   John  . Lee", array));
269         assertEquals("KO", WordUtils.initials("Kay O'Murphy", array));
270         assertEquals("iah1", WordUtils.initials("i am here 123", array));
271 
272         array = " .'".toCharArray();
273         assertNull(WordUtils.initials(null, array));
274         assertEquals("", WordUtils.initials("", array));
275         assertEquals("", WordUtils.initials("  ", array));
276         assertEquals("I", WordUtils.initials("I", array));
277         assertEquals("i", WordUtils.initials("i", array));
278         assertEquals("S", WordUtils.initials("SJC", array));
279         assertEquals("BJL", WordUtils.initials("Ben John Lee", array));
280         assertEquals("BJL", WordUtils.initials("Ben J.Lee", array));
281         assertEquals("BJL", WordUtils.initials(" Ben   John  . Lee", array));
282         assertEquals("KOM", WordUtils.initials("Kay O'Murphy", array));
283         assertEquals("iah1", WordUtils.initials("i am here 123", array));
284 
285         array = "SIJo1".toCharArray();
286         assertNull(WordUtils.initials(null, array));
287         assertEquals("", WordUtils.initials("", array));
288         assertEquals(" ", WordUtils.initials("  ", array));
289         assertEquals("", WordUtils.initials("I", array));
290         assertEquals("i", WordUtils.initials("i", array));
291         assertEquals("C", WordUtils.initials("SJC", array));
292         assertEquals("Bh", WordUtils.initials("Ben John Lee", array));
293         assertEquals("B.", WordUtils.initials("Ben J.Lee", array));
294         assertEquals(" h", WordUtils.initials(" Ben   John  . Lee", array));
295         assertEquals("K", WordUtils.initials("Kay O'Murphy", array));
296         assertEquals("i2", WordUtils.initials("i am here 123", array));
297     }
298 
299     @Test
300     void testInitials_SupplementaryCodePoint() {
301         final String emoji = new String(Character.toChars(0x1F600));
302         assertEquals("B" + emoji + "L", WordUtils.initials("Ben " + emoji + "mile Lee"));
303         assertEquals(emoji, WordUtils.initials(emoji + "abc"));
304         assertEquals("B" + emoji + "L", WordUtils.initials("Ben." + emoji + "mile.Lee", '.'));
305     }
306 
307     @Test
308     void testLANG1292() {
309         // Prior to fix, this was throwing StringIndexOutOfBoundsException
310         WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
311                 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
312                 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 70);
313     }
314 
315     @Test
316     void testLANG1397() {
317         // Prior to fix, this was throwing StringIndexOutOfBoundsException
318         WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
319             + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
320             + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Integer.MAX_VALUE);
321     }
322 
323     @Test
324     void testSwapCase_String() {
325         assertNull(WordUtils.swapCase(null));
326         assertEquals("", WordUtils.swapCase(""));
327         assertEquals("  ", WordUtils.swapCase("  "));
328 
329         assertEquals("i", WordUtils.swapCase("I"));
330         assertEquals("I", WordUtils.swapCase("i"));
331         assertEquals("I AM HERE 123", WordUtils.swapCase("i am here 123"));
332         assertEquals("i aM hERE 123", WordUtils.swapCase("I Am Here 123"));
333         assertEquals("I AM here 123", WordUtils.swapCase("i am HERE 123"));
334         assertEquals("i am here 123", WordUtils.swapCase("I AM HERE 123"));
335 
336         final String test = "This String contains a TitleCase character: \u01C8";
337         final String expect = "tHIS sTRING CONTAINS A tITLEcASE CHARACTER: \u01C9";
338         assertEquals(expect, WordUtils.swapCase(test));
339     }
340 
341     @Test
342     void testUncapitalize_String() {
343         assertNull(WordUtils.uncapitalize(null));
344         assertEquals("", WordUtils.uncapitalize(""));
345         assertEquals("  ", WordUtils.uncapitalize("  "));
346 
347         assertEquals("i", WordUtils.uncapitalize("I"));
348         assertEquals("i", WordUtils.uncapitalize("i"));
349         assertEquals("i am here 123", WordUtils.uncapitalize("i am here 123"));
350         assertEquals("i am here 123", WordUtils.uncapitalize("I Am Here 123"));
351         assertEquals("i am hERE 123", WordUtils.uncapitalize("i am HERE 123"));
352         assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123"));
353     }
354 
355     @Test
356     void testUncapitalizeWithDelimiters_String() {
357         assertNull(WordUtils.uncapitalize(null, null));
358         assertEquals("", WordUtils.uncapitalize(""));
359         assertEquals("  ", WordUtils.uncapitalize("  "));
360 
361         char[] chars = { '-', '+', ' ', '@' };
362         assertEquals("i", WordUtils.uncapitalize("I", chars));
363         assertEquals("i", WordUtils.uncapitalize("i", chars));
364         assertEquals("i am-here+123", WordUtils.uncapitalize("i am-here+123", chars));
365         assertEquals("i+am here-123", WordUtils.uncapitalize("I+Am Here-123", chars));
366         assertEquals("i-am+hERE 123", WordUtils.uncapitalize("i-am+HERE 123", chars));
367         assertEquals("i aM-hERE+123", WordUtils.uncapitalize("I AM-HERE+123", chars));
368         chars = new char[] {'.'};
369         assertEquals("i AM.fINE", WordUtils.uncapitalize("I AM.FINE", chars));
370         assertEquals("i aM.FINE", WordUtils.uncapitalize("I AM.FINE", null));
371     }
372 
373     @Test
374     void testWrap_StringInt() {
375         assertNull(WordUtils.wrap(null, 20));
376         assertNull(WordUtils.wrap(null, -1));
377 
378         assertEquals("", WordUtils.wrap("", 20));
379         assertEquals("", WordUtils.wrap("", -1));
380 
381         // normal
382         final String systemNewLine = System.lineSeparator();
383         String input = "Here is one line of text that is going to be wrapped after 20 columns.";
384         String expected = "Here is one line of" + systemNewLine + "text that is going"
385             + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns.";
386         assertEquals(expected, WordUtils.wrap(input, 20));
387 
388         // long word at end
389         input = "Click here to jump to the commons website - https://commons.apache.org";
390         expected = "Click here to jump" + systemNewLine + "to the commons" + systemNewLine
391             + "website -" + systemNewLine + "https://commons.apache.org";
392         assertEquals(expected, WordUtils.wrap(input, 20));
393 
394         // long word in middle
395         input = "Click here, https://commons.apache.org, to jump to the commons website";
396         expected = "Click here," + systemNewLine + "https://commons.apache.org," + systemNewLine
397             + "to jump to the" + systemNewLine + "commons website";
398         assertEquals(expected, WordUtils.wrap(input, 20));
399 
400         // leading spaces on a new line are stripped
401         // trailing spaces are not stripped
402         input = "word1             word2                        word3";
403         expected = "word1  " + systemNewLine + "word2  " + systemNewLine + "word3";
404         assertEquals(expected, WordUtils.wrap(input, 7));
405     }
406 
407     @Test
408     void testWrap_StringIntStringBoolean() {
409         assertNull(WordUtils.wrap(null, 20, "\n", false));
410         assertNull(WordUtils.wrap(null, 20, "\n", true));
411         assertNull(WordUtils.wrap(null, 20, null, true));
412         assertNull(WordUtils.wrap(null, 20, null, false));
413         assertNull(WordUtils.wrap(null, -1, null, true));
414         assertNull(WordUtils.wrap(null, -1, null, false));
415 
416         assertEquals("", WordUtils.wrap("", 20, "\n", false));
417         assertEquals("", WordUtils.wrap("", 20, "\n", true));
418         assertEquals("", WordUtils.wrap("", 20, null, false));
419         assertEquals("", WordUtils.wrap("", 20, null, true));
420         assertEquals("", WordUtils.wrap("", -1, null, false));
421         assertEquals("", WordUtils.wrap("", -1, null, true));
422 
423         // normal
424         String input = "Here is one line of text that is going to be wrapped after 20 columns.";
425         String expected = "Here is one line of\ntext that is going\nto be wrapped after\n20 columns.";
426         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
427         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
428 
429         // unusual newline char
430         input = "Here is one line of text that is going to be wrapped after 20 columns.";
431         expected = "Here is one line of<br />text that is going<br />to be wrapped after<br />20 columns.";
432         assertEquals(expected, WordUtils.wrap(input, 20, "<br />", false));
433         assertEquals(expected, WordUtils.wrap(input, 20, "<br />", true));
434 
435         // short line length
436         input = "Here is one line";
437         expected = "Here\nis one\nline";
438         assertEquals(expected, WordUtils.wrap(input, 6, "\n", false));
439         expected = "Here\nis\none\nline";
440         assertEquals(expected, WordUtils.wrap(input, 2, "\n", false));
441         assertEquals(expected, WordUtils.wrap(input, -1, "\n", false));
442 
443         // system newline char
444         final String systemNewLine = System.lineSeparator();
445         input = "Here is one line of text that is going to be wrapped after 20 columns.";
446         expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine
447             + "to be wrapped after" + systemNewLine + "20 columns.";
448         assertEquals(expected, WordUtils.wrap(input, 20, null, false));
449         assertEquals(expected, WordUtils.wrap(input, 20, null, true));
450 
451         // with extra spaces
452         input = " Here:  is  one  line  of  text  that  is  going  to  be  wrapped  after  20  columns.";
453         expected = "Here:  is  one  line\nof  text  that  is \ngoing  to  be \nwrapped  after  20 \ncolumns.";
454         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
455         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
456 
457         // with tab
458         input = "Here is\tone line of text that is going to be wrapped after 20 columns.";
459         expected = "Here is\tone line of\ntext that is going\nto be wrapped after\n20 columns.";
460         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
461         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
462 
463         // with tab at wrapColumn
464         input = "Here is one line of\ttext that is going to be wrapped after 20 columns.";
465         expected = "Here is one line\nof\ttext that is\ngoing to be wrapped\nafter 20 columns.";
466         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
467         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
468 
469         // difference because of long word
470         input = "Click here to jump to the commons website - https://commons.apache.org";
471         expected = "Click here to jump\nto the commons\nwebsite -\nhttps://commons.apache.org";
472         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
473         expected = "Click here to jump\nto the commons\nwebsite -\nhttps://commons.apac\nhe.org";
474         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
475 
476         // difference because of long word in middle
477         input = "Click here, https://commons.apache.org, to jump to the commons website";
478         expected = "Click here,\nhttps://commons.apache.org,\nto jump to the\ncommons website";
479         assertEquals(expected, WordUtils.wrap(input, 20, "\n", false));
480         expected = "Click here,\nhttps://commons.apac\nhe.org, to jump to\nthe commons website";
481         assertEquals(expected, WordUtils.wrap(input, 20, "\n", true));
482 
483         // a hard break for a long word must not split a surrogate pair across the new line
484         input = "a\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00";
485         expected = "a\uD83D\uDE00\uD83D\uDE00\n\uD83D\uDE00\uD83D\uDE00";
486         assertEquals(expected, WordUtils.wrap(input, 4, "\n", true));
487         input = "\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00";
488         expected = "\uD83D\uDE00\uD83D\uDE00\n\uD83D\uDE00";
489         assertEquals(expected, WordUtils.wrap(input, 3, "\n", true));
490     }
491 
492     @ParameterizedTest
493     @MethodSource
494     @Timeout(2)
495     void testWrapStringIntStringBooleanString(final String str, final int wrapLength, final boolean wrapLongWords, final String wrapOn, final String expected) {
496         assertEquals(expected, WordUtils.wrap(str, wrapLength, "\n", wrapLongWords, wrapOn));
497         final String sep = System.lineSeparator();
498         if (!sep.equals("\n")) {
499             assertEquals(expected != null ? expected.replace("\n", sep) : null, WordUtils.wrap(str, wrapLength, null, wrapLongWords, wrapOn));
500         }
501     }
502 }