public final class Assert extends Object
| Constructor and Description |
|---|
Assert() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
hasText(String str)
Check whether the given
String contains actual text. |
static void |
hasText(String text,
String message)
Assert that the given String contains valid text content; that is, it must not be
null and must contain at least one non-whitespace character. |
static void |
isTrue(boolean expression,
String message)
Assert a boolean expression, throwing an
IllegalArgumentException if the
expression evaluates to false. |
static void |
notEmpty(Collection<?> collection,
String message)
Assert that the collection is not
null and not empty. |
static void |
notNull(Object object,
String message)
Assert that an object is not
null. |
public static void notEmpty(@Nullable
Collection<?> collection,
String message)
null and not empty.collection - the collection to checkmessage - the exception message to use if the assertion failsIllegalArgumentException - if the collection is null or emptypublic static void notNull(@Nullable
Object object,
String message)
null.
Assert.notNull(clazz, "The class must not be null");
object - the object to checkmessage - the exception message to use if the assertion failsIllegalArgumentException - if the object is nullpublic static void hasText(@Nullable
String text,
String message)
null and must contain at least one non-whitespace character.
Assert.hasText(name, "'name' must not be empty");
text - the String to checkmessage - the exception message to use if the assertion failsIllegalArgumentException - if the text does not contain valid text contentpublic static boolean hasText(@Nullable
String str)
String contains actual text.
More specifically, this method returns true if the String is not
null, its length is greater than 0, and it contains at least one
non-whitespace character.
str - the String to check (may be null)true if the String is not null, its length is
greater than 0, and it does not contain whitespace onlyCharacter.isWhitespace(char)public static void isTrue(boolean expression,
String message)
IllegalArgumentException if the
expression evaluates to false.expression - a boolean expressionmessage - the exception message to use if the assertion failsIllegalArgumentException - if expression is falseCopyright © 2025. All rights reserved.