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:
- alruiz@google.com (Alex Ruiz)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(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> voidcheckNotNull(FilterOperator<T> filterOperator) Verifies that the givenFilterOperatorreference is notnull.static <T> TcheckNotNull(T reference) Deprecated.static <T> TcheckNotNull(T reference, String message) Deprecated.useObjects.requireNonNull(Object, String)instead.static CharSequenceVerifies that the givenCharSequenceis notnullor empty.static CharSequencecheckNotNullOrEmpty(CharSequence s, String message) Verifies that the givenCharSequenceis notnullor empty.static <T> T[]checkNotNullOrEmpty(T[] array) Verifies that the given array is notnullor empty.static voidcheckState(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 givenCharSequenceis notnullor empty.- Parameters:
s- the givenCharSequence.- Returns:
- the validated
CharSequence. - Throws:
NullPointerException- if the givenCharSequenceisnull.IllegalArgumentException- if the givenCharSequenceis empty.
-
checkNotNullOrEmpty
Verifies that the givenCharSequenceis notnullor empty.- Parameters:
s- the givenCharSequence.message- error message in case of emptyString.- Returns:
- the validated
CharSequence. - Throws:
NullPointerException- if the givenCharSequenceisnull.IllegalArgumentException- if the givenCharSequenceis empty.
-
checkNotNullOrEmpty
public static <T> T[] checkNotNullOrEmpty(T[] array) Verifies that the given array is notnullor 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-
nullreference 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-
nullreference that was validated. - Throws:
NullPointerException- if the given object reference isnull.
-
checkNotNull
Verifies that the givenFilterOperatorreference is notnull.- Type Parameters:
T- the type of the FilterOperator to check.- Parameters:
filterOperator- the givenFilterOperatorreference.- Throws:
IllegalArgumentException- if the givenFilterOperatorreference 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- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis 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- ifexpressionis falseNullPointerException- if the check fails anderrorMessageis 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- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
Objects.requireNonNull(Object)instead.