Package org.assertj.core.util
Class Preconditions
java.lang.Object
org.assertj.core.util.Preconditions
Verifies correct argument values and state. Borrowed from Guava.
- Author:
- [email protected] (Alex Ruiz)
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkArgument
(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.static void
checkArgument
(boolean expression, Supplier<String> errorMessage) Ensures the truth of an expression using a supplier to fetch the error message in case of a failure.static <T> void
checkNotNull
(FilterOperator<T> filterOperator) Verifies that the givenFilterOperator
reference is notnull
.static <T> T
checkNotNull
(T reference) Deprecated.static <T> T
checkNotNull
(T reference, String message) Deprecated.useObjects.requireNonNull(Object, String)
instead.static CharSequence
Verifies that the givenCharSequence
is notnull
or empty.static CharSequence
checkNotNullOrEmpty
(CharSequence s, String message) Verifies that the givenCharSequence
is notnull
or empty.static <T> T[]
checkNotNullOrEmpty
(T[] array) Verifies that the given array is notnull
or empty.static void
checkState
(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
-
Field Details
-
ARGUMENT_EMPTY
- See Also:
-
-
Method Details
-
checkNotNullOrEmpty
Verifies that the givenCharSequence
is notnull
or empty.- Parameters:
s
- the givenCharSequence
.- Returns:
- the validated
CharSequence
. - Throws:
NullPointerException
- if the givenCharSequence
isnull
.IllegalArgumentException
- if the givenCharSequence
is empty.
-
checkNotNullOrEmpty
Verifies that the givenCharSequence
is notnull
or empty.- Parameters:
s
- the givenCharSequence
.message
- error message in case of emptyString
.- Returns:
- the validated
CharSequence
. - Throws:
NullPointerException
- if the givenCharSequence
isnull
.IllegalArgumentException
- if the givenCharSequence
is empty.
-
checkNotNullOrEmpty
public static <T> T[] checkNotNullOrEmpty(T[] array) Verifies that the given array is notnull
or empty.- Type Parameters:
T
- the type of elements of the array.- Parameters:
array
- the given array.- Returns:
- the validated array.
- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.
-
checkNotNull
Deprecated.useObjects.requireNonNull(Object)
instead.Verifies that the given object reference is notnull
.- Type Parameters:
T
- the type of the reference to check.- Parameters:
reference
- the given object reference.- Returns:
- the non-
null
reference that was validated. - Throws:
NullPointerException
- if the given object reference isnull
.
-
checkNotNull
Deprecated.useObjects.requireNonNull(Object, String)
instead.Verifies that the given object reference is notnull
.- Type Parameters:
T
- the type of the reference to check.- Parameters:
reference
- the given object reference.message
- error message in case of null reference.- Returns:
- the non-
null
reference that was validated. - Throws:
NullPointerException
- if the given object reference isnull
.
-
checkNotNull
Verifies that the givenFilterOperator
reference is notnull
.- Type Parameters:
T
- the type of the FilterOperator to check.- Parameters:
filterOperator
- the givenFilterOperator
reference.- Throws:
IllegalArgumentException
- if the givenFilterOperator
reference isnull
.
-
checkArgument
public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.Borrowed from Guava.
- Parameters:
expression
- a boolean expressionerrorMessageTemplate
- a template for the exception message should the check fail. The message is formed by callingString.format(String, Object...)
with the given parameters.errorMessageArgs
- the arguments to be substituted into the message template.- Throws:
IllegalArgumentException
- ifexpression
is falseNullPointerException
- if the check fails and eithererrorMessageTemplate
orerrorMessageArgs
is null (don't let this happen)
-
checkArgument
Ensures the truth of an expression using a supplier to fetch the error message in case of a failure.- Parameters:
expression
- a boolean expressionerrorMessage
- a supplier to build the error message in case of failure. Must not be null.- Throws:
IllegalArgumentException
- ifexpression
is falseNullPointerException
- if the check fails anderrorMessage
is null (don't let this happen).
-
checkState
public static void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.Borrowed from Guava.
- Parameters:
expression
- a boolean expressionerrorMessageTemplate
- a template for the exception message should the check fail.The message is formed by callingString.format(String, Object...)
with the given parameters.errorMessageArgs
- the arguments to be substituted into the message template. Arguments are converted to strings usingString.valueOf(Object)
.- Throws:
IllegalStateException
- ifexpression
is falseNullPointerException
- if the check fails and eithererrorMessageTemplate
orerrorMessageArgs
is null (don't let this happen)
-
Objects.requireNonNull(Object)
instead.