Class StringUtils
java.lang.Object
org.junit.platform.commons.util.StringUtils
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The result of splitting a string into up to two parts. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsIsoControlCharacter
(@Nullable String str) Determine if the suppliedString
contains any ISO control characters.static boolean
containsWhitespace
(@Nullable String str) Determine if the suppliedString
contains any whitespace characters.static String
defaultToString
(@Nullable Object obj) Convert the suppliedObject
to a defaultString
representation using the following algorithm.static boolean
doesNotContainIsoControlCharacter
(@Nullable String str) Determine if the suppliedString
does not contain any ISO control characters.static boolean
doesNotContainWhitespace
(@Nullable String str) Determine if the suppliedString
does not contain any whitespace characters.static boolean
Determine if the suppliedString
is blank (i.e.,null
or consisting only of whitespace characters).static boolean
isNotBlank
(@Nullable String str) static String
nullSafeToString
(@Nullable Object obj) Convert the suppliedObject
to aString
using the following algorithm.static @Nullable String
replaceIsoControlCharacters
(@Nullable String str, String replacement) Replace all ISO control characters in the suppliedString
.static @Nullable String
replaceWhitespaceCharacters
(@Nullable String str, String replacement) Replace all whitespace characters in the suppliedString
.splitIntoTwo
(char separator, String value) Split the suppliedString
into up to two parts using the supplied separator character.splitIntoTwo
(String separator, String value) Split the suppliedString
into up to two parts using the supplied separator string.
-
Method Details
-
isBlank
-
isNotBlank
-
containsWhitespace
-
doesNotContainWhitespace
-
containsIsoControlCharacter
-
doesNotContainIsoControlCharacter
-
nullSafeToString
Convert the suppliedObject
to aString
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,
toString()
will be invoked on the object. If the result is non-null, that result will be returned. If the result isnull
,"null"
will be returned. - If any of the above results in an exception, this method delegates to
defaultToString(Object)
- Parameters:
obj
- the object to convert to a String; may benull
- Returns:
- a String representation of the supplied object; never
null
- See Also:
- If the supplied object is
-
defaultToString
Convert the suppliedObject
to a defaultString
representation using the following algorithm.- If the supplied object is
null
, this method returns"null"
. - Otherwise, the String returned by this method will be generated analogous
to the default implementation of
Object.toString()
by 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 benull
- Returns:
- the default String representation of the supplied object; never
null
- See Also:
- If the supplied object is
-
replaceIsoControlCharacters
@API(status=INTERNAL, since="1.4") public static @Nullable String replaceIsoControlCharacters(@Nullable String str, String replacement) Replace all ISO control characters in the suppliedString
.- Parameters:
str
- the string in which to perform the replacement; may benull
replacement
- the replacement string; nevernull
- Returns:
- the supplied string with all control characters replaced, or
null
if the supplied string wasnull
- Since:
- 1.4
-
replaceWhitespaceCharacters
@API(status=INTERNAL, since="1.4") public static @Nullable String replaceWhitespaceCharacters(@Nullable String str, String replacement) Replace all whitespace characters in the suppliedString
.- Parameters:
str
- the string in which to perform the replacement; may benull
replacement
- the replacement string; nevernull
- Returns:
- the supplied string with all whitespace characters replaced, or
null
if the supplied string wasnull
- Since:
- 1.4
-
splitIntoTwo
@API(status=INTERNAL, since="1.11") public static StringUtils.TwoPartSplitResult splitIntoTwo(char separator, String value) Split the suppliedString
into up to two parts using the supplied separator character.- Parameters:
separator
- the separator charactervalue
- the value to split; nevernull
- Since:
- 1.11
-
splitIntoTwo
@API(status=INTERNAL, since="1.11") public static StringUtils.TwoPartSplitResult splitIntoTwo(String separator, String value) Split the suppliedString
into up to two parts using the supplied separator string.- Parameters:
separator
- the separator string; nevernull
value
- the value to split; nevernull
- Since:
- 1.11
-