Validate that the argument condition is true
; otherwise throwing an exception with the
specified message.
Validate that the argument condition is true
; otherwise throwing an exception with the
specified message. This method is useful when validating according to an arbitrary boolean
expression, such as validating a primitive number or using your own custom validation
expression.
Assert.isTrue(i >= min && i <= max, "The value must be between %d and %d", min, max); Assert.isTrue(myObject.isOk(), "The object is not okay");
the boolean expression to check
the Object...)
exception message if invalid, not
null
the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
if expression is false
#isTrue(boolean)
Validate that the argument condition is true
; otherwise throwing an exception.
Validate that the argument condition is true
; otherwise throwing an exception. This
method is useful when validating according to an arbitrary boolean expression, such as
validating a primitive number or using your own custom validation expression.
Assert.isTrue(i > 0); Assert.isTrue(myObject.isOk());
The message of the exception is "The validated expression is false".
the boolean expression to check
IllegalArgumentException
if expression is false
#isTrue(boolean, String, Object...)
Validate that the specified argument iterable is neither null
nor contains any elements
that are null
; otherwise throwing an exception with the specified message.
Validate that the specified argument iterable is neither null
nor contains any elements
that are null
; otherwise throwing an exception with the specified message.
Assert.noNullElements(myCollection, "The collection contains null at position %d");
If the iterable is null
, then the message in the exception is "The validated
object is null".
If the iterable has a null
element, then the iteration index of the invalid element is
appended to the values
argument.
the iterable to check, validated not null by this method
the Object...)
exception message if invalid, not null
the optional values for the formatted exception message, null array not recommended
the validated iterable (never null
method for chaining)
IllegalArgumentException
if an element is null
NullPointerException
if the array is null
Validate that the specified argument character sequence is neither null
nor a length of
zero (no characters); otherwise throwing an exception with the specified message.
Validate that the specified argument character sequence is neither null
nor a length of
zero (no characters); otherwise throwing an exception with the specified message.
Assert.notEmpty(myString);
The message in the exception is "The validated character sequence is empty".
the character sequence to check, validated not null by this method
the validated character sequence (never null
method for chaining)
IllegalArgumentException
if the character sequence is empty
NullPointerException
if the character sequence is null
Validate that the specified argument array is neither null
nor a length of zero (no
elements); otherwise throwing an exception.
Validate that the specified argument array is neither null
nor a length of zero (no
elements); otherwise throwing an exception.
Assert.notEmpty(myArray);
The message in the exception is "The validated array is empty".
the validated array (never null
method for chaining)
IllegalArgumentException
if the array is empty
NullPointerException
if the array is null
Validate that the specified argument is not null
; otherwise throwing an exception with
the specified message.
Validate that the specified argument is not null
; otherwise throwing an exception with
the specified message.
Assert.notNull(myObject, "The object must not be null");
the Object...)
exception message if invalid, not
null
the optional values for the formatted exception message
the validated object (never null
for method chaining)
NullPointerException
if the object is null
#notNull(Object)
Validate that the specified argument is not null
; otherwise throwing an exception.
Validate that the specified argument is not null
; otherwise throwing an exception.
Assert.notNull(myObject, "The object must not be null");
The message of the exception is "The validated object is null".
the object to check
the validated object (never null
for method chaining)
NullPointerException
if the object is null
#notNull(Object, String, Object...)
Assertion tool class
3.0.0