Package org.assertj.core.util
Class Preconditions
- java.lang.Object
-
- org.assertj.core.util.Preconditions
-
public final class Preconditions extends java.lang.ObjectVerifies correct argument values and state. Borrowed from Guava.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringARGUMENT_EMPTY
-
Constructor Summary
Constructors Modifier Constructor Description privatePreconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcheckArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, java.util.function.Supplier<java.lang.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.useObjects.requireNonNull(Object)instead.static <T> TcheckNotNull(T reference, java.lang.String message)Deprecated.useObjects.requireNonNull(Object, String)instead.static java.lang.CharSequencecheckNotNullOrEmpty(java.lang.CharSequence s)Verifies that the givenCharSequenceis notnullor empty.static java.lang.CharSequencecheckNotNullOrEmpty(java.lang.CharSequence s, java.lang.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, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.private static voidthrowExceptionForBeingEmpty()private static voidthrowExceptionForBeingEmpty(java.lang.String message)
-
-
-
Field Detail
-
ARGUMENT_EMPTY
public static final java.lang.String ARGUMENT_EMPTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkNotNullOrEmpty
public static java.lang.CharSequence checkNotNullOrEmpty(java.lang.CharSequence s)
Verifies that the givenCharSequenceis notnullor empty.- Parameters:
s- the givenCharSequence.- Returns:
- the validated
CharSequence. - Throws:
java.lang.NullPointerException- if the givenCharSequenceisnull.java.lang.IllegalArgumentException- if the givenCharSequenceis empty.
-
checkNotNullOrEmpty
public static java.lang.CharSequence checkNotNullOrEmpty(java.lang.CharSequence s, java.lang.String message)Verifies that the givenCharSequenceis notnullor empty.- Parameters:
s- the givenCharSequence.message- error message in case of emptyString.- Returns:
- the validated
CharSequence. - Throws:
java.lang.NullPointerException- if the givenCharSequenceisnull.java.lang.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:
java.lang.NullPointerException- if the given array isnull.java.lang.IllegalArgumentException- if the given array is empty.
-
checkNotNull
@Deprecated public static <T> T checkNotNull(T reference)
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:
java.lang.NullPointerException- if the given object reference isnull.
-
checkNotNull
@Deprecated public static <T> T checkNotNull(T reference, java.lang.String message)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:
java.lang.NullPointerException- if the given object reference isnull.
-
checkNotNull
public static <T> void checkNotNull(FilterOperator<T> filterOperator)
Verifies that the givenFilterOperatorreference is notnull.- Type Parameters:
T- the type of the FilterOperator to check.- Parameters:
filterOperator- the givenFilterOperatorreference.- Throws:
java.lang.IllegalArgumentException- if the givenFilterOperatorreference isnull.
-
checkArgument
public static void checkArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.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:
java.lang.IllegalArgumentException- ifexpressionis falsejava.lang.NullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkArgument
public static void checkArgument(boolean expression, java.util.function.Supplier<java.lang.String> errorMessage)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:
java.lang.IllegalArgumentException- ifexpressionis falsejava.lang.NullPointerException- if the check fails anderrorMessageis null (don't let this happen).
-
checkState
public static void checkState(boolean expression, java.lang.String errorMessageTemplate, java.lang.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:
java.lang.IllegalStateException- ifexpressionis falsejava.lang.NullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
throwExceptionForBeingEmpty
private static void throwExceptionForBeingEmpty()
-
throwExceptionForBeingEmpty
private static void throwExceptionForBeingEmpty(java.lang.String message)
-
-