### Question:
StringUtil { public static String normaliseWhitespace(String string) { StringBuilder sb = new StringBuilder(string.length()); boolean lastWasWhite = false; boolean modified = false; int l = string.length(); for (int i = 0; i < l; i++) { int c = string.codePointAt(i); if (Character.isWhitespace(c)) { if (lastWasWhite) { modified = true; continue; } if (c != ' ') modified = true; sb.append(' '); lastWasWhite = true; } else { sb.appendCodePoint(c); lastWasWhite = false; } } return modified ? sb.toString() : string; }  static String join(Collection strings, String sep); static String join(Iterator strings, String sep); static String padding(int width); static boolean isBlank(String string); static boolean isNumeric(String string); static String normaliseWhitespace(String string);  }### Answer:
@Test public void normaliseWhiteSpace() { assertEquals(" ", StringUtil.normaliseWhitespace(" \r \n \r\n")); assertEquals(" hello there ", StringUtil.normaliseWhitespace(" hello \r \n there \n")); assertEquals("hello", StringUtil.normaliseWhitespace("hello")); assertEquals("hello there", StringUtil.normaliseWhitespace("hello\nthere")); }
@Test public void normaliseWhiteSpaceModified() { String check1 = "Hello there"; String check2 = "Hello\nthere"; String check3 = "Hello there"; assertTrue(check1 == StringUtil.normaliseWhitespace(check1)); assertTrue(check2 != StringUtil.normaliseWhitespace(check2)); assertTrue(check3 != StringUtil.normaliseWhitespace(check3)); }