Class StringUtils


  • @API(status=INTERNAL,
         since="1.0")
    public final class StringUtils
    extends Object
    Collection of utilities for working with Strings, CharSequences, etc.

    DISCLAIMER

    These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!

    Since:
    1.0
    • Method Detail

      • isBlank

        public static boolean isBlank​(String str)
        Determine if the supplied String is blank (i.e., null or consisting only of whitespace characters).
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string is blank
        See Also:
        isNotBlank(String)
      • isNotBlank

        public static boolean isNotBlank​(String str)
        Determine if the supplied String is not blank.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string is not blank
        See Also:
        isBlank(String)
      • containsIsoControlCharacter

        public static boolean containsIsoControlCharacter​(String str)
        Determine if the supplied String contains any ISO control characters.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string contains an ISO control character
        See Also:
        containsWhitespace(String), Character.isISOControl(int)
      • nullSafeToString

        public static String nullSafeToString​(Object obj)
        Convert the supplied Object to a String using the following algorithm.
        • If the supplied object is null, this method returns "null".
        • If the supplied object is a primitive array, the appropriate Arrays#toString(...) variant will be used to convert it to a String.
        • If the supplied object is an object array, Arrays#deepToString(Object[]) will be used to convert it to a String.
        • Otherwise, the result of invoking toString() on the object will be returned.
        • If any of the above results in an exception, the String returned by this method will be generated using the supplied object's class name and hash code as follows: obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj))
        Parameters:
        obj - the object to convert to a String; may be null
        Returns:
        a String representation of the supplied object; never null
        See Also:
        Arrays.deepToString(Object[]), ClassUtils.nullSafeToString(Class...)
      • replaceIsoControlCharacters

        @API(status=INTERNAL,
             since="1.4")
        public static String replaceIsoControlCharacters​(String str,
                                                         String replacement)
        Replace all ISO control characters in the supplied String.
        Parameters:
        str - the string to check; may be null
        replacement - the replacement string; never null
        Returns:
        The supplied string with all control characters replaced.
        Since:
        1.4
      • replaceWhitespaceCharacters

        @API(status=INTERNAL,
             since="1.4")
        public static String replaceWhitespaceCharacters​(String str,
                                                         String replacement)
        Replace all whitespace characters in the supplied String.
        Parameters:
        str - the string to check; may be null
        replacement - the replacement string; never null
        Returns:
        The supplied string with all whitespace characters replaced.
        Since:
        1.4