Package org.axonframework.common
Class Assert
java.lang.Object
org.axonframework.common.Assert
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 Summary
Modifier and TypeMethodDescriptionstatic <T,X extends Throwable>
voidassertNonNull(T value, Supplier<? extends X> exceptionSupplier) Assert that the givenvalueis non-null.static voidassertStrictPositive(int i, String exceptionMessage) Assert that the givenvalueis strictly positive, meaning greater than zero.static voidassertStrictPositive(long i, String exceptionMessage) Assert that the givenvalueis strictly positive, meaning greater than zero.static <T,X extends Throwable>
voidassertThat(T value, Predicate<T> assertion, Supplier<? extends X> exceptionSupplier) static voidAsserts that the givenexpressionis false.static voidAsserts that the givenexpressionis true.static StringAssert that the givenstringis notnulland does not equal an empty String.static <T> TAssert that the givenvalueis notnull.static voidAssert that the givenvalueis notnull.static voidAsserts that the value ofstateis true.
-
Method Details
-
state
Asserts that the value ofstateis 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
Asserts that the givenexpressionis 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
Asserts that the givenexpressionis false. If not, an IllegalArgumentException is thrown.- Parameters:
expression- The state validation expression.messageSupplier- Supplier of the exception message if the expression evaluates totrue.
-
notNull
Assert that the givenvalueis notnull. If not, an IllegalArgumentException is thrown.- Parameters:
value- The value not to benull.messageSupplier- Supplier of the exception message if the assertion fails.
-
nonNull
Assert that the givenvalueis notnull. If not, an IllegalArgumentException is thrown.- Parameters:
value- The value not to benull.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 givenvaluewill result totruethrough theassertionPredicate. If not, theexceptionSupplierprovides an exception to be thrown.- Type Parameters:
T- A generic specifying the type of thevalue, which is the input for theassertion.X- A generic extendingThrowablewhich will be provided by theexceptionSupplier.- Parameters:
value- ATspecifying the value to assert.assertion- APredicateto testvalueagainst.exceptionSupplier- ASupplierof the exceptionXifassertionevaluates tofalse.- Throws:
X- If thevalueasserts tofalseby theassertion.
-
assertNonNull
public static <T,X extends Throwable> void assertNonNull(T value, Supplier<? extends X> exceptionSupplier) throws X Assert that the givenvalueis non-null. If not, theexceptionSupplierprovides an exception to be thrown.- Type Parameters:
T- A generic specifying the type of thevalue, which is the input for theassertion.X- A generic extendingThrowablewhich will be provided by theexceptionSupplier.- Parameters:
value- ATspecifying the value to assert.exceptionSupplier- ASupplierof the exceptionXifvalueequalsnull.- Throws:
X- If thevalueequalsnull.
-
nonEmpty
Assert that the givenstringis notnulland does not equal an empty String.If not, an
IllegalArgumentExceptionis thrown containing the providedexceptionMessage.- Parameters:
string- The value to assert.exceptionMessage- The message for the exception.- Returns:
- The given
stringwhen it was notnullor empty.
-
assertStrictPositive
Assert that the givenvalueis strictly positive, meaning greater than zero.If not, an
IllegalArgumentExceptionis thrown containing the provided {code exceptionMessage}.- Parameters:
i- The value to assert to be strictly positive.exceptionMessage- The message for the exception.
-
assertStrictPositive
Assert that the givenvalueis strictly positive, meaning greater than zero.If not, an
IllegalArgumentExceptionis thrown containing the provided {code exceptionMessage}.- Parameters:
i- The value to assert to be strictly positive.exceptionMessage- The message for the exception.
-