com.github.sebhoss.contract:contract-verifier

Annotation-based design by contract library.

License

License

GroupId

GroupId

com.github.sebhoss.contract
ArtifactId

ArtifactId

contract-verifier
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Annotation-based design by contract library.

Download contract-verifier

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.sebhoss.contract/contract-verifier/ -->
<dependency>
    <groupId>com.github.sebhoss.contract</groupId>
    <artifactId>contract-verifier</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.sebhoss.contract/contract-verifier/
implementation 'com.github.sebhoss.contract:contract-verifier:1.0.0'
// https://jarcasting.com/artifacts/com.github.sebhoss.contract/contract-verifier/
implementation ("com.github.sebhoss.contract:contract-verifier:1.0.0")
'com.github.sebhoss.contract:contract-verifier:jar:1.0.0'
<dependency org="com.github.sebhoss.contract" name="contract-verifier" rev="1.0.0">
  <artifact name="contract-verifier" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.sebhoss.contract', module='contract-verifier', version='1.0.0')
)
libraryDependencies += "com.github.sebhoss.contract" % "contract-verifier" % "1.0.0"
[com.github.sebhoss.contract/contract-verifier "1.0.0"]

Dependencies

compile (4)

Group / Artifact Type Version
com.github.sebhoss.contract : contract-annotations jar 1.0.0
javax.inject : javax.inject jar
com.github.sebhoss : common-annotations jar
ch.qos.cal10n : cal10n-api jar

test (3)

Group / Artifact Type Version
com.github.sebhoss.contract : contract-testutils jar 1.0.0
junit : junit jar
org.mockito : mockito-core jar

Project Modules

There are no modules declared in this project.

annotated-contracts

Coverage Status Dependency Status

Design by Contract based on annotations. It allows easy usage of contracts without any need for extra JVM parameters, JVM agents, special classloaders or compilers. Instead it leverages dependency injection to capture method calls which are annotation with a contract. The project is highly flexible and can be extended to support new contract annotations and other contract clause definitions (see below).

Usage

Contracts can only be specified on methods. The following example shows how to do it:

public class ContractExample {

    @Contract(
        preconditions = {
            @Clause(value = "damage > 0", message = "Reported damage must be positive!", exception = IllegalStateException.class),
            @Clause("damage <= 5000")
        },
        postconditions = {
            @Clause("return >= 0"),
            @Clause(value = "return <= 2000", exception = NotEnoughMoneyException.class)
        })
    public double calculateCover(double damage) {
        // .. some calculations
    }

}

The above example shows a method with two pre- and postconditions. The first precondition sets the optional message and exception fields, which are used in case the contract clause was violated. In case the exception message isn’t set, a default no-argument constructor is used, otherwise a constructor with a single String parameter is searched. See the integration matrix below for a framework/language usage guide.

Integration

This library offers several implementations for a variety of other libraries/frameworks. The following configuration matrix shows what is currently supported. Anything missing? Create an issue!:

CDI Guice Spring
JavaScript
JEXL
JUEL
MVEL
OGNL
SpEL
UEL

Development

License

This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See LICENSE or http://www.wtfpl.net/ for more details.

Setup

This projects uses Java, Maven and Git as the main development tools. To build the project yourself just download & install at least Maven 3.0 and call mvn install inside the project folder. Maven should then proceed to clean, build, package and install this project.

Versioning

This project follows the semantic versioning guidelines.

Alternatives

Not what you are looking for? Try one of the alternatives:

Versions

Version
1.0.0