Assert
Assertion tool class
- Since
3.0.0
Value members
Concrete methods
Validate that the argument condition is <code>true</code>; 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.
Validate that the argument condition is <code>true</code>; 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.
<pre> Assert.isTrue(i > 0); Assert.isTrue(myObject.isOk()); </pre>
The message of the exception is "The validated expression is false".
- Value Params
- expression
the boolean expression to check
- Throws
- IllegalArgumentException
if expression is <code>false</code>
- See also
#isTrue(boolean, String, Object...)
Validate that the argument condition is <code>true</code>; 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.
Validate that the argument condition is <code>true</code>; 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.
<pre> 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"); </pre>
- Value Params
- expression
the boolean expression to check
- message
the
[[String#format(String, Object...)]]
exception message if invalid, not null- values
the optional values for the formatted exception message, null array not recommended
- Throws
- IllegalArgumentException
if expression is <code>false</code>
- See also
#isTrue(boolean)
Validate that the specified argument iterable is neither <code>null</code> nor contains any elements that are <code>null</code>; otherwise throwing an exception with the specified message.
Validate that the specified argument iterable is neither <code>null</code> nor contains any elements that are <code>null</code>; otherwise throwing an exception with the specified message.
<pre> Assert.noNullElements(myCollection, "The collection contains null at position %d"); </pre>
If the iterable is <code>null</code>, then the message in the exception is "The validated object is null".
If the iterable has a <code>null</code> element, then the iteration index of the invalid element is appended to the <code>values</code> argument.
- Value Params
- <T>
the iterable type
- iterable
the iterable to check, validated not null by this method
- message
the
[[String#format(String, Object...)]]
exception message if invalid, not null- values
the optional values for the formatted exception message, null array not recommended
- Returns
the validated iterable (never <code>null</code> method for chaining)
- Throws
- IllegalArgumentException
if an element is <code>null</code>
- NullPointerException
if the array is <code>null</code>
Validate that the specified argument array is neither <code>null</code> nor a length of zero (no elements); otherwise throwing an exception.
Validate that the specified argument array is neither <code>null</code> nor a length of zero (no elements); otherwise throwing an exception.
<pre> Assert.notEmpty(myArray); </pre>
The message in the exception is "The validated array is empty".
- Value Params
- <T>
the array type
- Returns
the validated array (never <code>null</code> method for chaining)
- Throws
- IllegalArgumentException
if the array is empty
- NullPointerException
if the array is <code>null</code>
Validate that the specified argument character sequence is neither <code>null</code> nor a length of zero (no characters); otherwise throwing an exception with the specified message.
Validate that the specified argument character sequence is neither <code>null</code> nor a length of zero (no characters); otherwise throwing an exception with the specified message.
<pre> Assert.notEmpty(myString); </pre>
The message in the exception is "The validated character sequence is empty".
- Value Params
- <T>
the character sequence type
- chars
the character sequence to check, validated not null by this method
- Returns
the validated character sequence (never <code>null</code> method for chaining)
- Throws
- IllegalArgumentException
if the character sequence is empty
- NullPointerException
if the character sequence is <code>null</code>
Validate that the specified argument is not <code>null</code>; otherwise throwing an exception.
Validate that the specified argument is not <code>null</code>; otherwise throwing an exception.
<pre> Assert.notNull(myObject, "The object must not be null"); </pre>
The message of the exception is "The validated object is null".
- Value Params
- <T>
the object type
- value
the object to check
- Returns
the validated object (never <code>null</code> for method chaining)
- Throws
- NullPointerException
if the object is <code>null</code>
- See also
#notNull(Object, String, Object...)
Validate that the specified argument is not <code>null</code>; otherwise throwing an exception with the specified message.
Validate that the specified argument is not <code>null</code>; otherwise throwing an exception with the specified message.
<pre> Assert.notNull(myObject, "The object must not be null"); </pre>
- Value Params
- <T>
the object type
- message
the
[[String#format(String, Object...)]]
exception message if invalid, not null- object
the object to check
- values
the optional values for the formatted exception message
- Returns
the validated object (never <code>null</code> for method chaining)
- Throws
- NullPointerException
if the object is <code>null</code>
- See also
#notNull(Object)