public final class Assertions extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArgument(boolean expression)
Ensures the truth of an expression involving one or more arguments passed to the calling
method.
|
static void |
checkArgument(boolean expression,
Object errorMessage)
Ensures the truth of an expression involving one or more arguments passed to the calling
method.
|
static void |
checkMainThread()
Ensures that the calling thread is the application's main thread.
|
static String |
checkNotEmpty(String string)
Ensures that a string passed as an argument to the calling method is not null or 0-length.
|
static String |
checkNotEmpty(String string,
Object errorMessage)
Ensures that a string passed as an argument to the calling method is not null or 0-length.
|
static <T> T |
checkNotNull(T reference)
Ensures that an object reference is not null.
|
static <T> T |
checkNotNull(T reference,
Object errorMessage)
Ensures that an object reference is not null.
|
static void |
checkState(boolean expression)
Ensures the truth of an expression involving the state of the calling instance.
|
static void |
checkState(boolean expression,
Object errorMessage)
Ensures the truth of an expression involving the state of the calling instance.
|
public static void checkArgument(boolean expression)
expression - A boolean expression.IllegalArgumentException - If expression is false.public static void checkArgument(boolean expression,
Object errorMessage)
expression - A boolean expression.errorMessage - The exception message to use if the check fails. The message is converted
to a String using String.valueOf(Object).IllegalArgumentException - If expression is false.public static void checkState(boolean expression)
expression - A boolean expression.IllegalStateException - If expression is false.public static void checkState(boolean expression,
Object errorMessage)
expression - A boolean expression.errorMessage - The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object).IllegalStateException - If expression is false.public static <T> T checkNotNull(T reference)
reference - An object reference.NullPointerException - If reference is null.public static <T> T checkNotNull(T reference,
Object errorMessage)
reference - An object reference.errorMessage - The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object).NullPointerException - If reference is null.public static String checkNotEmpty(String string)
string - A string.IllegalArgumentException - If string is null or 0-length.public static String checkNotEmpty(String string, Object errorMessage)
string - A string.errorMessage - The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object).IllegalArgumentException - If string is null or 0-length.public static void checkMainThread()
IllegalStateException - If the calling thread is not the application's main thread.