@API(value=Internal) public final class Preconditions extends java.lang.Object
Each method in this class throws a PreconditionViolationException
if the precondition is violated.
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!
| Modifier and Type | Method and Description |
|---|---|
static void |
condition(boolean predicate,
java.lang.String message)
Assert that the supplied
predicate is true. |
static void |
condition(boolean predicate,
java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that the supplied
predicate is true. |
static java.lang.String |
notBlank(java.lang.String str,
java.lang.String message)
Assert that the supplied
String is not null or blank. |
static java.lang.String |
notBlank(java.lang.String str,
java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that the supplied
String is not null or blank. |
static java.lang.String |
notEmpty(java.lang.String str,
java.lang.String message)
Assert that the supplied
String is not null or empty. |
static java.lang.String |
notEmpty(java.lang.String str,
java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that the supplied
String is not null or empty. |
static <T extends java.util.Collection<?>> |
notEmpty(T collection,
java.lang.String message)
Assert that the supplied
Collection is not null or empty. |
static java.lang.Object[] |
notNull(java.lang.Object[] objects,
java.lang.String message)
Assert that none of the supplied
Objects are null. |
static <T> T |
notNull(T object,
java.lang.String message)
Assert that the supplied
Object is not null. |
static <T> T |
notNull(T object,
java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that the supplied
Object is not null. |
public static <T> T notNull(T object,
java.lang.String message)
throws PreconditionViolationException
Object is not null.object - the object to checkmessage - precondition violation messagePreconditionViolationException - if the supplied object is nullnotNull(Object, Supplier)public static java.lang.Object[] notNull(java.lang.Object[] objects,
java.lang.String message)
throws PreconditionViolationException
Objects are null.objects - the objects to checkmessage - precondition violation messagePreconditionViolationException - if any of the supplied objects are nullnotNull(Object, Supplier)public static <T> T notNull(T object,
java.util.function.Supplier<java.lang.String> messageSupplier)
throws PreconditionViolationException
Object is not null.object - the object to checkmessageSupplier - precondition violation message supplierPreconditionViolationException - if the supplied object is nullcondition(boolean, Supplier)public static java.lang.String notEmpty(java.lang.String str,
java.lang.String message)
throws PreconditionViolationException
String is not null or empty.str - the string to checkmessage - precondition violation messagePreconditionViolationException - if the supplied string is null or emptynotEmpty(String, Supplier)public static java.lang.String notEmpty(java.lang.String str,
java.util.function.Supplier<java.lang.String> messageSupplier)
throws PreconditionViolationException
String is not null or empty.str - the string to checkmessageSupplier - precondition violation message supplierPreconditionViolationException - if the supplied string is null or emptyStringUtils.isNotEmpty(CharSequence),
condition(boolean, Supplier)public static <T extends java.util.Collection<?>> T notEmpty(T collection,
java.lang.String message)
throws PreconditionViolationException
Collection is not null or empty.collection - the collection to checkmessage - precondition violation messagePreconditionViolationException - if the supplied collection is null or emptycondition(boolean, Supplier)public static java.lang.String notBlank(java.lang.String str,
java.lang.String message)
throws PreconditionViolationException
String is not null or blank.str - the string to checkmessage - precondition violation messagePreconditionViolationException - if the supplied string is null or blanknotBlank(String, Supplier)public static java.lang.String notBlank(java.lang.String str,
java.util.function.Supplier<java.lang.String> messageSupplier)
throws PreconditionViolationException
String is not null or blank.str - the string to checkmessageSupplier - precondition violation message supplierPreconditionViolationException - if the supplied string is null or blankStringUtils.isNotBlank(String),
condition(boolean, Supplier)public static void condition(boolean predicate,
java.lang.String message)
throws PreconditionViolationException
predicate is true.predicate - the predicate to checkmessage - precondition violation messagePreconditionViolationException - if the predicate is falsecondition(boolean, Supplier)public static void condition(boolean predicate,
java.util.function.Supplier<java.lang.String> messageSupplier)
throws PreconditionViolationException
predicate is true.predicate - the predicate to checkmessageSupplier - precondition violation message supplierPreconditionViolationException - if the predicate is false