public final class AssertionUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
enableAssertionsFor(java.lang.Class<?> clasS)
Enables assertions for the given
clasS, regardless of the "enable assertions" command line options that
the JVM was started with. |
static void |
enableAssertionsForThisClass()
Enables assertions for the class that invokes this method, regardless of the "enable assertions" command line
options that the JVM was started with.
|
static java.lang.Object |
fail()
Identical with '
throw new AssertionError()', but returns an Object so it can be used in an
expression. |
static <T> T |
fail(java.lang.String message)
Identical with '
throw new AssertionError(message)', but returns an Object so it can be used in
an expression. |
static java.lang.Object |
fail(java.lang.String message,
java.lang.Throwable cause)
Identical with '
throw new AssertionError(message, cause)', but returns an Object so it can be
used in an expression. |
static java.lang.Object |
fail(java.lang.Throwable cause)
Identical with '
throw new AssertionError(cause)', but returns an Object so it can be used in
an expression. |
static <T> T |
notNull(T subject)
Verifies that the
subject is not null. |
static <T> T |
notNull(T subject,
java.lang.String message)
Verifies that the
subject is not null. |
public static void enableAssertionsFor(java.lang.Class<?> clasS)
clasS, regardless of the "enable assertions" command line options that
the JVM was started with.
Enabling assertions programmatically makes them much more helpful, because unfortunately assertions are disabled
by default and hardly any runtime environment provides a simple way to enable them.
enableAssertionsForThisClass() is an even more elegant way to enable assertions for classes as they
are loaded and initialized.
public static void enableAssertionsForThisClass()
public class MyClass {
static { AssertionUtil.enableAssertionsForThisClass(); }
// ...
}
Adding such static initializers to all classes makes assertions much more helpful, because unfortunately
assertions are disabled by default and hardly any runtime environment provides a simple way to enable them.
Must only be called from the static initializer of a class.
public static <T> T notNull(@Nullable T subject)
subject is not null.subjectjava.lang.NullPointerExceptionpublic static <T> T notNull(@Nullable T subject, java.lang.String message)
subject is not null.subjectjava.lang.NullPointerException - with the given message iff the subject is nullpublic static java.lang.Object fail()
throw new AssertionError()', but returns an Object so it can be used in an
expression.public static <T> T fail(java.lang.String message)
throw new AssertionError(message)', but returns an Object so it can be used in
an expression.public static java.lang.Object fail(java.lang.Throwable cause)
throw new AssertionError(cause)', but returns an Object so it can be used in
an expression.public static java.lang.Object fail(java.lang.String message,
java.lang.Throwable cause)
throw new AssertionError(message, cause)', but returns an Object so it can be
used in an expression.