@SuppressWarnings(value: unused) @CompileStatic class ContractsSimple extends Object
Defines simple DBC (Design-by-Contracts) methods with enhanced messages containing textual representation of used boolean expressions.
For example, the code fragmentrequireTrue(1 > 10)will result in
AssertionError
with the message
Require violation detected - boolean condition is false - [condition: (1 > 10)]Implementation uses Groovy macro methods to extract textual representation of tested boolean expressions which is very convenient to have in
AssertionError
messages.
Type | Name and description |
---|---|
static String |
REQUIRE_TRUE_MESSAGE_DEFAULT |
Constructor and description |
---|
ContractsSimple() |
Type Params | Return Type | Name and description |
---|---|---|
|
static Expression |
requireTrue(MacroContext macroContext, Expression expression) DBC precondition check based on boolean expression. |
DBC precondition check based on boolean expression.
It adds convenient message containing textual representation of actually used boolean expression. At the implementation level, when this Groovy macro method is expanded and replaced, we end up with the method call to ContractsBase#requireTrueBase(java.lang.Boolean, java.lang.String).Groovy Documentation