Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sebhoss/annotated-contracts

Design by Contract based on annotations
https://github.com/sebhoss/annotated-contracts

design-by-contracts java

Last synced: 14 days ago
JSON representation

Design by Contract based on annotations

Awesome Lists containing this project

README

        

h1. annotated-contracts

h2. "!https://www.ohloh.net/p/annotated-contracts/widgets/project_thin_badge.gif!":https://www.ohloh.net/p/annotated-contracts/ "!https://secure.travis-ci.org/sebhoss/annotated-contracts.png!":http://travis-ci.org/sebhoss/annotated-contracts !https://coveralls.io/repos/sebhoss/annotated-contracts/badge.png(Coverage Status)!:https://coveralls.io/r/sebhoss/annotated-contracts !https://www.versioneye.com/user/projects/5480dd186c476742c5000461/badge.svg?style=flat(Dependency Status)!:https://www.versioneye.com/user/projects/5480dd186c476742c5000461

p. "Design by Contract":http://en.wikipedia.org/wiki/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":http://en.wikipedia.org/wiki/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).

h2. Usage

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

bc.. 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
}

}

p. 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.

h2. Integration

p. 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!":https://github.com/sebhoss/annotated-contracts/issues/new:

| |_. "CDI":http://www.cdi-spec.org/ |_. "Guice":https://code.google.com/p/google-guice/ |_. "Spring":http://www.springsource.org/spring-framework |
| "JavaScript":http://download.java.net/jdk8/docs/technotes/guides/scripting/programmer_guide/index.html | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithJavaScript | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithJavaScript | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithJavaScript |
| "JEXL":http://commons.apache.org/proper/commons-jexl/ | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithJEXL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithJEXL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithJEXL |
| "JUEL":http://juel.sourceforge.net/ | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithJUEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithJUEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithJUEL |
| "MVEL":http://mvel.codehaus.org/ | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithMVEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithMVEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithMVEL |
| "OGNL":http://commons.apache.org/proper/commons-ognl/ | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithOGNL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithOGNL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithOGNL |
| "SpEL":http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/expressions.html | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithSpEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithSpEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithSpEL |
| "UEL":http://uel.java.net/ | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingCDIWithUEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingGuiceWithUEL | "✓":https://github.com/sebhoss/annotated-contracts/wiki/UsingSpringWithUEL |

h2. Development

h3. License

p. 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/":http://www.wtfpl.net/ for more details.

h3. Setup

p. This projects uses "Java":http://www.java.com/, "Maven":http://maven.apache.org/ and "Git":http://git-scm.com/ 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.

h3. Versioning

p. This project follows the "semantic versioning":http://semver.org/ guidelines.

h2. Alternatives

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

* "https://code.google.com/p/cofoja/":https://code.google.com/p/cofoja/
* "http://jcontracts.sourceforge.net/":http://jcontracts.sourceforge.net/
* "http://www.polyglotprogramming.com/contract4j":http://www.polyglotprogramming.com/contract4j
* "http://jcontractor.sourceforge.net/":http://jcontractor.sourceforge.net/
* "http://c4j.sourceforge.net/":http://c4j.sourceforge.net/
* "http://c4j-team.github.io/C4J/":http://c4j-team.github.io/C4J/
* "http://oval.sourceforge.net/":http://oval.sourceforge.net/
* "http://springcontracts.sourceforge.net/":http://springcontracts.sourceforge.net/
* "http://modernjass.sourceforge.net/":http://modernjass.sourceforge.net/
* "https://code.google.com/p/javadbc/":https://code.google.com/p/javadbc/
* "http://chex4j.sourceforge.net/":http://chex4j.sourceforge.net/
* "https://code.google.com/p/java-on-contracts/":https://code.google.com/p/java-on-contracts/