Class Assert

java.lang.Object
org.axonframework.common.Assert

public abstract class Assert extends Object
Utility class (inspired by Springs Assert class) for doing assertions on parameters and object state. To remove the need for explicit dependencies on Spring, the functionality of that class is migrated to this class.
Since:
0.3
Author:
Allard Buijze
  • Method Details

    • state

      public static void state(boolean state, Supplier<String> messageSupplier)
      Asserts that the value of state is true. If not, an IllegalStateException is thrown.
      Parameters:
      state - the state validation expression
      messageSupplier - Supplier of the exception message if state evaluates to false
    • isTrue

      public static void isTrue(boolean expression, Supplier<String> messageSupplier)
      Asserts that the given expression is true. If not, an IllegalArgumentException is thrown.
      Parameters:
      expression - the state validation expression
      messageSupplier - Supplier of the exception message if the expression evaluates to false
    • isFalse

      public static void isFalse(boolean expression, Supplier<String> messageSupplier)
      Asserts that the given expression is false. If not, an IllegalArgumentException is thrown.
      Parameters:
      expression - the state validation expression
      messageSupplier - Supplier of the exception message if the expression evaluates to true
    • notNull

      public static void notNull(Object value, Supplier<String> messageSupplier)
      Assert that the given value is not null. If not, an IllegalArgumentException is thrown.
      Parameters:
      value - the value not to be null
      messageSupplier - Supplier of the exception message if the assertion fails
    • nonNull

      public static <T> T nonNull(T value, Supplier<String> messageSupplier)
      Assert that the given value is not null. If not, an IllegalArgumentException is thrown.
      Parameters:
      value - the value not to be null
      messageSupplier - Supplier of the exception message if the assertion fails
      Returns:
      the provided value
    • assertThat

      public static <T, X extends Throwable> void assertThat(T value, Predicate<T> assertion, Supplier<? extends X> exceptionSupplier) throws X
      Assert that the given value will result to true through the assertion Predicate. If not, the exceptionSupplier provides an exception to be thrown.
      Type Parameters:
      T - a generic specifying the type of the value, which is the input for the assertion
      X - a generic extending Throwable which will be provided by the exceptionSupplier
      Parameters:
      value - a T specifying the value to assert
      assertion - a Predicate to test value against
      exceptionSupplier - a Supplier of the exception X if assertion evaluates to false
      Throws:
      X - if the value asserts to false by the assertion
    • assertNonNull

      public static <T, X extends Throwable> void assertNonNull(T value, Supplier<? extends X> exceptionSupplier) throws X
      Assert that the given value is non null. If not, the exceptionSupplier provides an exception to be thrown.
      Type Parameters:
      T - a generic specifying the type of the value, which is the input for the assertion
      X - a generic extending Throwable which will be provided by the exceptionSupplier
      Parameters:
      value - a T specifying the value to assert
      exceptionSupplier - a Supplier of the exception X if value equals null
      Throws:
      X - if the value equals null