Top Description Fields Constructors Methods
org.assertj.core.util

public final Class Preconditions

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.util.Objects.requireNonNull

Verifies correct argument values and state. Borrowed from Guava.
Author
[email protected] (Alex Ruiz)

Field Summary

Modifier and TypeField and Description
public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
checkArgument(boolean
a boolean expression
expression
,
String
a template for the exception message should the check fail. The message is formed by calling String#format(String, Object...) with the given parameters.
errorMessageTemplate
,
Object...
the arguments to be substituted into the message template.
errorMessageArgs
)

Ensures the truth of an expression involving one or more parameters to the calling method.

public static void
checkArgument(boolean
a boolean expression
expression
,
Supplier<String>
a supplier to build the error message in case of failure. Must not be null.
errorMessage
)

Ensures the truth of an expression using a supplier to fetch the error message in case of a failure.

public static <
the type of the reference to check.
T
>
T

Returns:

the non-null reference that was validated.
checkNotNull
(T
the given object reference.
reference
)

Verifies that the given object reference is not null.
public static <
the type of the reference to check.
T
>
T

Returns:

the non-null reference that was validated.
checkNotNull
(T
the given object reference.
reference
,
String
error message in case of null reference.
message
)

Verifies that the given object reference is not null.
public static <
the type of the FilterOperator to check.
T
>
void
checkNotNull(FilterOperator<T>
the given FilterOperator reference.
filterOperator
)

Verifies that the given FilterOperator reference is not null.

public static CharSequence

Returns:

the validated CharSequence.
checkNotNullOrEmpty
(CharSequence
the given CharSequence.
s
)

Verifies that the given CharSequence is not null or empty.

public static CharSequence

Returns:

the validated CharSequence.
checkNotNullOrEmpty
(CharSequence
the given CharSequence.
s
,
String
error message in case of empty String.
message
)

Verifies that the given CharSequence is not null or empty.

public static <
the type of elements of the array.
T
>
T[]

Returns:

the validated array.
checkNotNullOrEmpty
(T[]
the given array.
array
)

Verifies that the given array is not null or empty.

public static void
checkState(boolean
a boolean expression
expression
,
String
a template for the exception message should the check fail.The message is formed by calling String#format(String, Object...) with the given parameters.
errorMessageTemplate
,
Object...
the arguments to be substituted into the message template. Arguments are converted to strings using String#valueOf(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
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARGUMENT_EMPTYback to summary
public static final String ARGUMENT_EMPTY

Constructor Detail

Preconditionsback to summary
private Preconditions()

Method Detail

checkArgumentback to summary
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:boolean

a boolean expression

errorMessageTemplate:String

a template for the exception message should the check fail. The message is formed by calling String#format(String, Object...) with the given parameters.

errorMessageArgs:Object[]

the arguments to be substituted into the message template.

Exceptions
IllegalArgumentException:
if expression is false
NullPointerException:
if the check fails and either errorMessageTemplate or errorMessageArgs is null (don't let this happen)
checkArgumentback to summary
public 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.

Parameters
expression:boolean

a boolean expression

errorMessage:Supplier<String>

a supplier to build the error message in case of failure. Must not be null.

Exceptions
IllegalArgumentException:
if expression is false
NullPointerException:
if the check fails and errorMessage is null (don't let this happen).
checkNotNullback to summary
public static <T> T checkNotNull(T reference)

Verifies that the given object reference is not null.

Parameters
<T>
the type of the reference to check.
reference:T

the given object reference.

Returns:T

the non-null reference that was validated.

Annotations
@Deprecated
Exceptions
NullPointerException:
if the given object reference is null.
checkNotNullback to summary
public static <T> T checkNotNull(T reference, String message)

Verifies that the given object reference is not null.

Parameters
<T>
the type of the reference to check.
reference:T

the given object reference.

message:String

error message in case of null reference.

Returns:T

the non-null reference that was validated.

Annotations
@Deprecated
Exceptions
NullPointerException:
if the given object reference is null.
checkNotNullback to summary
public static <T> void checkNotNull(FilterOperator<T> filterOperator)

Verifies that the given FilterOperator reference is not null.

Parameters
<T>
the type of the FilterOperator to check.
filterOperator:FilterOperator<T>

the given FilterOperator reference.

Exceptions
IllegalArgumentException:
if the given FilterOperator reference is null.
checkNotNullOrEmptyback to summary
public static CharSequence checkNotNullOrEmpty(CharSequence s)

Verifies that the given CharSequence is not null or empty.

Parameters
s:CharSequence

the given CharSequence.

Returns:CharSequence

the validated CharSequence.

Exceptions
NullPointerException:
if the given CharSequence is null.
IllegalArgumentException:
if the given CharSequence is empty.
checkNotNullOrEmptyback to summary
public static CharSequence checkNotNullOrEmpty(CharSequence s, String message)

Verifies that the given CharSequence is not null or empty.

Parameters
s:CharSequence

the given CharSequence.

message:String

error message in case of empty String.

Returns:CharSequence

the validated CharSequence.

Exceptions
NullPointerException:
if the given CharSequence is null.
IllegalArgumentException:
if the given CharSequence is empty.
checkNotNullOrEmptyback to summary
public static <T> T[] checkNotNullOrEmpty(T[] array)

Verifies that the given array is not null or empty.

Parameters
<T>
the type of elements of the array.
array:T[]

the given array.

Returns:T[]

the validated array.

Exceptions
NullPointerException:
if the given array is null.
IllegalArgumentException:
if the given array is empty.
checkStateback to summary
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:boolean

a boolean expression

errorMessageTemplate:String

a template for the exception message should the check fail.The message is formed by calling String#format(String, Object...) with the given parameters.

errorMessageArgs:Object[]

the arguments to be substituted into the message template. Arguments are converted to strings using String#valueOf(Object).

Exceptions
IllegalStateException:
if expression is false
NullPointerException:
if the check fails and either errorMessageTemplate or errorMessageArgs is null (don't let this happen)
throwExceptionForBeingEmptyback to summary
private static void throwExceptionForBeingEmpty()
throwExceptionForBeingEmptyback to summary
private static void throwExceptionForBeingEmpty(String message)