@CompileStatic class ContractsMatchBase extends Object
Defines base DBC (Design-by-Contracts) methods that use Hamcrest matchers for expressing contracts.
Methods defined here can be used by direct method calls. However, it is more convenient to userequireMatch
alternatives implemented in ContractsMatch
as Groovy macro methods.
Under the hood, these Groovy macro methods delegate to base methods defined here.
Type | Name and description |
---|---|
static String |
REQUIRE_MATCH_MESSAGE_DEFAULT |
Constructor and description |
---|
ContractsMatchBase() |
Type Params | Return Type | Name and description |
---|---|---|
<T> |
static void |
requireMatchBase(T item, org.hamcrest.Matcher<?> matcher, String itemDescription, String matcherDescription) DBC precondition check based on Hamcrest matcher. |
<T> |
static void |
requireMatchWhenNotNullBase(T item, org.hamcrest.Matcher<?> matcher, String itemDescription, String matcherDescription) DBC precondition check for non-null values based on Hamcrest matcher. |
DBC precondition check based on Hamcrest matcher.
When mismatch occurs, AssertionError is thrown.item
- Object that is checked.matcher
- Hamcrest matcher expressing precondition.itemDescription
- Optional description of the item.matcherDescription
- Optional description of the Hamcrest matcher.DBC precondition check for non-null values based on Hamcrest matcher.
Whennull
, item is ignored.
When mismatch occurs, AssertionError is thrown. item
- Object that is checked.matcher
- Hamcrest matcher expressing precondition.itemDescription
- Optional description of the item.matcherDescription
- Optional description of the Hamcrest matcher.Groovy Documentation