Package org.assertj.core.util
Class Preconditions
- java.lang.Object
-
- org.assertj.core.util.Preconditions
-
public final class Preconditions extends Object
Verifies correct argument values and state. Borrowed from Guava.- Author:
- alruiz@google.com (Alex Ruiz)
-
-
Field Summary
Fields Modifier and Type Field Description static StringARGUMENT_EMPTY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)Ensures the truth of an expression involving one or more parameters to the calling method.static <T> voidcheckNotNull(FilterOperator<T> filterOperator)Verifies that the givenFilterOperatorreference is notnull.static <T> TcheckNotNull(T reference)Verifies that the given object reference is notnull.static <T> TcheckNotNull(T reference, String message)Verifies that the given object reference is notnull.static CharSequencecheckNotNullOrEmpty(CharSequence s)Verifies 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 Detail
-
ARGUMENT_EMPTY
public static final String ARGUMENT_EMPTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkNotNullOrEmpty
public static CharSequence checkNotNullOrEmpty(CharSequence s)
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
public static CharSequence checkNotNullOrEmpty(CharSequence s, String message)
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.- Parameters:
array- the given array.- Returns:
- the validated array.
- Throws:
NullPointerException- if the given array isnull.IllegalArgumentException- if the given array is empty.
-
checkNotNull
public static <T> T checkNotNull(T reference)
Verifies that the given object reference is notnull.- Parameters:
reference- the given object reference.- Returns:
- the non-
nullreference that was validated. - Throws:
NullPointerException- if the given object reference isnull.
-
checkNotNull
public static <T> T checkNotNull(T reference, String message)Verifies that the given object reference is notnull.- 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
public static <T> void checkNotNull(FilterOperator<T> filterOperator)
Verifies that the givenFilterOperatorreference is notnull.- 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)
-
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)
-
-