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:
- [email protected] (Alex Ruiz)
-
-
Field Summary
Fields Modifier and Type Field Description static String
ARGUMENT_EMPTY
-
Constructor Summary
Constructors Modifier Constructor Description private
Preconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)
Ensures the truth of an expression involving one or more parameters to the calling method.static <T> void
checkNotNull(FilterOperator<T> filterOperator)
Verifies that the givenFilterOperator
reference is notnull
.static <T> T
checkNotNull(T reference)
Deprecated.useObjects.requireNonNull(Object)
instead.static <T> T
checkNotNull(T reference, String message)
Deprecated.useObjects.requireNonNull(Object, String)
instead.static CharSequence
checkNotNullOrEmpty(CharSequence s)
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.private static void
throwExceptionForBeingEmpty()
private static void
throwExceptionForBeingEmpty(String message)
-
-
-
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 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
public static CharSequence checkNotNullOrEmpty(CharSequence s, String message)
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 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-
null
reference that was validated. - Throws:
NullPointerException
- if the given object reference isnull
.
-
checkNotNull
@Deprecated public static <T> T checkNotNull(T reference, 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-
null
reference that was validated. - Throws:
NullPointerException
- if the given object reference isnull
.
-
checkNotNull
public static <T> void checkNotNull(FilterOperator<T> filterOperator)
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)
-
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)
-
throwExceptionForBeingEmpty
private static void throwExceptionForBeingEmpty()
-
throwExceptionForBeingEmpty
private static void throwExceptionForBeingEmpty(String message)
-
-