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 Details

  • Method Details

    • checkNotNullOrEmpty

      public static CharSequence checkNotNullOrEmpty(CharSequence s)
      Verifies that the given CharSequence is not null or empty.
      Parameters:
      s - the given CharSequence.
      Returns:
      the validated CharSequence.
      Throws:
      NullPointerException - if the given CharSequence is null.
      IllegalArgumentException - if the given CharSequence is empty.
    • checkNotNullOrEmpty

      public static CharSequence checkNotNullOrEmpty(CharSequence s, String message)
      Verifies that the given CharSequence is not null or empty.
      Parameters:
      s - the given CharSequence.
      message - error message in case of empty String.
      Returns:
      the validated CharSequence.
      Throws:
      NullPointerException - if the given CharSequence is null.
      IllegalArgumentException - if the given CharSequence is empty.
    • checkNotNullOrEmpty

      public static <T> T[] checkNotNullOrEmpty(T[] array)
      Verifies that the given array is not null 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 is null.
      IllegalArgumentException - if the given array is empty.
    • checkNotNull

      @Deprecated public static <T> T checkNotNull(T reference)
      Deprecated.
      Verifies that the given object reference is not null.
      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 is null.
    • checkNotNull

      @Deprecated public static <T> T checkNotNull(T reference, String message)
      Deprecated.
      Verifies that the given object reference is not null.
      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 is null.
    • checkNotNull

      public static <T> void checkNotNull(FilterOperator<T> filterOperator)
      Verifies that the given FilterOperator reference is not null.
      Type Parameters:
      T - the type of the FilterOperator to check.
      Parameters:
      filterOperator - the given FilterOperator reference.
      Throws:
      IllegalArgumentException - if the given FilterOperator reference is null.
    • 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 expression
      errorMessageTemplate - 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 - the arguments to be substituted into the message template.
      Throws:
      IllegalArgumentException - if expression is false
      NullPointerException - if the check fails and either errorMessageTemplate or errorMessageArgs is null (don't let this happen)
    • checkArgument

      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 - a boolean expression
      errorMessage - a supplier to build the error message in case of failure. Must not be null.
      Throws:
      IllegalArgumentException - if expression is false
      NullPointerException - if the check fails and errorMessage 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 expression
      errorMessageTemplate - 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 - the arguments to be substituted into the message template. Arguments are converted to strings using String.valueOf(Object).
      Throws:
      IllegalStateException - if expression is false
      NullPointerException - if the check fails and either errorMessageTemplate or errorMessageArgs is null (don't let this happen)