@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 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 blank. |
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 the supplied array and none of the objects it contains 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 null
notNull(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 null
condition(boolean, Supplier)
public static java.lang.Object[] notNull(java.lang.Object[] objects, java.lang.String message) throws PreconditionViolationException
null
.objects
- the array to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied array or any of
the objects its contains is null
notNull(Object, 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 blank.
A String
is blank if it is null
or consists
only of whitespace characters.
str
- the string to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied string is 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 blank.
A String
is blank if it is null
or consists
only of whitespace characters.
str
- the string to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the supplied string is 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 false
condition(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