@API(value=Internal) public final class Preconditions extends 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,
String message)
Assert that the supplied
predicate is true . |
static void |
condition(boolean predicate,
Supplier<String> messageSupplier)
Assert that the supplied
predicate is true . |
static <T> T[] |
containsNoNullElements(T[] array,
String message)
Assert that the supplied array contains no
null elements. |
static <T> T[] |
containsNoNullElements(T[] array,
Supplier<String> messageSupplier)
Assert that the supplied array contains no
null elements. |
static <T extends Collection<?>> |
containsNoNullElements(T collection,
String message)
Assert that the supplied collection contains no
null elements. |
static <T extends Collection<?>> |
containsNoNullElements(T collection,
Supplier<String> messageSupplier)
Assert that the supplied collection contains no
null elements. |
static String |
notBlank(String str,
String message)
Assert that the supplied
String is not blank. |
static String |
notBlank(String str,
Supplier<String> messageSupplier)
Assert that the supplied
String is not blank. |
static <T> T[] |
notEmpty(T[] array,
String message)
Assert that the supplied array is neither
null nor empty. |
static <T> T[] |
notEmpty(T[] array,
Supplier<String> messageSupplier)
Assert that the supplied array is neither
null nor empty. |
static <T extends Collection<?>> |
notEmpty(T collection,
String message)
Assert that the supplied
Collection is neither null nor empty. |
static <T extends Collection<?>> |
notEmpty(T collection,
Supplier<String> messageSupplier)
Assert that the supplied
Collection is neither null nor empty. |
static <T> T |
notNull(T object,
String message)
Assert that the supplied
Object is not null . |
static <T> T |
notNull(T object,
Supplier<String> messageSupplier)
Assert that the supplied
Object is not null . |
public static <T> T notNull(T object, 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, Supplier<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, 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, Supplier<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 Collection<?>> T notEmpty(T collection, 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 Collection<?>> T notEmpty(T collection, Supplier<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, 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, Supplier<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 Collection<?>> T containsNoNullElements(T collection, 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 Collection<?>> T containsNoNullElements(T collection, Supplier<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 String notBlank(String str, 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 String notBlank(String str, Supplier<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, 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, Supplier<String> messageSupplier) throws PreconditionViolationException
predicate
is true
.predicate
- the predicate to checkmessageSupplier
- precondition violation message supplierPreconditionViolationException
- if the predicate is false