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 <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 <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 expressionmessageSupplier- 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 expressionmessageSupplier- 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 expressionmessageSupplier- Supplier of the exception message if the expression evaluates to true
-
notNull
Assert that the givenvalueis notnull. If not, an IllegalArgumentException is thrown.- Parameters:
value- the value not to benullmessageSupplier- 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 benullmessageSupplier- 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 theassertionX- a generic extendingThrowablewhich will be provided by theexceptionSupplier- Parameters:
value- aTspecifying the value to assertassertion- aPredicateto testvalueagainstexceptionSupplier- aSupplierof the exceptionXifassertionevaluates to false- 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 theassertionX- a generic extendingThrowablewhich will be provided by theexceptionSupplier- Parameters:
value- aTspecifying the value to assertexceptionSupplier- aSupplierof the exceptionXifvalueequals null- Throws:
X- if thevalueequalsnull
-