Class Preconditions
- java.lang.Object
-
- org.junit.platform.commons.util.Preconditions
-
@API(status=INTERNAL, since="1.0") public final class Preconditions extends java.lang.ObjectCollection of utilities for asserting preconditions for method and constructor arguments.Each method in this class throws a
PreconditionViolationExceptionif the precondition is violated.DISCLAIMER
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!
- Since:
- 1.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcondition(boolean predicate, java.lang.String message)Assert that the suppliedpredicateistrue.static voidcondition(boolean predicate, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the suppliedpredicateistrue.static <T> T[]containsNoNullElements(T[] array, java.lang.String message)Assert that the supplied array contains nonullelements.static <T> T[]containsNoNullElements(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the supplied array contains nonullelements.static <T extends java.util.Collection<?>>
TcontainsNoNullElements(T collection, java.lang.String message)Assert that the supplied collection contains nonullelements.static <T extends java.util.Collection<?>>
TcontainsNoNullElements(T collection, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the supplied collection contains nonullelements.static java.lang.StringnotBlank(java.lang.String str, java.lang.String message)Assert that the suppliedStringis not blank.static java.lang.StringnotBlank(java.lang.String str, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the suppliedStringis not blank.static <T> T[]notEmpty(T[] array, java.lang.String message)Assert that the supplied array is neithernullnor empty.static <T> T[]notEmpty(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the supplied array is neithernullnor empty.static <T extends java.util.Collection<?>>
TnotEmpty(T collection, java.lang.String message)Assert that the suppliedCollectionis neithernullnor empty.static <T extends java.util.Collection<?>>
TnotEmpty(T collection, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the suppliedCollectionis neithernullnor empty.static <T> TnotNull(T object, java.lang.String message)Assert that the suppliedObjectis notnull.static <T> TnotNull(T object, java.util.function.Supplier<java.lang.String> messageSupplier)Assert that the suppliedObjectis notnull.
-
-
-
Method Detail
-
notNull
public static <T> T notNull(T object, java.lang.String message) throws PreconditionViolationExceptionAssert that the suppliedObjectis notnull.- Parameters:
object- the object to checkmessage- precondition violation message- Returns:
- the supplied object as a convenience
- Throws:
PreconditionViolationException- if the supplied object isnull- See Also:
notNull(Object, Supplier)
-
notNull
public static <T> T notNull(T object, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the suppliedObjectis notnull.- Parameters:
object- the object to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied object as a convenience
- Throws:
PreconditionViolationException- if the supplied object isnull- See Also:
condition(boolean, Supplier)
-
notEmpty
public static <T> T[] notEmpty(T[] array, java.lang.String message) throws PreconditionViolationExceptionAssert that the supplied array is neithernullnor empty.WARNING: this method does NOT check if the supplied array contains any
nullelements.- Parameters:
array- the array to checkmessage- precondition violation message- Returns:
- the supplied array as a convenience
- Throws:
PreconditionViolationException- if the supplied array isnullor empty- See Also:
containsNoNullElements(Object[], String),condition(boolean, String)
-
notEmpty
public static <T> T[] notEmpty(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the supplied array is neithernullnor empty.WARNING: this method does NOT check if the supplied array contains any
nullelements.- Parameters:
array- the array to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied array as a convenience
- Throws:
PreconditionViolationException- if the supplied array isnullor empty- See Also:
containsNoNullElements(Object[], String),condition(boolean, String)
-
notEmpty
public static <T extends java.util.Collection<?>> T notEmpty(T collection, java.lang.String message) throws PreconditionViolationExceptionAssert that the suppliedCollectionis neithernullnor empty.WARNING: this method does NOT check if the supplied collection contains any
nullelements.- Parameters:
collection- the collection to checkmessage- precondition violation message- Returns:
- the supplied collection as a convenience
- Throws:
PreconditionViolationException- if the supplied collection isnullor empty- See Also:
containsNoNullElements(Collection, String),condition(boolean, String)
-
notEmpty
public static <T extends java.util.Collection<?>> T notEmpty(T collection, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the suppliedCollectionis neithernullnor empty.WARNING: this method does NOT check if the supplied collection contains any
nullelements.- Parameters:
collection- the collection to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied collection as a convenience
- Throws:
PreconditionViolationException- if the supplied collection isnullor empty- See Also:
containsNoNullElements(Collection, String),condition(boolean, String)
-
containsNoNullElements
public static <T> T[] containsNoNullElements(T[] array, java.lang.String message) throws PreconditionViolationExceptionAssert that the supplied array contains nonullelements.WARNING: this method does NOT check if the supplied array is
nullor empty.- Parameters:
array- the array to checkmessage- precondition violation message- Returns:
- the supplied array as a convenience
- Throws:
PreconditionViolationException- if the supplied array contains anynullelements- See Also:
notNull(Object, String)
-
containsNoNullElements
public static <T> T[] containsNoNullElements(T[] array, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the supplied array contains nonullelements.WARNING: this method does NOT check if the supplied array is
nullor empty.- Parameters:
array- the array to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied array as a convenience
- Throws:
PreconditionViolationException- if the supplied array contains anynullelements- See Also:
notNull(Object, String)
-
containsNoNullElements
public static <T extends java.util.Collection<?>> T containsNoNullElements(T collection, java.lang.String message) throws PreconditionViolationExceptionAssert that the supplied collection contains nonullelements.WARNING: this method does NOT check if the supplied collection is
nullor empty.- Parameters:
collection- the collection to checkmessage- precondition violation message- Returns:
- the supplied collection as a convenience
- Throws:
PreconditionViolationException- if the supplied collection contains anynullelements- See Also:
notNull(Object, String)
-
containsNoNullElements
public static <T extends java.util.Collection<?>> T containsNoNullElements(T collection, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the supplied collection contains nonullelements.WARNING: this method does NOT check if the supplied collection is
nullor empty.- Parameters:
collection- the collection to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied collection as a convenience
- Throws:
PreconditionViolationException- if the supplied collection contains anynullelements- See Also:
notNull(Object, String)
-
notBlank
public static java.lang.String notBlank(java.lang.String str, java.lang.String message) throws PreconditionViolationExceptionAssert that the suppliedStringis not blank.A
Stringis blank if it isnullor consists only of whitespace characters.- Parameters:
str- the string to checkmessage- precondition violation message- Returns:
- the supplied string as a convenience
- Throws:
PreconditionViolationException- if the supplied string is blank- See Also:
notBlank(String, Supplier)
-
notBlank
public static java.lang.String notBlank(java.lang.String str, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the suppliedStringis not blank.A
Stringis blank if it isnullor consists only of whitespace characters.- Parameters:
str- the string to checkmessageSupplier- precondition violation message supplier- Returns:
- the supplied string as a convenience
- Throws:
PreconditionViolationException- if the supplied string is blank- See Also:
StringUtils.isNotBlank(String),condition(boolean, Supplier)
-
condition
public static void condition(boolean predicate, java.lang.String message) throws PreconditionViolationExceptionAssert that the suppliedpredicateistrue.- Parameters:
predicate- the predicate to checkmessage- precondition violation message- Throws:
PreconditionViolationException- if the predicate isfalse- See Also:
condition(boolean, Supplier)
-
condition
public static void condition(boolean predicate, java.util.function.Supplier<java.lang.String> messageSupplier) throws PreconditionViolationExceptionAssert that the suppliedpredicateistrue.- Parameters:
predicate- the predicate to checkmessageSupplier- precondition violation message supplier- Throws:
PreconditionViolationException- if the predicate isfalse
-
-