@API(status=INTERNAL, since="1.0") 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 | 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 <T> T[] |
containsNoNullElements(T[] array,
java.lang.String message) |
Assert that the supplied array contains no
null elements. |
static <T> T[] |
containsNoNullElements(T[] array,
java.util.function.Supplier<java.lang.String> messageSupplier) |
Assert that the supplied array contains no
null elements. |
static <T extends java.util.Collection<?>> |
containsNoNullElements(T collection,
java.lang.String message) |
Assert that the supplied collection contains no
null elements. |
static <T extends java.util.Collection<?>> |
containsNoNullElements(T collection,
java.util.function.Supplier<java.lang.String> messageSupplier) |
Assert that the supplied collection contains no
null elements. |
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> T[] |
notEmpty(T[] array,
java.lang.String message) |
Assert that the supplied array is neither
null nor empty. |
static <T> T[] |
notEmpty(T[] array,
java.util.function.Supplier<java.lang.String> messageSupplier) |
Assert that the supplied array is neither
null nor empty. |
static <T extends java.util.Collection<?>> |
notEmpty(T collection,
java.lang.String message) |
Assert that the supplied
Collection is neither null nor empty. |
static <T extends java.util.Collection<?>> |
notEmpty(T collection,
java.util.function.Supplier<java.lang.String> messageSupplier) |
Assert that the supplied
Collection is neither null nor empty. |
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 <T> T[] notEmpty(T[] array, java.lang.String message) throws PreconditionViolationException
null
nor empty.
WARNING: this method does NOT check if the supplied
array contains any null
elements.
array
- the array to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied array is
null
or emptycontainsNoNullElements(Object[], String)
,
condition(boolean, String)
public static <T> T[] notEmpty(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationException
null
nor empty.
WARNING: this method does NOT check if the supplied
array contains any null
elements.
array
- the array to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the supplied array is
null
or emptycontainsNoNullElements(Object[], String)
,
condition(boolean, String)
public static <T extends java.util.Collection<?>> T notEmpty(T collection, java.lang.String message) throws PreconditionViolationException
Collection
is neither null
nor empty.
WARNING: this method does NOT check if the supplied
collection contains any null
elements.
collection
- the collection to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied collection is null
or emptycontainsNoNullElements(Collection, String)
,
condition(boolean, String)
public static <T extends java.util.Collection<?>> T notEmpty(T collection, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationException
Collection
is neither null
nor empty.
WARNING: this method does NOT check if the supplied
collection contains any null
elements.
collection
- the collection to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the supplied collection is null
or emptycontainsNoNullElements(Collection, String)
,
condition(boolean, String)
public static <T> T[] containsNoNullElements(T[] array, java.lang.String message) throws PreconditionViolationException
null
elements.
WARNING: this method does NOT check if the supplied
array is null
or empty.
array
- the array to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied array contains
any null
elementsnotNull(Object, String)
public static <T> T[] containsNoNullElements(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationException
null
elements.
WARNING: this method does NOT check if the supplied
array is null
or empty.
array
- the array to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the supplied array contains
any null
elementsnotNull(Object, String)
public static <T extends java.util.Collection<?>> T containsNoNullElements(T collection, java.lang.String message) throws PreconditionViolationException
null
elements.
WARNING: this method does NOT check if the supplied
collection is null
or empty.
collection
- the collection to checkmessage
- precondition violation messagePreconditionViolationException
- if the supplied collection contains
any null
elementsnotNull(Object, String)
public static <T extends java.util.Collection<?>> T containsNoNullElements(T collection, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationException
null
elements.
WARNING: this method does NOT check if the supplied
collection is null
or empty.
collection
- the collection to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the supplied collection contains
any null
elementsnotNull(Object, String)
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